[clang] [Clang] Eagerly instantiate used constexpr function upon definition. (PR #73463)

2023-11-27 Thread via cfe-commits

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

>From 80fc2336d14e6929c67f2e67d8bb2469fa48cbc4 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 26 Nov 2023 22:47:51 +0100
Subject: [PATCH] [Clang] Eagerly instantiate used constexpr function upon
 definition.

Despite CWG2497 not being resolved, it is reasonable to expect the following
code to compile (and which is supported by other compilers)

```cpp
  template constexpr T f();
  constexpr int g() { return f(); } // #1
  template constexpr T f() { return 123; }
  int k[g()];
  // #2
```

To that end, we eagerly instantiate all referenced
specializations of constexpr functions when they are defined.

We maintain a map of (pattern, [instantiations]) independant of
`PendingInstantiations` to avoid having to iterate that list after
each function definition.

We should apply the same logic to constexpr variables,
but I wanted to keep the PR small.

Fixes #73232
---
 clang/docs/ReleaseNotes.rst   |  5 
 clang/include/clang/Sema/Sema.h   | 11 +++
 clang/lib/Sema/SemaDecl.cpp   |  3 ++
 clang/lib/Sema/SemaExpr.cpp   |  9 --
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 17 +++
 .../SemaCXX/cxx2b-consteval-propagate.cpp |  8 +++--
 .../instantiate-used-constexpr-function.cpp   | 30 +++
 7 files changed, 78 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-used-constexpr-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29a06d0f713f588..b34b66ec7dcabc2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -762,6 +762,11 @@ Bug Fixes to C++ Support
   completes (except deduction guides). Fixes:
   (`#59827 `_)
 
+- Clang now immediately instantiates function template specializations
+  at the end of the definition of the corresponding function template
+  when the definition appears after the first point of instantiation.
+  (`#73232 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7c9d0e2e6412b7..091e1e3b4c1fd64 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -59,6 +59,7 @@
 #include "clang/Sema/TypoCorrection.h"
 #include "clang/Sema/Weak.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -10078,6 +10079,12 @@ class Sema final {
   /// but have not yet been performed.
   std::deque PendingInstantiations;
 
+  /// Track constexpr functions referenced before they are (lexically) defined.
+  /// The key is the pattern, associated with a list of specialisations that
+  /// need to be instantiated when the pattern is defined.
+  llvm::DenseMap>
+  PendingInstantiationsOfConstexprEntities;
+
   /// Queue of implicit template instantiations that cannot be performed
   /// eagerly.
   SmallVector LateParsedInstantiations;
@@ -10396,6 +10403,10 @@ class Sema final {
  bool Recursive = false,
  bool DefinitionRequired = false,
  bool AtEndOfTU = false);
+
+  void InstantiateFunctionTemplateSpecializations(
+  SourceLocation PointOfInstantiation, FunctionDecl *Template);
+
   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
   VarTemplateDecl *VarTemplate, VarDecl *FromVar,
   const TemplateArgumentList &TemplateArgList,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 23dd8ae15c16583..1030ba0d21b1906 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16255,6 +16255,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
   if (FD && !FD->isDeleted())
 checkTypeSupport(FD->getType(), FD->getLocation(), FD);
 
+  if (FD && FD->isConstexpr() && FD->isTemplated())
+InstantiateFunctionTemplateSpecializations(FD->getEndLoc(), FD);
+
   return dcl;
 }
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index fc39d6149c1cc65..37b0d0eed35845c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19047,12 +19047,17 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   CodeSynthesisContexts.size())
 PendingLocalImplicitInstantiations.push_back(
 std::make_pair(Func, PointOfInstantiation));
-  else if (Func->isConstexpr())
+  else if (Func->isConstexpr()) {
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call b

[clang] [llvm] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-11-27 Thread Jianjian Guan via cfe-commits

https://github.com/jacquesguan created 
https://github.com/llvm/llvm-project/pull/73489

Now we have default abi lp64 for rv64if and ilp32 for rv32if, which is 
different with riscv-gnu-toolchain. In 
https://github.com/riscv-collab/riscv-gnu-toolchain/blob/8e9fb09a0c4b1e566492ee6f42e8c1fa5ef7e0c2/configure#L3385
 when have f and not d, it prefers lp64f/ilp32f but no soft float. This patch 
tries to make their behaviors consistent.

>From b41c0a913a4ef81e650762a5ede5ae702860f001 Mon Sep 17 00:00:00 2001
From: Jianjian GUAN 
Date: Mon, 27 Nov 2023 16:14:04 +0800
Subject: [PATCH] [clang][RISCV] Change default abi when only have f extension
 but no d extension

Now we have default abi lp64 for rv64if and ilp32 for rv32if, which is 
different with riscv-gnu-toolchain.
In 
https://github.com/riscv-collab/riscv-gnu-toolchain/blob/8e9fb09a0c4b1e566492ee6f42e8c1fa5ef7e0c2/configure#L3385
 when have f but not, it prefers lp64f/ilp32f but no soft float. This patch 
tries to make their behaviors consistent.
---
 clang/test/Driver/riscv-abi.c | 14 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  4 
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/clang/test/Driver/riscv-abi.c b/clang/test/Driver/riscv-abi.c
index e67f790e0de0e59..16568271564c797 100644
--- a/clang/test/Driver/riscv-abi.c
+++ b/clang/test/Driver/riscv-abi.c
@@ -4,8 +4,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
-// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### \
@@ -24,6 +22,10 @@
 
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if -mabi=ilp32f 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -mabi=ilp32f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
 
 // CHECK-ILP32F: "-target-abi" "ilp32f"
 
@@ -51,8 +53,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
-// RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64  %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### \
@@ -60,7 +60,11 @@
 
 // CHECK-LP64: "-target-abi" "lp64"
 
-// RUN:  not %clang --target=riscv64-unknown-elf %s -### -march=rv64f 
-mabi=lp64f 2>&1 \
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if -mabi=lp64f 
2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -mabi=lp64f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
 
 // CHECK-LP64F: "-target-abi" "lp64f"
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 6322748430063ce..24d0d40cbc74ebc 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -1292,12 +1292,16 @@ StringRef RISCVISAInfo::computeDefaultABI() const {
   if (XLen == 32) {
 if (hasExtension("d"))
   return "ilp32d";
+if (hasExtension("f"))
+  return "ilp32f";
 if (hasExtension("e"))
   return "ilp32e";
 return "ilp32";
   } else if (XLen == 64) {
 if (hasExtension("d"))
   return "lp64d";
+if (hasExtension("f"))
+  return "lp64f";
 if (hasExtension("e"))
   return "lp64e";
 return "lp64";

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


[clang] [llvm] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-11-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-support
@llvm/pr-subscribers-clang

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

Author: Jianjian Guan (jacquesguan)


Changes

Now we have default abi lp64 for rv64if and ilp32 for rv32if, which is 
different with riscv-gnu-toolchain. In 
https://github.com/riscv-collab/riscv-gnu-toolchain/blob/8e9fb09a0c4b1e566492ee6f42e8c1fa5ef7e0c2/configure#L3385
 when have f and not d, it prefers lp64f/ilp32f but no soft float. This patch 
tries to make their behaviors consistent.

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


2 Files Affected:

- (modified) clang/test/Driver/riscv-abi.c (+9-5) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+4) 


``diff
diff --git a/clang/test/Driver/riscv-abi.c b/clang/test/Driver/riscv-abi.c
index e67f790e0de0e59..16568271564c797 100644
--- a/clang/test/Driver/riscv-abi.c
+++ b/clang/test/Driver/riscv-abi.c
@@ -4,8 +4,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
-// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### \
@@ -24,6 +22,10 @@
 
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if -mabi=ilp32f 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -mabi=ilp32f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
 
 // CHECK-ILP32F: "-target-abi" "ilp32f"
 
@@ -51,8 +53,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
-// RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64  %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### \
@@ -60,7 +60,11 @@
 
 // CHECK-LP64: "-target-abi" "lp64"
 
-// RUN:  not %clang --target=riscv64-unknown-elf %s -### -march=rv64f 
-mabi=lp64f 2>&1 \
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if -mabi=lp64f 
2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -mabi=lp64f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
 
 // CHECK-LP64F: "-target-abi" "lp64f"
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 6322748430063ce..24d0d40cbc74ebc 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -1292,12 +1292,16 @@ StringRef RISCVISAInfo::computeDefaultABI() const {
   if (XLen == 32) {
 if (hasExtension("d"))
   return "ilp32d";
+if (hasExtension("f"))
+  return "ilp32f";
 if (hasExtension("e"))
   return "ilp32e";
 return "ilp32";
   } else if (XLen == 64) {
 if (hasExtension("d"))
   return "lp64d";
+if (hasExtension("f"))
+  return "lp64f";
 if (hasExtension("e"))
   return "lp64e";
 return "lp64";

``




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


[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-27 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/73432

>From def7bbb22cdd9269aa927d8dcf4247c88877503b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 25 Nov 2023 23:55:11 -0800
Subject: [PATCH 1/2] [clang-format] Add BreakConcatenatedStrings option

Closes #70451.
---
 clang/docs/ClangFormatStyleOptions.rst | 15 +++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h| 14 ++
 clang/lib/Format/Format.cpp|  2 ++
 clang/lib/Format/TokenAnnotator.cpp|  3 +--
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 14 ++
 7 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ff424828ff63cdb..4ff9293b3de7a03 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2761,6 +2761,21 @@ the configuration (without a prefix: ``Auto``).
  firstValue :
  SecondValueVeryVeryVeryVeryLong;
 
+.. _BreakConcatenatedStrings:
+
+**BreakConcatenatedStrings** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Break between concatenated string literals in C, C++, and Objective-C.
+
+  .. code-block:: c++
+
+ true:
+ return "Code"
+"\0\52\26\55\55\0"
+"x013"
+"\02\xBA";
+ false:
+ return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
+
 .. _BreakConstructorInitializers:
 
 **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) 
:versionbadge:`clang-format 5` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52c9d6eb69617b0..3aa408496101ad3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -884,6 +884,7 @@ clang-format
 - Add ``AllowBreakBeforeNoexceptSpecifier`` option.
 - Add ``AllowShortCompoundRequirementOnASingleLine`` option.
 - Change ``BreakAfterAttributes`` from ``Never`` to ``Leave`` in LLVM style.
+- Add ``BreakConcatenatedStrings`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc412611ef62493..b5f7c16774cd96e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2088,6 +2088,19 @@ struct FormatStyle {
   /// \version 3.7
   bool BreakBeforeTernaryOperators;
 
+  /// Break between concatenated string literals in C, C++, and Objective-C.
+  /// \code
+  ///true:
+  ///return "Code"
+  ///   "\0\52\26\55\55\0"
+  ///   "x013"
+  ///   "\02\xBA";
+  ///false:
+  ///return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
+  /// \endcode
+  /// \version 18
+  bool BreakConcatenatedStrings;
+
   /// Different ways to break initializers.
   enum BreakConstructorInitializersStyle : int8_t {
 /// Break constructor initializers before the colon and after the commas.
@@ -4753,6 +4766,7 @@ struct FormatStyle {
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
+   BreakConcatenatedStrings == R.BreakConcatenatedStrings &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e1abcac5604a410..025bca2ea9f7365 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -978,6 +978,7 @@ template <> struct MappingTraits {
Style.BreakBeforeInlineASMColon);
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
+IO.mapOptional("BreakConcatenatedStrings", Style.BreakConcatenatedStrings);
 IO.mapOptional("BreakConstructorInitializers",
Style.BreakConstructorInitializers);
 IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
@@ -1485,6 +1486,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
   LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
   LLVMStyle.BreakBeforeTernaryOperators = true;
+  LLVMStyle.BreakConcatenatedStrings = true;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
   LLVMStyle.BreakStringLiterals = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index cfca7c00312aab3..17d3b48e0af8332 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5078,8 +5078,7 @@ bool TokenAnnota

[clang] [clang-format] Add BreakAdjacentStringLiterals option (PR #73432)

2023-11-27 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Add BreakAdjacentStringLiterals option (PR #73432)

2023-11-27 Thread Owen Pan via cfe-commits


@@ -2088,6 +2088,19 @@ struct FormatStyle {
   /// \version 3.7
   bool BreakBeforeTernaryOperators;
 
+  /// Break between concatenated string literals in C, C++, and Objective-C.

owenca wrote:

Fixed.

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


[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

2023-11-27 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Thinking some more about "Approach 2", I realized there is a challenge with it: 
given the node we are trying to resolve (for example, a dependent member expr) 
as a starting point, we need to find the enclosing template decl, so that we 
can query it for its "only instantiation".

The current patch does this by introspecting the starting node, and in a subset 
of cases (base expression is `MemberExpr` or `DeclRefExpr`) extracting a `Decl` 
from it, and then walking its `DeclContext` chain to find the template decl.

However, we would ideally like our "only instantiation" heuristic to work for 
any AST node inside a template (and so, for dependent member exprs, we would 
like it to work for any base expression type, not just specific ones).

In principle, it could be possible to extend the introspection approach to 
handle all expression types, since if an expression is dependent, it will 
ultimately reference a template parameter (or a Decl whose type references a 
template parameter, etc.) However, I feel like this may be a lot of work to 
implement and could be error-prone.

I wonder if we could do something easier: require that the caller pass in a 
`DeclContext*` which it knows to be enclosing the node we are trying to resolve 
(and then we can walk the chain from there to find the template).

Editor operations like go-to-def which involve taking an action at a cursor 
position use `SelectionTree` to "hit-test" the node under the cursor. 
`SelectionTree` exposes the chain of node that was hit (see e.g. 
`SelectionTree::print()` which prints the chain), so we can recover an 
enclosing `DeclContext*` from there; we'd just need to plumb the information 
through to `HeuristicResolver`.

In the future when we want to use `HeuristicResolver` for code completion, it 
can get the enclosing `DeclContext*` even more easily (`Sema::CurContext`).

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,455 @@
+//===--- InterpBitcast.cpp - Interpreter for the constexpr VM ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/BitVector.h"
+
+namespace clang {
+namespace interp {
+
+/// Used to iterate over pointer fields.
+using DataFunc =
+llvm::function_ref;
+
+#define BITCAST_TYPE_SWITCH(Expr, B)   
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\

tbaederr wrote:

Probably not the right place here? Would fit into `CheckBitCastType` instead. 
The primtypes should all be supported.

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


[clang] [Clang][SME2] Add outer product and accumulate/subtract builtins (PR #71176)

2023-11-27 Thread Matthew Devereau via cfe-commits

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


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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-27 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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 57a0a9aadf1ec4c111e303b7f0fe76505b3ad137 
0f1c2b52846a3da7b7efdac795b8009ac69ac1f1 -- 
clang/lib/AST/Interp/InterpBitcast.cpp 
clang/test/AST/Interp/builtin-bit-cast.cpp clang/lib/AST/Interp/Boolean.h 
clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/ByteCodeExprGen.h 
clang/lib/AST/Interp/Floating.h clang/lib/AST/Interp/Integral.h 
clang/lib/AST/Interp/IntegralAP.h clang/lib/AST/Interp/Interp.cpp 
clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/PrimType.h 
clang/lib/AST/Interp/Record.h clang/test/AST/Interp/literals.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/Interp/InterpBitcast.cpp 
b/clang/lib/AST/Interp/InterpBitcast.cpp
index 7d3e5d8ed5..3b5833604a 100644
--- a/clang/lib/AST/Interp/InterpBitcast.cpp
+++ b/clang/lib/AST/Interp/InterpBitcast.cpp
@@ -337,7 +337,8 @@ bool DoBitCast(InterpState &S, CodePtr OpPC, const Pointer 
&P, std::byte *Buff,
   bool BigEndian = ASTCtx.getTargetInfo().isBigEndian();
 
   BitTracker Bits;
-  bool Success = readPointerToBuffer(S.getContext(), P, Bits, 
/*ReturnOnUninit=*/false);
+  bool Success =
+  readPointerToBuffer(S.getContext(), P, Bits, /*ReturnOnUninit=*/false);
 
   Bits.markUninitializedUntil(BuffSize * 8);
   assert(Bits.size() == BuffSize * 8);

``




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


[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

2023-11-27 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> > I also discovered some complications related to nested templates [...]
> 
> Does my previous comment elaborate on the same issue you've encountered?

I believe so, yes.

> Could you kindly share your thoughts more?

Let's consider a nested template like this:

```c++
template 
struct Outer {
  template 
  void inner(U u) {
u.foo();
  }
}
```

I believe our heuristic needs to require two things:
  1. `Outer` has an "only instantiation", say `Outer`
  2. `Outer::inner` also has an "only instantiation", say 
`Outer::inner`

Now, suppose we have written an algorithm for "given a template `X`, and some 
AST node `N` inside the body of `X`, find the corresponding AST node inside an 
instantiation `X`.

Then, I think we can proceed as follows:

 1. Start with the expression `u.foo` in the uninstantiated template
 2. Get the enclosing template decl, it's `Outer::inner`
 3. (As you observed, `Outer::inner` has no "only instantiation", only 
`Outer::inner` does.)
 4. Walk the `DeclContext` chain further to see if there are any further 
enclosing templates. We find `Outer`
 5. Check `Outer` for an "only instantiation". It has one, `Outer`!
 6. Run our algorithm with `X = Outer`, `N = Outer::inner`, `C = A`. It 
finds `Outer::inner`
 7. Run our algorithm with `X = Outer::inner`, `N = u.foo`, `C = B`. It 
finds the concrete `MemberExpr` which `u.foo` instantiated to inside 
`Outer::inner`.

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


[llvm] [clang] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-11-27 Thread Jianjian Guan via cfe-commits

https://github.com/jacquesguan updated 
https://github.com/llvm/llvm-project/pull/73489

>From e03da61c3ad76b76a99639ad1735ec556aaec10b Mon Sep 17 00:00:00 2001
From: Jianjian GUAN 
Date: Mon, 27 Nov 2023 16:14:04 +0800
Subject: [PATCH] [clang][RISCV] Change default abi when only have f extension
 but no d extension

Now we have default abi lp64 for rv64if and ilp32 for rv32if, which is 
different with riscv-gnu-toolchain.
In 
https://github.com/riscv-collab/riscv-gnu-toolchain/blob/8e9fb09a0c4b1e566492ee6f42e8c1fa5ef7e0c2/configure#L3385
 when have f but not, it prefers lp64f/ilp32f but no soft float. This patch 
tries to make their behaviors consistent.
---
 clang/test/Driver/riscv-abi.c | 14 +-
 clang/test/Driver/riscv-cpus.c|  8 
 llvm/lib/Support/RISCVISAInfo.cpp |  4 
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/test/Driver/riscv-abi.c b/clang/test/Driver/riscv-abi.c
index e67f790e0de0e59..16568271564c797 100644
--- a/clang/test/Driver/riscv-abi.c
+++ b/clang/test/Driver/riscv-abi.c
@@ -4,8 +4,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
-// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### \
@@ -24,6 +22,10 @@
 
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if -mabi=ilp32f 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -mabi=ilp32f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
 
 // CHECK-ILP32F: "-target-abi" "ilp32f"
 
@@ -51,8 +53,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
-// RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64  %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### \
@@ -60,7 +60,11 @@
 
 // CHECK-LP64: "-target-abi" "lp64"
 
-// RUN:  not %clang --target=riscv64-unknown-elf %s -### -march=rv64f 
-mabi=lp64f 2>&1 \
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if -mabi=lp64f 
2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -mabi=lp64f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
 
 // CHECK-LP64F: "-target-abi" "lp64f"
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 6c31282d0c8d49c..bfef54de183ac5e 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -1,4 +1,4 @@
-// Check target CPUs are correctly passed.
+·// Check target CPUs are correctly passed.
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=rocket-rv32 | FileCheck 
-check-prefix=MCPU-ROCKET32 %s
 // MCPU-ROCKET32: "-nostdsysteminc" "-target-cpu" "rocket-rv32"
@@ -113,7 +113,7 @@
 // MCPU-SIFIVE-E24: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f"
 // MCPU-SIFIVE-E24: "-target-feature" "+c"
 // MCPU-SIFIVE-E24: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
-// MCPU-SIFIVE-E24: "-target-abi" "ilp32"
+// MCPU-SIFIVE-E24: "-target-abi" "ilp32f"
 
 // mcpu with default march
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=sifive-e34 | FileCheck 
-check-prefix=MCPU-SIFIVE-E34 %s
@@ -121,7 +121,7 @@
 // MCPU-SIFIVE-E34: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f"
 // MCPU-SIFIVE-E34: "-target-feature" "+c"
 // MCPU-SIFIVE-E34: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
-// MCPU-SIFIVE-E34: "-target-abi" "ilp32"
+// MCPU-SIFIVE-E34: "-target-abi" "ilp32f"
 
 // mcpu with mabi option
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=sifive-s21 -mabi=lp64 | 
FileCheck -check-prefix=MCPU-ABI-SIFIVE-S21 %s
@@ -178,7 +178,7 @@
 // MCPU-SIFIVE-E76: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f"
 // MCPU-SIFIVE-E76: "-target-feature" "+c"
 // MCPU-SIFIVE-E76: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
-// MCPU-SIFIVE-E76: "-target-abi" "ilp32"
+// MCPU-SIFIVE-E76: "-target-abi" "ilp32f"
 
 // mcpu with mabi option
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=sifive-u74 -mabi=lp64 | 
FileCheck -check-p

[clang] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-11-27 Thread Nathan Ridge via cfe-commits


@@ -585,6 +585,17 @@ TEST_F(TokenCollectorTest, DelayedParsing) {
   EXPECT_THAT(collectAndDump(Code), StartsWith(ExpectedTokens));
 }
 
+TEST_F(TokenCollectorTest, UnclosedToken) {

HighCommander4 wrote:

Indeed, it looks like `TokenBuffer::spelledForExpanded()` (which is the only 
call site of `spelledForExpandedToken()`)  is not called by anything currently 
in this test.

To exercise `spelledForExpanded()`, we will need to make an explicit call to 
it, the way a number of other tests in this file do.

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


[clang] Improve clang-format-diff help output (PR #73491)

2023-11-27 Thread via cfe-commits

https://github.com/serge-sans-paille created 
https://github.com/llvm/llvm-project/pull/73491

It is quite common to symlink clang-format-diff.py to clang-format-diff, and in 
that case the help output still refers to the .py version. Compute it instead 
to work in both setup.

>From 788d03126f95ffc8d3b9701fdba73bb931e25cfc Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 27 Nov 2023 10:17:32 +0100
Subject: [PATCH] Improve clang-format-diff help output

It is quite common to symlink clang-format-diff.py to
clang-format-diff, and in that case the help output still refers to the
.py version. Compute it instead to work in both setup.
---
 clang/tools/clang-format/clang-format-diff.py | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 892c1e38a462ff4..facaaf96dd8f90a 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -13,8 +13,8 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
-  svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
+  git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i
+  svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i
 
 It should be noted that the filename contained in the diff is used unmodified
 to determine the source file to update. Users calling this script directly
@@ -25,6 +25,7 @@
 
 import argparse
 import difflib
+import os
 import re
 import subprocess
 import sys
@@ -36,8 +37,10 @@
 
 
 def main():
+basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__, 
formatter_class=argparse.RawDescriptionHelpFormatter
+description=__doc__.format(clang_format_diff=basename),
+formatter_class=argparse.RawDescriptionHelpFormatter
 )
 parser.add_argument(
 "-i",

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


[clang] Improve clang-format-diff help output (PR #73491)

2023-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (serge-sans-paille)


Changes

It is quite common to symlink clang-format-diff.py to clang-format-diff, and in 
that case the help output still refers to the .py version. Compute it instead 
to work in both setup.

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


1 Files Affected:

- (modified) clang/tools/clang-format/clang-format-diff.py (+6-3) 


``diff
diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 892c1e38a462ff4..facaaf96dd8f90a 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -13,8 +13,8 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
-  svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
+  git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i
+  svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i
 
 It should be noted that the filename contained in the diff is used unmodified
 to determine the source file to update. Users calling this script directly
@@ -25,6 +25,7 @@
 
 import argparse
 import difflib
+import os
 import re
 import subprocess
 import sys
@@ -36,8 +37,10 @@
 
 
 def main():
+basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__, 
formatter_class=argparse.RawDescriptionHelpFormatter
+description=__doc__.format(clang_format_diff=basename),
+formatter_class=argparse.RawDescriptionHelpFormatter
 )
 parser.add_argument(
 "-i",

``




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


[clang] Improve clang-format-diff help output (PR #73491)

2023-11-27 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
772f296214e10323ca16921c02b1852307b7d51b..788d03126f95ffc8d3b9701fdba73bb931e25cfc
 clang/tools/clang-format/clang-format-diff.py
``





View the diff from darker here.


``diff
--- clang-format-diff.py2023-11-27 09:17:32.00 +
+++ clang-format-diff.py2023-11-27 09:25:15.926747 +
@@ -38,11 +38,11 @@
 
 def main():
 basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
 description=__doc__.format(clang_format_diff=basename),
-formatter_class=argparse.RawDescriptionHelpFormatter
+formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(
 "-i",
 action="store_true",
 default=False,

``




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


[clang-tools-extra] [llvm] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-27 Thread Qiu Chaofan via cfe-commits


@@ -8900,6 +8900,83 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
   return FP;
 }
 
+SDValue PPCTargetLowering::LowerSET_ROUNDING(SDValue Op,
+ SelectionDAG &DAG) const {
+  SDLoc Dl(Op);
+  MachineFunction &MF = DAG.getMachineFunction();
+  EVT PtrVT = getPointerTy(MF.getDataLayout());
+  SDValue Chain = Op.getOperand(0);
+
+  // If requested mode is constant, just use simpler mtfsb.
+  if (auto *CVal = dyn_cast(Op.getOperand(1))) {
+uint64_t Mode = CVal->getZExtValue();
+if (Mode >= 4)
+  llvm_unreachable("Unsupported rounding mode!");
+unsigned InternalRnd = Mode ^ (~(Mode >> 1) & 1);
+SDNode *SetHi = DAG.getMachineNode(
+(InternalRnd & 2) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(30, Dl, MVT::i32, true), Chain});
+SDNode *SetLo = DAG.getMachineNode(
+(InternalRnd & 1) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(31, Dl, MVT::i32, true), SDValue(SetHi, 0)});
+return SDValue(SetLo, 0);
+  }
+
+  // Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format.
+  SDValue One = DAG.getConstant(1, Dl, MVT::i32);
+  SDValue SrcFlag = DAG.getNode(ISD::AND, Dl, MVT::i32, Op.getOperand(1),
+DAG.getConstant(3, Dl, MVT::i32));
+  SDValue DstFlag = DAG.getNode(
+  ISD::XOR, Dl, MVT::i32, SrcFlag,
+  DAG.getNode(ISD::AND, Dl, MVT::i32,
+  DAG.getNOT(Dl,
+ DAG.getNode(ISD::SRL, Dl, MVT::i32, SrcFlag, One),
+ MVT::i32),
+  One));
+  SDValue MFFS = DAG.getNode(PPCISD::MFFS, Dl, {MVT::f64, MVT::Other}, Chain);
+  Chain = MFFS.getValue(1);
+  SDValue NewFPSCR;
+  if (isTypeLegal(MVT::i64)) {
+// Set the last two bits (rounding mode) of bitcasted FPSCR.
+NewFPSCR = DAG.getNode(
+ISD::OR, Dl, MVT::i64,
+DAG.getNode(ISD::AND, Dl, MVT::i64,
+DAG.getNode(ISD::BITCAST, Dl, MVT::i64, MFFS),
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i64), 
MVT::i64)),
+DAG.getNode(ISD::ZERO_EXTEND, Dl, MVT::i64, DstFlag));

ecnelises wrote:

Yes, `DestFlag = SrcFlag ^ (~(SrcFlag >> 1) & 1)`, and `SrcFlag < 4`.

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


[clang] [llvm] [clang-tools-extra] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-27 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/67302

>From a1567f579531c3abbd1f4e9b7c7edd2f95ead42c Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Mon, 25 Sep 2023 17:10:51 +0800
Subject: [PATCH 1/3] [PowerPC] Implement llvm.set.rounding intrinsic

According to LangRef, llvm.set.rounding sets rounding mode by integer argument:

0 - toward zero
1 - to nearest, ties to even
2 - toward positive infinity
3 - toward negative infinity
4 - to nearest, ties away from zero

While PowerPC ISA says:

0 - to nearest
1 - toward zero
2 - toward positive infinity
3 - toward negative infinity

This patch maps the argument and write into last two bits of FPSCR (rounding 
mode).
---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp |  80 
 llvm/lib/Target/PowerPC/PPCISelLowering.h   |   1 +
 llvm/test/CodeGen/PowerPC/frounds.ll| 194 +++-
 3 files changed, 274 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index f4e3531980d165f..4e5ff0cb7169662 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -426,6 +426,7 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine 
&TM,
 setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
 
   setOperationAction(ISD::GET_ROUNDING, MVT::i32, Custom);
+  setOperationAction(ISD::SET_ROUNDING, MVT::Other, Custom);
 
   // If we're enabling GP optimizations, use hardware square root
   if (!Subtarget.hasFSQRT() &&
@@ -8898,6 +8899,83 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
   return FP;
 }
 
+SDValue PPCTargetLowering::LowerSET_ROUNDING(SDValue Op,
+ SelectionDAG &DAG) const {
+  SDLoc Dl(Op);
+  MachineFunction &MF = DAG.getMachineFunction();
+  EVT PtrVT = getPointerTy(MF.getDataLayout());
+  SDValue Chain = Op.getOperand(0);
+
+  // If requested mode is constant, just use simpler mtfsb.
+  if (auto *CVal = dyn_cast(Op.getOperand(1))) {
+uint64_t Mode = CVal->getZExtValue();
+if (Mode >= 4)
+  llvm_unreachable("Unsupported rounding mode!");
+unsigned InternalRnd = Mode ^ (~(Mode >> 1) & 1);
+SDNode *SetHi = DAG.getMachineNode(
+(InternalRnd & 2) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(30, Dl, MVT::i32, true), Chain});
+SDNode *SetLo = DAG.getMachineNode(
+(InternalRnd & 1) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(31, Dl, MVT::i32, true), SDValue(SetHi, 0)});
+return SDValue(SetLo, 0);
+  }
+
+  // Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format.
+  SDValue One = DAG.getConstant(1, Dl, MVT::i32);
+  SDValue SrcFlag = DAG.getNode(ISD::AND, Dl, MVT::i32, Op.getOperand(1),
+DAG.getConstant(3, Dl, MVT::i32));
+  SDValue DstFlag = DAG.getNode(
+  ISD::XOR, Dl, MVT::i32, SrcFlag,
+  DAG.getNode(ISD::AND, Dl, MVT::i32,
+  DAG.getNOT(Dl,
+ DAG.getNode(ISD::SRL, Dl, MVT::i32, SrcFlag, One),
+ MVT::i32),
+  One));
+  SDValue MFFS = DAG.getNode(PPCISD::MFFS, Dl, {MVT::f64, MVT::Other}, Chain);
+  Chain = MFFS.getValue(1);
+  SDValue NewFPSCR;
+  if (isTypeLegal(MVT::i64)) {
+// Set the last two bits (rounding mode) of bitcasted FPSCR.
+NewFPSCR = DAG.getNode(
+ISD::OR, Dl, MVT::i64,
+DAG.getNode(ISD::AND, Dl, MVT::i64,
+DAG.getNode(ISD::BITCAST, Dl, MVT::i64, MFFS),
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i64), 
MVT::i64)),
+DAG.getNode(ISD::ZERO_EXTEND, Dl, MVT::i64, DstFlag));
+NewFPSCR = DAG.getNode(ISD::BITCAST, Dl, MVT::f64, NewFPSCR);
+  } else {
+// In 32-bit mode, store f64, load and update the lower half.
+int SSFI = MF.getFrameInfo().CreateStackObject(8, Align(8), false);
+SDValue StackSlot = DAG.getFrameIndex(SSFI, PtrVT);
+Chain = DAG.getStore(Chain, Dl, MFFS, StackSlot, MachinePointerInfo());
+SDValue Addr;
+if (Subtarget.isLittleEndian())
+  Addr = StackSlot;
+else
+  Addr = DAG.getNode(ISD::ADD, Dl, PtrVT, StackSlot,
+ DAG.getConstant(4, Dl, PtrVT));
+SDValue Tmp = DAG.getLoad(MVT::i32, Dl, Chain, Addr, MachinePointerInfo());
+Chain = Tmp.getValue(1);
+
+Tmp = DAG.getNode(
+ISD::OR, Dl, MVT::i32,
+DAG.getNode(ISD::AND, Dl, MVT::i32, Tmp,
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i32), 
MVT::i32)),
+DstFlag);
+
+Chain = DAG.getStore(Chain, Dl, Tmp, Addr, MachinePointerInfo());
+NewFPSCR =
+DAG.getLoad(MVT::f64, Dl, Chain, StackSlot, MachinePointerInfo());
+Chain = NewFPSCR.getValue(1);
+  }
+  SDValue Zero = DAG.getConstant(0, Dl, MVT::i32, true);
+  SDNode *MTFSF = DAG.getMachineNode(
+  PPC::MTFSF, Dl

[clang-tools-extra] [llvm] [clang] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-27 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/67302

>From a1567f579531c3abbd1f4e9b7c7edd2f95ead42c Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Mon, 25 Sep 2023 17:10:51 +0800
Subject: [PATCH 1/4] [PowerPC] Implement llvm.set.rounding intrinsic

According to LangRef, llvm.set.rounding sets rounding mode by integer argument:

0 - toward zero
1 - to nearest, ties to even
2 - toward positive infinity
3 - toward negative infinity
4 - to nearest, ties away from zero

While PowerPC ISA says:

0 - to nearest
1 - toward zero
2 - toward positive infinity
3 - toward negative infinity

This patch maps the argument and write into last two bits of FPSCR (rounding 
mode).
---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp |  80 
 llvm/lib/Target/PowerPC/PPCISelLowering.h   |   1 +
 llvm/test/CodeGen/PowerPC/frounds.ll| 194 +++-
 3 files changed, 274 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index f4e3531980d165f..4e5ff0cb7169662 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -426,6 +426,7 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine 
&TM,
 setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
 
   setOperationAction(ISD::GET_ROUNDING, MVT::i32, Custom);
+  setOperationAction(ISD::SET_ROUNDING, MVT::Other, Custom);
 
   // If we're enabling GP optimizations, use hardware square root
   if (!Subtarget.hasFSQRT() &&
@@ -8898,6 +8899,83 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
   return FP;
 }
 
+SDValue PPCTargetLowering::LowerSET_ROUNDING(SDValue Op,
+ SelectionDAG &DAG) const {
+  SDLoc Dl(Op);
+  MachineFunction &MF = DAG.getMachineFunction();
+  EVT PtrVT = getPointerTy(MF.getDataLayout());
+  SDValue Chain = Op.getOperand(0);
+
+  // If requested mode is constant, just use simpler mtfsb.
+  if (auto *CVal = dyn_cast(Op.getOperand(1))) {
+uint64_t Mode = CVal->getZExtValue();
+if (Mode >= 4)
+  llvm_unreachable("Unsupported rounding mode!");
+unsigned InternalRnd = Mode ^ (~(Mode >> 1) & 1);
+SDNode *SetHi = DAG.getMachineNode(
+(InternalRnd & 2) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(30, Dl, MVT::i32, true), Chain});
+SDNode *SetLo = DAG.getMachineNode(
+(InternalRnd & 1) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(31, Dl, MVT::i32, true), SDValue(SetHi, 0)});
+return SDValue(SetLo, 0);
+  }
+
+  // Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format.
+  SDValue One = DAG.getConstant(1, Dl, MVT::i32);
+  SDValue SrcFlag = DAG.getNode(ISD::AND, Dl, MVT::i32, Op.getOperand(1),
+DAG.getConstant(3, Dl, MVT::i32));
+  SDValue DstFlag = DAG.getNode(
+  ISD::XOR, Dl, MVT::i32, SrcFlag,
+  DAG.getNode(ISD::AND, Dl, MVT::i32,
+  DAG.getNOT(Dl,
+ DAG.getNode(ISD::SRL, Dl, MVT::i32, SrcFlag, One),
+ MVT::i32),
+  One));
+  SDValue MFFS = DAG.getNode(PPCISD::MFFS, Dl, {MVT::f64, MVT::Other}, Chain);
+  Chain = MFFS.getValue(1);
+  SDValue NewFPSCR;
+  if (isTypeLegal(MVT::i64)) {
+// Set the last two bits (rounding mode) of bitcasted FPSCR.
+NewFPSCR = DAG.getNode(
+ISD::OR, Dl, MVT::i64,
+DAG.getNode(ISD::AND, Dl, MVT::i64,
+DAG.getNode(ISD::BITCAST, Dl, MVT::i64, MFFS),
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i64), 
MVT::i64)),
+DAG.getNode(ISD::ZERO_EXTEND, Dl, MVT::i64, DstFlag));
+NewFPSCR = DAG.getNode(ISD::BITCAST, Dl, MVT::f64, NewFPSCR);
+  } else {
+// In 32-bit mode, store f64, load and update the lower half.
+int SSFI = MF.getFrameInfo().CreateStackObject(8, Align(8), false);
+SDValue StackSlot = DAG.getFrameIndex(SSFI, PtrVT);
+Chain = DAG.getStore(Chain, Dl, MFFS, StackSlot, MachinePointerInfo());
+SDValue Addr;
+if (Subtarget.isLittleEndian())
+  Addr = StackSlot;
+else
+  Addr = DAG.getNode(ISD::ADD, Dl, PtrVT, StackSlot,
+ DAG.getConstant(4, Dl, PtrVT));
+SDValue Tmp = DAG.getLoad(MVT::i32, Dl, Chain, Addr, MachinePointerInfo());
+Chain = Tmp.getValue(1);
+
+Tmp = DAG.getNode(
+ISD::OR, Dl, MVT::i32,
+DAG.getNode(ISD::AND, Dl, MVT::i32, Tmp,
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i32), 
MVT::i32)),
+DstFlag);
+
+Chain = DAG.getStore(Chain, Dl, Tmp, Addr, MachinePointerInfo());
+NewFPSCR =
+DAG.getLoad(MVT::f64, Dl, Chain, StackSlot, MachinePointerInfo());
+Chain = NewFPSCR.getValue(1);
+  }
+  SDValue Zero = DAG.getConstant(0, Dl, MVT::i32, true);
+  SDNode *MTFSF = DAG.getMachineNode(
+  PPC::MTFSF, Dl

[clang] [Clang] CWG2789 Overload resolution with implicit and explicit object… (PR #73493)

2023-11-27 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/73493

… member functions

Implement the resolution to CWG2789 from
https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p3046r0.html

The DR page is not updated because the issue has not made it to a published 
list yet.

>From 3758290904571237c13ba23f2e3f65e58b6598aa Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 27 Nov 2023 10:48:13 +0100
Subject: [PATCH] [Clang] CWG2789 Overload resolution with implicit and
 explicit object member functions

Implement the resolution to CWG2789 from
https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p3046r0.html

The DR page is not updated because the issue has not made
it to a published list yet.
---
 clang/include/clang/Sema/Sema.h |  6 +++
 clang/lib/Sema/SemaOverload.cpp | 69 ++---
 clang/test/CXX/drs/dr27xx.cpp   | 31 +++
 3 files changed, 92 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr27xx.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7c9d0e2e6412b7..7579a3256bc37aa 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3849,6 +3849,12 @@ class Sema final {
   const FunctionProtoType *NewType,
   unsigned *ArgPos = nullptr,
   bool Reversed = false);
+
+  bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction,
+   const FunctionDecl *NewFunction,
+   unsigned *ArgPos = nullptr,
+   bool Reversed = false);
+
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9800d7f1c9cfee9..cc69cd1f2862aae 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -3239,6 +3239,28 @@ bool Sema::FunctionParamTypesAreEqual(const 
FunctionProtoType *OldType,
 NewType->param_types(), ArgPos, Reversed);
 }
 
+bool Sema::FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction,
+   const FunctionDecl *NewFunction,
+   unsigned *ArgPos,
+   bool Reversed) {
+
+  if (OldFunction->getNumNonObjectParams() !=
+  NewFunction->getNumNonObjectParams())
+return false;
+
+  unsigned OldIgnore =
+  unsigned(OldFunction->hasCXXExplicitFunctionObjectParameter());
+  unsigned NewIgnore =
+  unsigned(NewFunction->hasCXXExplicitFunctionObjectParameter());
+
+  auto *OldPT = cast(OldFunction->getFunctionType());
+  auto *NewPT = cast(NewFunction->getFunctionType());
+
+  return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore),
+NewPT->param_types().slice(NewIgnore),
+ArgPos, Reversed);
+}
+
 /// CheckPointerConversion - Check the pointer conversion from the
 /// expression From to the type ToType. This routine checks for
 /// ambiguous or inaccessible derived-to-base pointer
@@ -10121,22 +10143,41 @@ static bool haveSameParameterTypes(ASTContext 
&Context, const FunctionDecl *F1,
 
 /// We're allowed to use constraints partial ordering only if the candidates
 /// have the same parameter types:
-/// [over.match.best]p2.6
-/// F1 and F2 are non-template functions with the same parameter-type-lists,
-/// and F1 is more constrained than F2 [...]
+/// [over.match.best.general]p2.6
+/// F1 and F2 are non-template functions with the same
+/// non-object-parameter-type-lists, and F1 is more constrained than F2 [...]
 static bool sameFunctionParameterTypeLists(Sema &S,
-  const OverloadCandidate &Cand1,
-  const OverloadCandidate &Cand2) {
-  if (Cand1.Function && Cand2.Function) {
-auto *PT1 = cast(Cand1.Function->getFunctionType());
-auto *PT2 = cast(Cand2.Function->getFunctionType());
-if (PT1->getNumParams() == PT2->getNumParams() &&
-PT1->isVariadic() == PT2->isVariadic() &&
-S.FunctionParamTypesAreEqual(PT1, PT2, nullptr,
- Cand1.isReversed() ^ Cand2.isReversed()))
-  return true;
+   const OverloadCandidate &Cand1,
+   const OverloadCandidate &Cand2) {
+  if (!Cand1.Function || !Cand2.Function)
+return false;
+
+  auto *Fn1 = Cand1.Function;
+  auto *Fn2 = Cand2.Function;
+
+  if (Fn1->isVariadic() != Fn1->isVariadic())
+return false;
+
+  if (!S.FunctionNonObjectParamTypesAreEqual(
+  Fn1, Fn2, nullptr, Cand1.isReversed() ^ Cand2.isReversed

[clang] [Clang] CWG2789 Overload resolution with implicit and explicit object… (PR #73493)

2023-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

… member functions

Implement the resolution to CWG2789 from
https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p3046r0.html

The DR page is not updated because the issue has not made it to a published 
list yet.

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


3 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+6) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+55-14) 
- (added) clang/test/CXX/drs/dr27xx.cpp (+31) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7c9d0e2e6412b7..7579a3256bc37aa 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3849,6 +3849,12 @@ class Sema final {
   const FunctionProtoType *NewType,
   unsigned *ArgPos = nullptr,
   bool Reversed = false);
+
+  bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction,
+   const FunctionDecl *NewFunction,
+   unsigned *ArgPos = nullptr,
+   bool Reversed = false);
+
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9800d7f1c9cfee9..cc69cd1f2862aae 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -3239,6 +3239,28 @@ bool Sema::FunctionParamTypesAreEqual(const 
FunctionProtoType *OldType,
 NewType->param_types(), ArgPos, Reversed);
 }
 
+bool Sema::FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction,
+   const FunctionDecl *NewFunction,
+   unsigned *ArgPos,
+   bool Reversed) {
+
+  if (OldFunction->getNumNonObjectParams() !=
+  NewFunction->getNumNonObjectParams())
+return false;
+
+  unsigned OldIgnore =
+  unsigned(OldFunction->hasCXXExplicitFunctionObjectParameter());
+  unsigned NewIgnore =
+  unsigned(NewFunction->hasCXXExplicitFunctionObjectParameter());
+
+  auto *OldPT = cast(OldFunction->getFunctionType());
+  auto *NewPT = cast(NewFunction->getFunctionType());
+
+  return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore),
+NewPT->param_types().slice(NewIgnore),
+ArgPos, Reversed);
+}
+
 /// CheckPointerConversion - Check the pointer conversion from the
 /// expression From to the type ToType. This routine checks for
 /// ambiguous or inaccessible derived-to-base pointer
@@ -10121,22 +10143,41 @@ static bool haveSameParameterTypes(ASTContext 
&Context, const FunctionDecl *F1,
 
 /// We're allowed to use constraints partial ordering only if the candidates
 /// have the same parameter types:
-/// [over.match.best]p2.6
-/// F1 and F2 are non-template functions with the same parameter-type-lists,
-/// and F1 is more constrained than F2 [...]
+/// [over.match.best.general]p2.6
+/// F1 and F2 are non-template functions with the same
+/// non-object-parameter-type-lists, and F1 is more constrained than F2 [...]
 static bool sameFunctionParameterTypeLists(Sema &S,
-  const OverloadCandidate &Cand1,
-  const OverloadCandidate &Cand2) {
-  if (Cand1.Function && Cand2.Function) {
-auto *PT1 = cast(Cand1.Function->getFunctionType());
-auto *PT2 = cast(Cand2.Function->getFunctionType());
-if (PT1->getNumParams() == PT2->getNumParams() &&
-PT1->isVariadic() == PT2->isVariadic() &&
-S.FunctionParamTypesAreEqual(PT1, PT2, nullptr,
- Cand1.isReversed() ^ Cand2.isReversed()))
-  return true;
+   const OverloadCandidate &Cand1,
+   const OverloadCandidate &Cand2) {
+  if (!Cand1.Function || !Cand2.Function)
+return false;
+
+  auto *Fn1 = Cand1.Function;
+  auto *Fn2 = Cand2.Function;
+
+  if (Fn1->isVariadic() != Fn1->isVariadic())
+return false;
+
+  if (!S.FunctionNonObjectParamTypesAreEqual(
+  Fn1, Fn2, nullptr, Cand1.isReversed() ^ Cand2.isReversed()))
+return false;
+
+  auto *Mem1 = dyn_cast(Fn1);
+  auto *Mem2 = dyn_cast(Fn2);
+  if (Mem1 && Mem2) {
+// if they are member functions, both are direct members of the same class,
+// and
+if (Mem1->getParent() != Mem2->getParent())
+  return false;
+// if both are non-static member functions, they have the same types for
+// their object parameters
+if (Mem1->isInstance() && Mem2->isInstance() &&
+  

[clang] d1652ff - [Clang][SME2] Add outer product and accumulate/subtract builtins (#71176)

2023-11-27 Thread via cfe-commits

Author: Kerry McLaughlin
Date: 2023-11-27T09:54:23Z
New Revision: d1652ff0803ac9f2f3ea99336f71edacdf95a721

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

LOG: [Clang][SME2] Add outer product and accumulate/subtract builtins (#71176)

Adds the following SME2 builtins:
 - svmop(a|s)_za32,
 - svbmop(a|s)_za32

See https://github.com/ARM-software/acle/pull/217

Added: 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_bmop.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mop.c
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp

Modified: 
clang/include/clang/Basic/arm_sme.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..d55deeaa40bbcd5 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,19 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Outer product and accumulate/subtract
+//
+
+let TargetGuard = "sme2" in {
+  def SVSMOPA  : Inst<"svmopa_za32[_{d}]_m", "viPPdd", "s", MergeNone, 
"aarch64_sme_smopa_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+  def SVUSMOPA : Inst<"svmopa_za32[_{d}]_m", "viPPdd", "Us", MergeNone, 
"aarch64_sme_umopa_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+
+  def SVSMOPS  : Inst<"svmops_za32[_{d}]_m", "viPPdd", "s", MergeNone, 
"aarch64_sme_smops_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+  def SVUSMOPS : Inst<"svmops_za32[_{d}]_m", "viPPdd", "Us", MergeNone, 
"aarch64_sme_umops_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+
+  def SVBMOPA : Inst<"svbmopa_za32[_{d}]_m", "viPPdd", "iUi", MergeNone, 
"aarch64_sme_bmopa_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+
+  def SVBMOPS : Inst<"svbmops_za32[_{d}]_m", "viPPdd", "iUi", MergeNone, 
"aarch64_sme_bmops_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+}

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_bmop.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_bmop.c
new file mode 100644
index 000..67a330625884f87
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_bmop.c
@@ -0,0 +1,94 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// BMOPA
+
+// CHECK-LABEL: @test_svbmopa_u32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.bmopa.za32.nxv4i32(i32 3, 
 [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z16test_svbmopa_u32u10__SVBool_tS_u12__SVUint32_tS0_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PN:%.*]])
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PM:%.*]])
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.bmopa.za32.nxv4i32(i32 
3,  [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svbmopa_u32(svbool_t pn, svbool_t pm, svuint32_t zn, svuint32_t zm) 
_

[clang] [Clang][SME2] Add outer product and accumulate/subtract builtins (PR #71176)

2023-11-27 Thread Kerry McLaughlin via cfe-commits

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


[clang] Improve clang-format-diff help output (PR #73491)

2023-11-27 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/73491

>From 788d03126f95ffc8d3b9701fdba73bb931e25cfc Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 27 Nov 2023 10:17:32 +0100
Subject: [PATCH 1/2] Improve clang-format-diff help output

It is quite common to symlink clang-format-diff.py to
clang-format-diff, and in that case the help output still refers to the
.py version. Compute it instead to work in both setup.
---
 clang/tools/clang-format/clang-format-diff.py | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 892c1e38a462ff4..facaaf96dd8f90a 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -13,8 +13,8 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
-  svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
+  git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i
+  svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i
 
 It should be noted that the filename contained in the diff is used unmodified
 to determine the source file to update. Users calling this script directly
@@ -25,6 +25,7 @@
 
 import argparse
 import difflib
+import os
 import re
 import subprocess
 import sys
@@ -36,8 +37,10 @@
 
 
 def main():
+basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__, 
formatter_class=argparse.RawDescriptionHelpFormatter
+description=__doc__.format(clang_format_diff=basename),
+formatter_class=argparse.RawDescriptionHelpFormatter
 )
 parser.add_argument(
 "-i",

>From 4ddec8f2a65e60a701d13399a556b0acb281ed40 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 27 Nov 2023 11:00:36 +0100
Subject: [PATCH 2/2] fixup! [clang] Avoid memcopy for small structure with
 padding under -ftrivial-auto-var-init (#71677)

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

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index facaaf96dd8f90a..b25ee8f4337518e 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -40,7 +40,7 @@ def main():
 basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
 description=__doc__.format(clang_format_diff=basename),
-formatter_class=argparse.RawDescriptionHelpFormatter
+formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(
 "-i",

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


[clang] 0e86d3e - [clang] Print static_assert values of arithmetic binary operators (#71671)

2023-11-27 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-27T11:10:02+01:00
New Revision: 0e86d3ea9b93da273ee800a251dd60a44b85a320

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

LOG: [clang] Print static_assert values of arithmetic binary operators (#71671)

These are actually quite useful to print.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/complex-folding.cpp
clang/test/SemaCXX/static-assert.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29a06d0f713f588..25af97f7a059145 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -478,6 +478,24 @@ Improvements to Clang's diagnostics
   with GCC.
 - Clang will warn on deprecated specializations used in system headers when 
their instantiation
   is caused by user code.
+- Clang will now print ``static_assert`` failure details for arithmetic binary 
operators.
+  Example:
+
+  .. code-block:: cpp
+
+static_assert(1 << 4 == 15);
+
+  will now print:
+
+  .. code-block:: text
+
+error: static assertion failed due to requirement '1 << 4 == 15'
+   48 | static_assert(1 << 4 == 15);
+  |   ^~~~
+note: expression evaluates to '16 == 15'
+   48 | static_assert(1 << 4 == 15);
+  |   ~~~^
+
 
 Improvements to Clang's time-trace
 --

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..91c9a82bcfa0edc 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17218,10 +17218,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 
   return true;
 }

diff  --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 8c56cf0e5d984b0..054f159e9ce0dd2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -3,7 +3,8 @@
 // Test the constant folding of builtin complex numbers.
 
 static_assert((0.0 + 0.0j) == (0.0 + 0.0j));
-static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 
 static_assert((0.0 + 0.0j) == 0.0);
 static_assert(0.0 == (0.0 + 0.0j));
@@ -14,21 +15,29 @@ static_assert(0.0 != 1.0j);
 
 // Walk around the complex plane stepping between angular 
diff erences and
 // equality.
-static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 0.0j) == (1.0 + 0.0j));
-static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 1.0j) == (1.0 + 1.0j));
-static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((0.0 + 1.0j) == (0.0 + 1.0j));
-static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((-1.0 + 1.0j) == (-1.0 + 1.0j));
-static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 + 0.0j) == (-1.0 + 0.0j));
-static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_as

[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-27 Thread Balázs Kéri via cfe-commits


@@ -824,20 +817,76 @@ void StreamChecker::evalFgetcFputc(const FnDescription 
*Desc,
 
   // If a (non-EOF) error occurs, the resulting value of the file position
   // indicator for the stream is indeterminate.
-  StreamErrorState NewES;
-  if (IsRead)
-NewES =
-OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
-  else
-NewES = ErrorFError;
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
   StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
   StateFailed = StateFailed->set(StreamSym, NewSS);
-  if (IsRead && OldSS->ErrorState != ErrorFEof)
+  if (OldSS->ErrorState != ErrorFEof)
 C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
   else
 C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C, bool IsSingleChar) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // `fputc` returns the written character on success, otherwise returns EOF.
+  // `fputs` returns a non negative value on sucecess, otherwise returns EOF.
+
+  // Generddate a transition for the success state of `fputc`.

balazske wrote:

"Generate"

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


[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-27 Thread Balázs Kéri via cfe-commits


@@ -824,20 +817,76 @@ void StreamChecker::evalFgetcFputc(const FnDescription 
*Desc,
 
   // If a (non-EOF) error occurs, the resulting value of the file position
   // indicator for the stream is indeterminate.
-  StreamErrorState NewES;
-  if (IsRead)
-NewES =
-OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
-  else
-NewES = ErrorFError;
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
   StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
   StateFailed = StateFailed->set(StreamSym, NewSS);
-  if (IsRead && OldSS->ErrorState != ErrorFEof)
+  if (OldSS->ErrorState != ErrorFEof)
 C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
   else
 C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C, bool IsSingleChar) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // `fputc` returns the written character on success, otherwise returns EOF.
+  // `fputs` returns a non negative value on sucecess, otherwise returns EOF.
+
+  // Generddate a transition for the success state of `fputc`.
+  if (IsSingleChar) {
+std::optional PutVal = Call.getArgSVal(0).getAs();
+if (!PutVal)
+  return;
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), *PutVal);
+StateNotFailed =
+StateNotFailed->set(StreamSym, 
StreamState::getOpened(Desc));
+C.addTransition(StateNotFailed);
+  }
+  // Generddate a transition for the success state of `fputs`.
+  else {
+NonLoc RetVal = makeRetVal(C, CE).castAs();
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), RetVal);
+SValBuilder &SVB = C.getSValBuilder();
+auto &ASTC = C.getASTContext();
+auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, 
SVB.makeZeroVal(ASTC.IntTy),
+  SVB.getConditionType())
+.getAs();
+if (!Cond)
+  return;
+StateNotFailed = StateNotFailed->assume(*Cond, true);
+if (!StateNotFailed)
+  return;
+C.addTransition(StateNotFailed);
+  }
+
+  // Add transition for the failed state.
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+
+  // If a (non-EOF) error occurs, the resulting value of the file position
+  // indicator for the stream is indeterminate.

balazske wrote:

The file position becomes always indeterminate here.
`NewES` variable is not needed.

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


[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-27 Thread Balázs Kéri via cfe-commits


@@ -824,20 +817,76 @@ void StreamChecker::evalFgetcFputc(const FnDescription 
*Desc,
 
   // If a (non-EOF) error occurs, the resulting value of the file position
   // indicator for the stream is indeterminate.
-  StreamErrorState NewES;
-  if (IsRead)
-NewES =
-OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
-  else
-NewES = ErrorFError;
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
   StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
   StateFailed = StateFailed->set(StreamSym, NewSS);
-  if (IsRead && OldSS->ErrorState != ErrorFEof)
+  if (OldSS->ErrorState != ErrorFEof)
 C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
   else
 C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C, bool IsSingleChar) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // `fputc` returns the written character on success, otherwise returns EOF.
+  // `fputs` returns a non negative value on sucecess, otherwise returns EOF.
+
+  // Generddate a transition for the success state of `fputc`.
+  if (IsSingleChar) {
+std::optional PutVal = Call.getArgSVal(0).getAs();
+if (!PutVal)
+  return;
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), *PutVal);
+StateNotFailed =
+StateNotFailed->set(StreamSym, 
StreamState::getOpened(Desc));
+C.addTransition(StateNotFailed);
+  }
+  // Generddate a transition for the success state of `fputs`.
+  else {
+NonLoc RetVal = makeRetVal(C, CE).castAs();
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), RetVal);
+SValBuilder &SVB = C.getSValBuilder();
+auto &ASTC = C.getASTContext();

balazske wrote:

At this place `auto` should not be used.

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


[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-27 Thread Balázs Kéri via cfe-commits


@@ -824,20 +817,76 @@ void StreamChecker::evalFgetcFputc(const FnDescription 
*Desc,
 
   // If a (non-EOF) error occurs, the resulting value of the file position
   // indicator for the stream is indeterminate.
-  StreamErrorState NewES;
-  if (IsRead)
-NewES =
-OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
-  else
-NewES = ErrorFError;
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
   StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
   StateFailed = StateFailed->set(StreamSym, NewSS);
-  if (IsRead && OldSS->ErrorState != ErrorFEof)
+  if (OldSS->ErrorState != ErrorFEof)
 C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
   else
 C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C, bool IsSingleChar) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // `fputc` returns the written character on success, otherwise returns EOF.
+  // `fputs` returns a non negative value on sucecess, otherwise returns EOF.
+
+  // Generddate a transition for the success state of `fputc`.
+  if (IsSingleChar) {
+std::optional PutVal = Call.getArgSVal(0).getAs();
+if (!PutVal)
+  return;
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), *PutVal);
+StateNotFailed =
+StateNotFailed->set(StreamSym, 
StreamState::getOpened(Desc));
+C.addTransition(StateNotFailed);
+  }
+  // Generddate a transition for the success state of `fputs`.

balazske wrote:

This comment is at better place after the `else`.

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


[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-27 Thread Balázs Kéri via cfe-commits


@@ -141,6 +141,24 @@ void error_fputc(void) {
   fputc('A', F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_fputs(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int Ret = fputs("XYZ", F);
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+fputs("QWD", F);   // no-warning
+  } else {
+clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+clang_analyzer_eval(ferror(F));  // expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F));// expected-warning {{FALSE}}
+fputs("QWD", F); // expected-warning {{might be 
'indeterminate'}}
+  }
+  fclose(F);
+  fputs("ABC", F);   // expected-warning {{Stream might be 
already closed}}
+}
+

balazske wrote:

One type of test is missing, where the stream is in EOF state 
(`StreamTesterChecker_make_feof_stream(F)` can be used to get such a stream 
`F`) and a `fputc` or `fputs` is called. Then no error and no warning should be 
generated, and the state after the call should be non-error and non-EOF.

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


[clang] 489df61 - [clang][Interp][NFC] const qualify a local variable

2023-11-27 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-11-27T11:17:49+01:00
New Revision: 489df61a2960cbd154fe0a2c23918c2609ef4357

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

LOG: [clang][Interp][NFC] const qualify a local variable

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5dc1f9dfb10ff32..f45e8624a7741a5 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -75,7 +75,7 @@ template  class OptionScope final {
 
 template 
 bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) {
-  auto *SubExpr = CE->getSubExpr();
+  const Expr *SubExpr = CE->getSubExpr();
   switch (CE->getCastKind()) {
 
   case CK_LValueToRValue: {



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


[flang] [clang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Kiran Chandramohan via cfe-commits


@@ -142,6 +142,26 @@ void Flang::addCodegenOptions(const ArgList &Args,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);

kiranchandramohan wrote:

Some discussion regarding `-Os` is here.
https://discourse.llvm.org/t/code-size-optimization-flags-in-flang/69482

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


[clang] [lld] [clang-tools-extra] [libcxxabi] [libcxx] [libunwind] [mlir] [llvm] [flang] [lldb] [libc] [compiler-rt] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-27 Thread Shahid Iqbal via cfe-commits

shahidiqbal13 wrote:

Hi @DrTodd13 , 
Any further needs to be done here ?? Can you please add more devs for reviewing 
this 

Thanks,
Shahid

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


[llvm] [clang] [clang-tools-extra] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-27 Thread Qiu Chaofan via cfe-commits

ecnelises wrote:

> The patch looks good but I am not familiar with PPC instructions enough. 
> Could you please run the runtime tests from here: 
> https://github.com/llvm/llvm-test-suite/tree/main/MultiSource/UnitTests/Float/rounding?
>  You just need to build application from two files: clang rounding.c 
> rounding-dynamic.c.

Sure. All passed on `ppc64le`, `ppc64` and `ppc32`. (of course changes to 
test-suite and clang are needed, I'll update then)

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


[clang] [llvm] AArch64: add support for currently released Apple CPUs. (PR #73499)

2023-11-27 Thread Tim Northover via cfe-commits

https://github.com/TNorthover created 
https://github.com/llvm/llvm-project/pull/73499

These are still v8.6a and have no real changes as far as LLVM cares, so it's 
mostly just a copy/paste job (actually from 
https://github.com/llvm/llvm-project/pull/73497 rather than `main` as I write 
this).

>From c415ffd79582e6a24e4da7152935c93cbe17210e Mon Sep 17 00:00:00 2001
From: Tim Northover 
Date: Wed, 22 Nov 2023 14:10:31 +
Subject: [PATCH] AArch64: add support for currently released Apple CPUs.

These are still v8.6a so mostly just a copy/paste job.
---
 clang/test/Misc/target-invalid-cpu-note.c |  4 +--
 .../llvm/TargetParser/AArch64TargetParser.h   |  9 +++
 llvm/lib/Target/AArch64/AArch64.td| 25 ++-
 llvm/lib/Target/AArch64/AArch64Subtarget.cpp  |  2 ++
 llvm/lib/Target/AArch64/AArch64Subtarget.h|  1 +
 .../TargetParser/TargetParserTest.cpp | 22 +++-
 6 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 693f47a78b7fa57..c7146e63add5f20 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16,  apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X8

[clang] [llvm] AArch64: add support for currently released Apple CPUs. (PR #73499)

2023-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Tim Northover (TNorthover)


Changes

These are still v8.6a and have no real changes as far as LLVM cares, so it's 
mostly just a copy/paste job (actually from 
https://github.com/llvm/llvm-project/pull/73497 rather than `main` as I write 
this).

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


6 Files Affected:

- (modified) clang/test/Misc/target-invalid-cpu-note.c (+2-2) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+9) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+24-1) 
- (modified) llvm/lib/Target/AArch64/AArch64Subtarget.cpp (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64Subtarget.h (+1) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+21-1) 


``diff
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 693f47a78b7fa57..c7146e63add5f20 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16,  apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
 // X86: error: unknown target CPU 'not-a-cpu'
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
i

[llvm] [clang] AArch64: add support for currently released Apple CPUs. (PR #73499)

2023-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tim Northover (TNorthover)


Changes

These are still v8.6a and have no real changes as far as LLVM cares, so it's 
mostly just a copy/paste job (actually from 
https://github.com/llvm/llvm-project/pull/73497 rather than `main` as I write 
this).

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


6 Files Affected:

- (modified) clang/test/Misc/target-invalid-cpu-note.c (+2-2) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+9) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+24-1) 
- (modified) llvm/lib/Target/AArch64/AArch64Subtarget.cpp (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64Subtarget.h (+1) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+21-1) 


``diff
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 693f47a78b7fa57..c7146e63add5f20 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16,  apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
 // X86: error: unknown target CPU 'not-a-cpu'
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 38ccc

[clang] [flang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Andrzej Warzyński via cfe-commits


@@ -2,12 +2,25 @@
 ! See flang/test/Fir/tbaa-codegen.fir for a test that the output is correct
 
 ! RUN: %flang -c -emit-llvm -falias-analysis %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
-! RUN: %flang -c -emit-llvm -falias-analysis -fno-alias-analysis %s -o - | 
llvm-dis | FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -Ofast %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -O3 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -O2 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -O1 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+
+! RUN: %flang -c -emit-llvm -O0 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -Ofast -fno-alias-analysis %s -o - | llvm-dis | 
FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL

banach-space wrote:

What's going to happen in this case:
```
! RUN: %flang -c -emit-llvm -fno-alias-analysis  -Ofast %s -o - | llvm-dis | 
FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
```
? And will that behavior be consistent with Clang?

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


[flang] [clang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Andrzej Warzyński via cfe-commits

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


[flang] [clang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space commented:

Thanks for addressing my comments - this is looking really good now!

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


[clang] [flang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Andrzej Warzyński via cfe-commits


@@ -142,6 +142,24 @@ void Flang::addCodegenOptions(const ArgList &Args,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);
+  if (aliasAnalysis) {
+bool faliasAnalysis =
+aliasAnalysis->getOption().matches(options::OPT_falias_analysis);
+// only pass on the argument if it does not match that implied by the
+// optimization level
+if (optLevel && !faliasAnalysis) {
+  CmdArgs.push_back("-fno-alias-analysis");
+} else {
+  if (faliasAnalysis)
+// requested alias analysis but no optimization enabled
+CmdArgs.push_back("-falias-analysis");
+}
+  }

banach-space wrote:

[nit] It would be worth adding a comment here explaining the intent (e.g. "Only 
forward `-f{no}-alias-analysis if that makes sense considering other 
optimisation flags"). Alternatively, you could rename `optLevel` as 
`optLevelForSpeed` to communicate that. Or both. 

Just to make things clear for our future selves ;-) 

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


[llvm] [clang] AArch64: add support for currently released Apple CPUs. (PR #73499)

2023-11-27 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 ea5de6021cf69a233106689cc6f0ee14899e1a83 
c415ffd79582e6a24e4da7152935c93cbe17210e -- 
clang/test/Misc/target-invalid-cpu-note.c 
llvm/include/llvm/TargetParser/AArch64TargetParser.h 
llvm/lib/Target/AArch64/AArch64Subtarget.cpp 
llvm/lib/Target/AArch64/AArch64Subtarget.h 
llvm/unittests/TargetParser/TargetParserTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 734bb2e309..0c301f37ca 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -419,9 +419,9 @@ inline constexpr CpuInfo CpuInfos[] = {
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
 {"cortex-a55", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC}))},
 {"cortex-a510", ARMV9A,
  (AArch64::ExtensionBitset(
  {AArch64::AEK_BF16, AArch64::AEK_I8MM, AArch64::AEK_SB,
@@ -437,13 +437,13 @@ inline constexpr CpuInfo CpuInfos[] = {
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
 {"cortex-a65", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_DOTPROD,
-  AArch64::AEK_FP16, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_DOTPROD, AArch64::AEK_FP16,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a65ae", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_DOTPROD,
-  AArch64::AEK_FP16, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_DOTPROD, AArch64::AEK_FP16,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a72", ARMV8A,
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
@@ -451,38 +451,38 @@ inline constexpr CpuInfo CpuInfos[] = {
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
 {"cortex-a75", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC}))},
 {"cortex-a76", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a76ae", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a77", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_RCPC, AArch64::AEK_DOTPROD, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_RCPC,
+AArch64::AEK_DOTPROD, AArch64::AEK_SSBS}))},
 {"cortex-a78", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC, AArch64::AEK_SSBS,
-  AArch64::AEK_PROFILE}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS,
+  

[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-27 Thread Krystian Stasiowski via cfe-commits


@@ -4,7 +4,8 @@ void f(T);
 
 template
 struct A {
-  // expected-error@+1{{cannot declare an explicit specialization in a friend}}
+  // expected-error@+2{{cannot declare an explicit specialization in a friend}}
+  // expected-error@+1{{friend function specialization cannot be defined}}

sdkrystian wrote:

@erichkeane I suppose we don't want double-erroring for any of these 
https://godbolt.org/z/Wdo7bqe1v... if that is the case, perhaps we should 
postpone diagnosing friend function definitions until after we call 
`ActOnFunctionDecl`?

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-27 Thread Krystian Stasiowski via cfe-commits


@@ -373,6 +373,7 @@ template  void foo() {} // 
expected-note{{candidate ignored: not a memb
 }
 using ns::foo;
 template  struct A {
+  // expected-error@+1{{friend function specialization cannot be defined}}

sdkrystian wrote:

Per my other comment, I think the right thing to do here is to diagnose friend 
function definitions after calling `ActOnFunctionDecl`... in this case we would 
emit the "no candidate function template was found for dependent friend 
function template specialization" diagnostic, but not "friend function 
specialization cannot be defined".

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[flang] [clang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Tom Eccles via cfe-commits

https://github.com/tblah updated https://github.com/llvm/llvm-project/pull/73111

>From 617d6d23b2f861cd6dceb82f54a2685059b6 Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Thu, 14 Sep 2023 09:09:29 +
Subject: [PATCH 1/8] [flang] Enable alias tags pass by default

Enable by default when optimizing for speed.

For simplicity, only forward the flag to the frontend driver when it
contradicts what is implied by the optimization level.
---
 clang/lib/Driver/ToolChains/Flang.cpp | 20 
 flang/include/flang/Tools/CLOptions.inc   |  8 
 flang/lib/Frontend/CompilerInvocation.cpp | 22 ++
 flang/test/Driver/falias-analysis.f90 |  4 
 flang/test/Driver/mlir-pass-pipeline.f90  |  2 ++
 flang/test/Driver/optimization-remark.f90 | 22 +-
 flang/test/Fir/basic-program.fir  |  4 
 flang/tools/tco/tco.cpp   |  1 +
 8 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 8bdd920c3dcbb79..9382433b94dadfd 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -142,6 +142,26 @@ void Flang::addCodegenOptions(const ArgList &Args,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);
+  if (aliasAnalysis) {
+bool falias_analysis =
+aliasAnalysis->getOption().matches(options::OPT_falias_analysis);
+// only pass on the argument if it does not match that implied by the
+// optimization level
+if (optLevel) {
+  if (!falias_analysis) {
+CmdArgs.push_back("-fno-alias-analysis");
+  }
+} else {
+  if (falias_analysis)
+// requested alias analysis but no optimization enabled
+CmdArgs.push_back("-falias-analysis");
+}
+  }
+
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_flang_experimental_polymorphism,
diff --git a/flang/include/flang/Tools/CLOptions.inc 
b/flang/include/flang/Tools/CLOptions.inc
index c452c023b4a80ce..5a17385fb3dae87 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -157,11 +157,11 @@ inline void addDebugFoundationPass(mlir::PassManager &pm) 
{
   [&]() { return fir::createAddDebugFoundationPass(); });
 }
 
-inline void addFIRToLLVMPass(
-mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel) 
{
+inline void addFIRToLLVMPass(mlir::PassManager &pm,
+llvm::OptimizationLevel optLevel = defaultOptLevel, bool applyTbaa = true) 
{
   fir::FIRToLLVMPassOptions options;
   options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
-  options.applyTBAA = optLevel.isOptimizingForSpeed();
+  options.applyTBAA = applyTbaa;
   options.forceUnifiedTBAATree = useOldAliasTags;
   addPassConditionally(pm, disableFirToLlvmIr,
   [&]() { return fir::createFIRToLLVMPass(options); });
@@ -311,7 +311,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
   if (config.VScaleMin != 0)
 pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, 
config.VScaleMax}));
 
-  fir::addFIRToLLVMPass(pm, config.OptLevel);
+  fir::addFIRToLLVMPass(pm, config.OptLevel, config.AliasAnalysis);
 }
 
 /// Create a pass pipeline for lowering from MLIR to LLVM IR
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index cb4f2d6a6225205..cfb1dd91ead3056 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -242,10 +242,24 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
clang::driver::options::OPT_fno_loop_versioning, false))
 opts.LoopVersioning = 1;
 
-  opts.AliasAnalysis =
-  args.hasFlag(clang::driver::options::OPT_falias_analysis,
-   clang::driver::options::OPT_fno_alias_analysis,
-   /*default=*/false);
+  bool aliasAnalysis = false;
+  bool noAliasAnalysis = false;
+  if (auto *arg =
+  args.getLastArg(clang::driver::options::OPT_falias_analysis,
+  clang::driver::options::OPT_fno_alias_analysis)) {
+if (arg->getOption().matches(clang::driver::options::OPT_falias_analysis))
+  aliasAnalysis = true;
+else
+  noAliasAnalysis = true;
+  }
+  opts.AliasAnalysis = 0;
+  if (opts.OptimizationLevel > 0) {
+if (!noAliasAnalysis)
+  opts.AliasAnalysis = 1;
+  } else {
+if (aliasAnalysis)
+  opts.AliasAnalysis = 1;
+  }
 
   for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
 opts

[clang] [flang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Tom Eccles via cfe-commits


@@ -2,12 +2,25 @@
 ! See flang/test/Fir/tbaa-codegen.fir for a test that the output is correct
 
 ! RUN: %flang -c -emit-llvm -falias-analysis %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
-! RUN: %flang -c -emit-llvm -falias-analysis -fno-alias-analysis %s -o - | 
llvm-dis | FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -Ofast %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -O3 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -O2 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -O1 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-AA --check-prefix=CHECK-ALL
+
+! RUN: %flang -c -emit-llvm -O0 %s -o - | llvm-dis | FileCheck %s 
--check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
+! RUN: %flang -c -emit-llvm -Ofast -fno-alias-analysis %s -o - | llvm-dis | 
FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL

tblah wrote:

I have added a test in this case. `-fno-alias-analysis` takes precedence over 
`-Ofast` no matter their order.

I don't think there is anything in clang that is equivalent to 
`-f[no-]alias-analysis`. These flags were added to flang so we could upstream 
alias analysis without enabling it by default. I would like to keep them after 
enabling by default in case alias analysis leads to any regressions.

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


[clang] [flang] [Flang][Clang] Add support for frame pointers in Flang Driver (PR #72146)

2023-11-27 Thread Radu Salavat via cfe-commits


@@ -49,6 +49,26 @@ class CodeGenOptionsBase {
 class CodeGenOptions : public CodeGenOptionsBase {
 
 public:
+  /// The type of frame pointer used
+  enum class FramePointerKind {
+None,// Omit all frame pointers.
+NonLeaf, // Keep non-leaf frame pointers.
+All, // Keep all frame pointers.
+  };
+
+  static llvm::StringRef getFramePointerKindName(FramePointerKind Kind) {
+switch (Kind) {
+case FramePointerKind::None:
+  return "none";
+case FramePointerKind::NonLeaf:
+  return "non-leaf";
+case FramePointerKind::All:
+  return "all";
+}
+
+llvm_unreachable("invalid FramePointerKind");
+  };
+

Radu2k wrote:

Issue has been addressed

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


[llvm] [clang] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-11-27 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp approved this pull request.

I have similar patch before: https://reviews.llvm.org/D125947, so it LGTM as 
GCC's default behavior has changed. :-)
But please wait for others' opinions.

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-27 Thread Balázs Kéri via cfe-commits

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

From 5300f979c96eb2f88c298872f0519e274c155cfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 14 Nov 2023 11:53:20 +0100
Subject: [PATCH 1/2] [clang][ASTImporter] Improve structural equivalence of
 overloadable operators.

Operators that are overloadable may be parsed as `CXXOperatorCallExpr`
or as `UnaryOperator` (or `BinaryOperator`). This depends on the context
and can be different if a similar construct is imported into an existing AST.
The two "forms" of the operator call AST nodes should be detected as
equivalent to allow AST import of these cases.

This fix has probably other consequences because if a structure is imported
that has `CXXOperatorCallExpr` into an AST with an existing similar structure
that has `UnaryOperator` (or binary), the additional data in the
`CXXOperatorCallExpr` node is lost at the import (because the existing node
will be used). I am not sure if this can cause problems.
---
 clang/lib/AST/ASTStructuralEquivalence.cpp|  57 ++
 .../AST/StructuralEquivalenceTest.cpp | 170 ++
 2 files changed, 227 insertions(+)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7b..b937ff0579ca02d 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -98,6 +98,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  Decl *D1, Decl *D2);
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Stmt *S1, const Stmt *S2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const TemplateArgument &Arg1,
  const TemplateArgument &Arg2);
@@ -437,12 +439,67 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const UnaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return UnaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getSubExpr(), E2->getArg(0));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const UnaryOperator *E2) {
+  return E1->getOperator() ==
+ UnaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getSubExpr());
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const BinaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return BinaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getLHS(), E2->getArg(0)) &&
+ IsStructurallyEquivalent(Context, E1->getRHS(), E2->getArg(1));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const BinaryOperator *E2) {
+  return E1->getOperator() ==
+ BinaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getLHS()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(1), E2->getRHS());
+}
+
 /// Determine structural equivalence of two statements.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const Stmt *S1, const Stmt *S2) {
   if (!S1 || !S2)
 return S1 == S2;
 
+  // Check for statements with similar syntax but different AST.
+  // The unary and binary operators (like '+', '&') can be parsed as
+  // CXXOperatorCall too (and UnaryOperator or BinaryOperator).
+  // This depends on arguments with unresolved type and on the name lookup.
+  // The lookup results can be different in a "From" and "To" AST even if the
+  // compared structure is otherwise equivalent. For this reason we must treat
+  // these operators as equivalent even if they are represented by different 
AST
+  // nodes.
+  if (const auto *E2CXXOperatorCall = dyn_cast(S2)) {
+if (const auto *E1Unary = dyn_cast(S1))
+  return IsStructurallyEquivalent(Context, E1Unary, E2CXXOperatorCall);
+if (const auto *E1Binary = dyn_cast(S1))
+  return IsStructurallyEquivalent(Context, E1Binary, E2CXXOperatorCall);
+  }
+  if

[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-27 Thread Balázs Kéri via cfe-commits

balazske wrote:

I have updated the comment.
Probably I can test it with more projects after the other fixes with variable 
templates (#72841) are finished, then there may be less crashes.

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-27 Thread via cfe-commits

tomekpaszek wrote:

> After giving more thoughts to this, I think what we really want is 
> `SkipMacroDefinitionBody`, which would format the code below:
> (...)
> That is, only the body (except comments) of a macro definition is not 
> formatted.

I understand that: 
- we do want to align the macros (respect IndentPPDirectives)
- we do want to remove extra whitespaces before, within and right after the 
first token (#define)
- we do NOT want to touch the body
- we do NOT want to break lines

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -1280,6 +1280,7 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
   OS << "typedef __SVBfloat16_t svbfloat16_t;\n";
 
   OS << "#include \n";
+  OS << "#include \n";

sdesmalen-arm wrote:

I'm missing similar changes for NeonEmitter.cpp where this include would be 
added for arm_neon.h and where the types are removed from arm_neon.h so that we 
don't end up with duplicate typedefs.

Duplicate typedefs is not an issue when they are exactly the same (from C11 
onward), but as I pointed out above, they are subtly different, which leads to 
issues.

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -2546,6 +2548,44 @@ void NeonEmitter::runFP16(raw_ostream &OS) {
   OS << "#endif /* __ARM_FP16_H */\n";
 }
 
+void NeonEmitter::runVectorType(raw_ostream &OS) {
+  OS << "/*=== arm_vector_type - ARM vector type "
+"--===\n"
+" *\n"
+" *\n"
+" * Part of the LLVM Project, under the Apache License v2.0 with LLVM "
+"Exceptions.\n"
+" * See https://llvm.org/LICENSE.txt for license information.\n"
+" * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
+" *\n"
+" 
*===-"
+"--===\n"
+" */\n\n";
+  OS << "#ifndef __ARM_NEON_TYPES_H\n";
+  OS << "#define __ARM_NEON_TYPES_H\n";
+  OS << "#ifdef __cplusplus\n";
+  OS << "extern \"C\" {\n";

sdesmalen-arm wrote:

Is `extern "C"` required? My understanding is that only affects the mangling of 
function names, of which there are non in the generated header file.

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -279,11 +282,14 @@ cl::opt Action(
"Generate riscv_vector_builtin_cg.inc for clang"),
 clEnumValN(GenRISCVVectorBuiltinSema, "gen-riscv-vector-builtin-sema",
"Generate riscv_vector_builtin_sema.inc for clang"),
-clEnumValN(GenRISCVSiFiveVectorBuiltins, 
"gen-riscv-sifive-vector-builtins",
+clEnumValN(GenRISCVSiFiveVectorBuiltins,

sdesmalen-arm wrote:

unrelated changes?

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -2546,6 +2548,44 @@ void NeonEmitter::runFP16(raw_ostream &OS) {
   OS << "#endif /* __ARM_FP16_H */\n";
 }
 
+void NeonEmitter::runVectorType(raw_ostream &OS) {
+  OS << "/*=== arm_vector_type - ARM vector type "
+"--===\n"
+" *\n"
+" *\n"
+" * Part of the LLVM Project, under the Apache License v2.0 with LLVM "
+"Exceptions.\n"
+" * See https://llvm.org/LICENSE.txt for license information.\n"
+" * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
+" *\n"
+" 
*===-"
+"--===\n"
+" */\n\n";
+  OS << "#ifndef __ARM_NEON_TYPES_H\n";
+  OS << "#define __ARM_NEON_TYPES_H\n";
+  OS << "#ifdef __cplusplus\n";
+  OS << "extern \"C\" {\n";
+  OS << "#endif\n";
+  OS << "#ifndef __ARM_NEON_H\n";
+
+  std::string TypedefTypes("QcQsQiQlQUcQUsQUiQUlQhQfQdQb");

sdesmalen-arm wrote:

This only emits the 128-bit vector types which are needed arm_sve.h, but not 
the others. The name `arm_vector_type.h` suggests this contains all vector 
types. Maybe you can rename the header file to 
`arm_neon_sve_compatible_vector_types.h` or something?

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -0,0 +1,13 @@
+//===--- arm_vector_type.td - ARM Fixed vector types compiler interface 
---===//

sdesmalen-arm wrote:

What is the value of this file?

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -2546,6 +2548,44 @@ void NeonEmitter::runFP16(raw_ostream &OS) {
   OS << "#endif /* __ARM_FP16_H */\n";
 }
 
+void NeonEmitter::runVectorType(raw_ostream &OS) {
+  OS << "/*=== arm_vector_type - ARM vector type "

sdesmalen-arm wrote:

For here and everywhere else in this patch (in function names, file names, 
etc), please use `vector types` (plural) rather than `vector type`.

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -2546,6 +2548,44 @@ void NeonEmitter::runFP16(raw_ostream &OS) {
   OS << "#endif /* __ARM_FP16_H */\n";
 }
 
+void NeonEmitter::runVectorType(raw_ostream &OS) {
+  OS << "/*=== arm_vector_type - ARM vector type "
+"--===\n"
+" *\n"
+" *\n"
+" * Part of the LLVM Project, under the Apache License v2.0 with LLVM "
+"Exceptions.\n"
+" * See https://llvm.org/LICENSE.txt for license information.\n"
+" * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
+" *\n"
+" 
*===-"
+"--===\n"
+" */\n\n";
+  OS << "#ifndef __ARM_NEON_TYPES_H\n";
+  OS << "#define __ARM_NEON_TYPES_H\n";
+  OS << "#ifdef __cplusplus\n";
+  OS << "extern \"C\" {\n";
+  OS << "#endif\n";
+  OS << "#ifndef __ARM_NEON_H\n";
+
+  std::string TypedefTypes("QcQsQiQlQUcQUsQUiQUlQhQfQdQb");
+  std::vector TDTypeVec = TypeSpec::fromTypeSpecs(TypedefTypes);
+  for (auto &TS : TDTypeVec) {
+Type T(TS, ".");
+OS << "typedef __attribute__((vector_size(16))) ";

sdesmalen-arm wrote:

This is using `vector_type`, as opposed to `neon_vector_type` which is used in 
arm_neon.h. This means that when you would do:
```
#include 
#include 
```
you would get an error that you've redeclared some of these types. See: 
https://godbolt.org/z/ddbGrsYKK

>From what I can tell, the attributes are almost the same with the exception 
>that Clang ensures that:
* NEON/MVE is enabled in order for these attributes to be valid
* the number of elements / element-type is a valid combination for NEON.

My suggestion would be to use `vector_type` in the separate header like you're 
doing here since we don't really need the additional checks, because;
* In arm_neon.h it requires NEON to be enabled to even get to the typedef
* We know that the combination of number of elements / element type is valid.

You just need to make sure to remove the conflicting typedefs from arm_neon.h.

It may also be worth adding something like this to this header file:
```
#if !defined(__ARM_NEON) && !defined(__ARM_SVE)
#error "This header should only be included from arm_neon.h or arm_sve.h"
#endif
```
to avoid this header being used outside of the suggested use.

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-27 Thread Sander de Smalen via cfe-commits


@@ -0,0 +1,113 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3

sdesmalen-arm wrote:

Given my previous comment, I think it's also worth having a test for:
```
 #include 
 #include 
```
and
```
 #include 
 #include 
```
Maybe you can modify this test with some extra RUN lines and `#ifdef` logic for 
the includes.

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-27 Thread via cfe-commits
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= 
Message-ID:
In-Reply-To: 



@@ -437,12 +439,67 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const UnaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return UnaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getSubExpr(), E2->getArg(0));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const UnaryOperator *E2) {
+  return E1->getOperator() ==
+ UnaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getSubExpr());
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const BinaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return BinaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getLHS(), E2->getArg(0)) &&
+ IsStructurallyEquivalent(Context, E1->getRHS(), E2->getArg(1));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const BinaryOperator *E2) {
+  return E1->getOperator() ==
+ BinaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getLHS()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(1), E2->getRHS());
+}
+
 /// Determine structural equivalence of two statements.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const Stmt *S1, const Stmt *S2) {
   if (!S1 || !S2)
 return S1 == S2;
 
+  // Check for statements with similar syntax but different AST.
+  // The unary and binary operators (like '+', '&') can be parsed as
+  // CXXOperatorCall too (and UnaryOperator or BinaryOperator).
+  // This depends on arguments with unresolved type and on the name lookup.

DonatNagyE wrote:

Thanks, the updated comment is clear now.

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


[clang] [clang][Interp] Diagnose reads from non-const global variables (PR #71919)

2023-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 047249032d70e486380e8790915a8edeb70add56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 27 Nov 2023 12:10:48 +0100
Subject: [PATCH 1/2] [clang][Interp][NFC] Remove unused include

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f45e8624a7741a5..f7f8e6c73d84e21 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -15,7 +15,6 @@
 #include "Function.h"
 #include "PrimType.h"
 #include "Program.h"
-#include "State.h"
 
 using namespace clang;
 using namespace clang::interp;

>From 5f0b63a3cfd65893a4424605cccf1679767e8622 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 9 Nov 2023 15:45:05 +0100
Subject: [PATCH 2/2] [clang][Interp] Diagnose reads from non-const global
 variables

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  2 +-
 clang/lib/AST/Interp/Interp.cpp  | 44 ++--
 clang/lib/AST/Interp/Interp.h| 14 
 clang/lib/AST/Interp/Opcodes.td  |  1 +
 clang/test/AST/Interp/arrays.cpp | 32 +
 clang/test/AST/Interp/cxx23.cpp  | 25 +-
 clang/test/AST/Interp/literals.cpp   | 27 +--
 7 files changed, 122 insertions(+), 23 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f7f8e6c73d84e21..537ff39b9f8f953 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2120,7 +2120,7 @@ bool ByteCodeExprGen::visitDecl(const VarDecl 
*VD) {
 auto GlobalIndex = P.getGlobal(VD);
 assert(GlobalIndex); // visitVarDecl() didn't return false.
 if (VarT) {
-  if (!this->emitGetGlobal(*VarT, *GlobalIndex, VD))
+  if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
 return false;
 } else {
   if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 13b77e9a87725c7..f531a44a5b05e2f 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -53,6 +53,18 @@ static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset) {
   return true;
 }
 
+static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
+ const ValueDecl *VD) {
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  S.FFDiag(Loc,
+   VD->getType()->isIntegralOrEnumerationType()
+   ? diag::note_constexpr_ltor_non_const_int
+   : diag::note_constexpr_ltor_non_constexpr,
+   1)
+  << VD;
+  S.Note(VD->getLocation(), diag::note_declared_at);
+}
+
 static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
 AccessKinds AK) {
   if (Ptr.isActive())
@@ -159,9 +171,7 @@ bool CheckExtern(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
 
   if (!S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus) {
 const auto *VD = Ptr.getDeclDesc()->asValueDecl();
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_ltor_non_constexpr, 1) << VD;
-S.Note(VD->getLocation(), diag::note_declared_at);
+diagnoseNonConstVariable(S, OpPC, VD);
   }
   return false;
 }
@@ -204,6 +214,24 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer 
&Ptr,
   return true;
 }
 
+bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
+  assert(Desc);
+  if (const auto *D = Desc->asValueDecl()) {
+if (const auto *VD = dyn_cast(D);
+VD && VD->hasGlobalStorage() &&
+!(VD->isConstexpr() || VD->getType().isConstQualified())) {
+  diagnoseNonConstVariable(S, OpPC, VD);
+  return false;
+}
+  }
+
+  return true;
+}
+
+static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+  return CheckConstant(S, OpPC, Ptr.getDeclDesc());
+}
+
 bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   return !Ptr.isZero() && !Ptr.isDummy();
 }
@@ -292,6 +320,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   if (!CheckDummy(S, OpPC, Ptr))
 return false;
+  if (!CheckConstant(S, OpPC, Ptr))
+return false;
   if (!CheckLive(S, OpPC, Ptr, AK_Read))
 return false;
   if (!CheckExtern(S, OpPC, Ptr))
@@ -590,13 +620,7 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const 
DeclRefExpr *DR) {
 }
   } else if (const auto *VD = dyn_cast(D)) {
 if (!VD->getType().isConstQualified()) {
-  S.FFDiag(E,
-   VD->getType()->isIntegralOrEnumerationType()
-   ? dia

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-11-27 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


cor3ntin wrote:

@tbaederr I will need time to review/discuss this patch with other folks 
(@AaronBallman). 
I thought we had agreement on a direction before it got reverted completely and 
it is not clear to me that doing whole file lexing for each warning isn't going 
to negatively impact some folks.

But I haven't forgotten about it!

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


[clang-tools-extra] [clangd] Add tweak to inline concept requirements (PR #69693)

2023-11-27 Thread via cfe-commits

https://github.com/Venyla updated 
https://github.com/llvm/llvm-project/pull/69693

>From d42a9f963471d6e78584febdacf4c5e99419a3c2 Mon Sep 17 00:00:00 2001
From: Vina Zahnd 
Date: Fri, 20 Oct 2023 10:01:54 +0200
Subject: [PATCH] [clangd] Add tweak to inline concept requirements

Co-authored-by: Jeremy Stucki 
---
 .../clangd/refactor/tweaks/CMakeLists.txt |   1 +
 .../tweaks/InlineConceptRequirement.cpp   | 265 ++
 .../clangd/unittests/CMakeLists.txt   |   1 +
 .../tweaks/InlineConceptRequirementTests.cpp  |  94 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +
 5 files changed, 364 insertions(+)
 create mode 100644 
clang-tools-extra/clangd/refactor/tweaks/InlineConceptRequirement.cpp
 create mode 100644 
clang-tools-extra/clangd/unittests/tweaks/InlineConceptRequirementTests.cpp

diff --git a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt 
b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
index 526a073f619ea34..b01053faf738a90 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangDaemonTweaks OBJECT
   ExpandMacro.cpp
   ExtractFunction.cpp
   ExtractVariable.cpp
+  InlineConceptRequirement.cpp
   MemberwiseConstructor.cpp
   ObjCLocalizeStringLiteral.cpp
   ObjCMemberwiseInitializer.cpp
diff --git 
a/clang-tools-extra/clangd/refactor/tweaks/InlineConceptRequirement.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/InlineConceptRequirement.cpp
new file mode 100644
index 000..201ad8ee15dc5d5
--- /dev/null
+++ b/clang-tools-extra/clangd/refactor/tweaks/InlineConceptRequirement.cpp
@@ -0,0 +1,265 @@
+//===--- InlineConceptRequirement.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "refactor/Tweak.h"
+#include "support/Logger.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+/// Inlines a concept requirement.
+///
+/// Before:
+///   template  void f(T) requires foo {}
+///^^
+/// After:
+///   template  void f(T) {}
+class InlineConceptRequirement : public Tweak {
+public:
+  const char *id() const final;
+
+  auto prepare(const Selection &Inputs) -> bool override;
+  auto apply(const Selection &Inputs) -> Expected override;
+  auto title() const -> std::string override {
+return "Inline concept requirement";
+  }
+  auto kind() const -> llvm::StringLiteral override {
+return CodeAction::REFACTOR_KIND;
+  }
+
+private:
+  const ConceptSpecializationExpr *ConceptSpecializationExpression;
+  const TemplateTypeParmDecl *TemplateTypeParameterDeclaration;
+  const syntax::Token *RequiresToken;
+
+  static auto getTemplateParameterIndexOfTemplateArgument(
+  const TemplateArgument &TemplateArgument) -> std::optional;
+  auto generateRequiresReplacement(ASTContext &)
+  -> llvm::Expected;
+  auto generateRequiresTokenReplacement(const syntax::TokenBuffer &)
+  -> tooling::Replacement;
+  auto generateTemplateParameterReplacement(ASTContext &Context)
+  -> llvm::Expected;
+
+  static auto findToken(const ParsedAST *, const SourceRange &,
+const tok::TokenKind) -> const syntax::Token *;
+
+  template 
+  static auto findNode(const SelectionTree::Node &Root)
+  -> std::tuple;
+
+  template 
+  static auto findExpression(const SelectionTree::Node &Root)
+  -> std::tuple {
+return findNode(Root);
+  }
+
+  template 
+  static auto findDeclaration(const SelectionTree::Node &Root)
+  -> std::tuple {
+return findNode(Root);
+  }
+};
+
+REGISTER_TWEAK(InlineConceptRequirement)
+
+auto InlineConceptRequirement::prepare(const Selection &Inputs) -> bool {
+  // Check if C++ version is 20 or higher
+  if (!Inputs.AST->getLangOpts().CPlusPlus20)
+return false;
+
+  const auto *Root = Inputs.ASTSelection.commonAncestor();
+  if (!Root)
+return false;
+
+  const SelectionTree::Node *ConceptSpecializationExpressionTreeNode;
+  std::tie(ConceptSpecializationExpression,
+   ConceptSpecializationExpressionTreeNode) =
+  findExpression(*Root);
+  if (!ConceptSpecializationExpression)
+return false;
+
+  // Only allow concepts that are direct children of function template
+  // declarations or function declarations. This excludes conjunctions of
+  // concepts which are not handled.
+  const auto *ParentDeclaration =
+  ConceptSpecializat

[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

2023-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 047249032d70e486380e8790915a8edeb70add56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 27 Nov 2023 12:10:48 +0100
Subject: [PATCH 1/2] [clang][Interp][NFC] Remove unused include

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f45e8624a7741a5..f7f8e6c73d84e21 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -15,7 +15,6 @@
 #include "Function.h"
 #include "PrimType.h"
 #include "Program.h"
-#include "State.h"
 
 using namespace clang;
 using namespace clang::interp;

>From eece512e5c002ac78802192873ec49fec4591975 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 18 Oct 2023 15:36:13 +0200
Subject: [PATCH 2/2] [clang][Interp] Implement inc/dec for IntegralAP

---
 clang/lib/AST/Interp/IntegralAP.h | 12 ++
 clang/test/AST/Interp/intap.cpp   | 66 ++-
 2 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 9019f32e6cef2a3..d5f46409d231d48 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -182,17 +182,13 @@ template  class IntegralAP final {
   }
 
   static bool increment(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return add(A, One, A.bitWidth() + 1, R);
   }
 
   static bool decrement(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return sub(A, One, A.bitWidth() + 1, R);
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index c93ec331296647b..b99422dc8f93125 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -57,9 +57,25 @@ namespace APCast {
 }
 
 #ifdef __SIZEOF_INT128__
+typedef __int128 int128_t;
+typedef unsigned __int128 uint128_t;
+static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
+static_assert(UINT128_MAX == -1, "");
+static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion 
failed}} \
+ // expected-note 
{{'340282366920938463463374607431768211455 == 1'}} \
+ // ref-error {{static assertion failed}} \
+ // ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
+
+static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
+static_assert(INT128_MAX != 0, "");
+static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
+// expected-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}} \
+// ref-error {{failed}} \
+// ref-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}}
+static const __int128_t INT128_MIN = -INT128_MAX - 1;
+
 namespace i128 {
-  typedef __int128 int128_t;
-  typedef unsigned __int128 uint128_t;
+
   constexpr int128_t I128_1 = 12;
   static_assert(I128_1 == 12, "");
   static_assert(I128_1 != 10, "");
@@ -200,4 +216,50 @@ namespace BitOps {
   static_assert((Max ^ UZero) == Max, "");
 }
 
+namespace IncDec {
+#if __cplusplus >= 201402L
+  constexpr int128_t maxPlus1(bool Pre) {
+int128_t a = INT128_MAX;
+
+if (Pre)
+  ++a; // ref-note {{value 170141183460469231731687303715884105728 is 
outside the range}} \
+   // expected-note {{value 170141183460469231731687303715884105728 is 
outside the range}}
+else
+  a++; // ref-note {{value 170141183460469231731687303715884105728 is 
outside the range}} \
+   // expected-note {{value 170141183460469231731687303715884105728 is 
outside the range}}
+return a;
+  }
+  static_assert(maxPlus1(true) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+  // ref-note {{in call to}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{in call to}}
+  static_assert(maxPlus1(false) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+   // ref-note {{in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note {{in call to}}
+
+  constexpr int1

[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-27 Thread Owen Pan via cfe-commits

owenca wrote:

> > After giving more thoughts to this, I think what we really want is 
> > `SkipMacroDefinitionBody`, which would format the code below:
> > (...)
> > That is, only the body (except comments) of a macro definition is not 
> > formatted.
> 
> I understand that:
> 
> * we do want to align the macros (respect IndentPPDirectives)
> * we do want to remove extra whitespaces before, within and right after the 
> first token (#define)

We want to format e.g. `#define FOO` and `#define BAR(x, y)`.

> * we do NOT want to touch the body
> * we do NOT want to break lines

We don't want to change line splicing (if any) within the body.

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-27 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From 2a2693364cb8e9b657b9ff54aa78df0466b55fe4 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 01/11] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206ee8..740ae71177b2c3a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -982,7 +982,20 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC,
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -993,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
  ArgStringList &CmdArgs) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 0d652282f4dbed2dde11df53ead3e6c8b6856bed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 02/11] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 740ae71177b2c3a..464a87737de062c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -987,10 +987,10 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1006,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
  ArgStringList &CmdArgs) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 39612e237cb815cf4ea0120027783d35304bcb6b Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 03/11] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 85c4d60b3f09862..ea91946316cfaa6 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -28,7 +28,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran

[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-27 Thread Michael Klemm via cfe-commits

mjklemm wrote:

FYI: Rebased and resolved conflict flagged by GitHub.  Alas, this means that I 
have lost the change to also make the linker fail on Windows.  I've sent a 
request to the authors of the code to perform linking on Windows to help me 
figure out what to do.

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


[flang] [clang] [clang-tools-extra] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-27 Thread Yi Wu via cfe-commits

yi-wu-arm wrote:

> > Hello @klausler, could you please share your thoughts or comments on this 
> > patch, particularly with regard to the Windows side? Thanks in advance.
> 
> You should use modern C++ braced initialization in flang/runtime.

Hi @klausler. Thanks for the comment! I have updated the runtime file with 
variables being braced initialized. Any other things that I should be aware of? 
Thanks in advance.

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


[clang] [clang] Fix sorting header paths (PR #73323)

2023-11-27 Thread Tulio Magno Quites Machado Filho via cfe-commits

tuliom wrote:

> So what breakage is caused by the sorting failure?

@dwblaikie This is not causing a breakage. It is just not working as designed 
because the sort function has been comparing `""` against `""` since commit 
https://github.com/llvm/llvm-project/commit/e6830b6028ec5434ccf8dbebdd992918f67b1751
 .

I found this while investigating issue #73145.

The way the code is behaving now, the sort function is acting as a NOP and 
could be removed. However, I don't think that was the intention of the author 
of 
https://github.com/llvm/llvm-project/commit/7ff29148ac7883881e62dc9e1714057c68ad4436.

> Can that behavior be tested in some way to validate this change and ensure it 
> doesn't regress in the future?

Possibly. Let me think on this.

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-27 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@erichkeane the most recent commit results in the following:
```cpp
template void f(T);
void g() { }

template
struct A {
  // error: cannot declare an explicit specialization in a friend
  template<> friend void f<>(T) { }
  // error: friend function specialization cannot be defined
  friend void f<>(T) { }
  // error: cannot declare an explicit specialization in a friend
  template<> friend void ::g() { }
  // error: friend function definition cannot be qualified with '::'
  friend void ::g() { }
};

void h() {
  void i();
  struct B {
// error: templates can only be declared in namespace or class scope
// error: cannot declare an explicit specialization in a friend
template<> friend void i() { }
// error: friend function cannot be defined in a local class
friend void i() { }
  };
}
```
Unrelated, but it also seems that `template<> friend void f<>(T) { }` causes 
[this 
assert](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDecl.cpp#L10477)
 to fire. This happens because we clear `HasExplicitTemplateArgs` for invalid 
declarations 
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDecl.cpp#L10427).
 I could include a fix, but it might fall outside the scope of this PR.

I also added a release note as requested.

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-27 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/72863

>From 3e191f245325742338eba223a3f98b6bb5ad414b Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 20 Nov 2023 07:11:41 -0500
Subject: [PATCH 1/2] [Clang][Sema] Diagnose friend function specialization
 definitions

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/AST/Decl.cpp |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp | 14 ++
 clang/test/CXX/class.access/class.friend/p6.cpp| 13 +
 clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp  |  8 +---
 .../CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp|  3 ++-
 6 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3f6ca64baf23ae6..35acbb40a4b4f38 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1669,6 +1669,8 @@ def err_qualified_friend_def : Error<
   "friend function definition cannot be qualified with '%0'">;
 def err_friend_def_in_local_class : Error<
   "friend function cannot be defined in a local class">;
+def err_friend_specialization_def : Error<
+  "friend function specialization cannot be defined">;
 def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..527ea6042daa034 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4150,6 +4150,7 @@ 
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
   assert(TSK != TSK_Undeclared &&
  "Must specify the type of function template specialization");
   assert((TemplateOrSpecialization.isNull() ||
+  getFriendObjectKind() != FOK_None ||
   TSK == TSK_ExplicitSpecialization) &&
  "Member specialization must be an explicit specialization");
   FunctionTemplateSpecializationInfo *Info =
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..2bfb02da08bde54 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17960,6 +17960,20 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 
 DCScope = getScopeForDeclContext(S, DC);
 
+// C++ [class.friend]p6:
+//   A function may be defined in a friend declaration of a class if and
+//   only if the class is a non-local class, and the function name is
+//   unqualified.
+//
+// Per [basic.pre]p4, a template-id is not a name. Therefore, if we have
+// a template-id, the function name is not unqualified because these is no
+// name. While the wording requires some reading in-between the lines, GCC,
+// MSVC, and EDG all consider a friend function specialization definitions
+// to be de facto explicit specialization and diagnose them as such.
+if (D.isFunctionDefinition() && isTemplateId) {
+  Diag(NameInfo.getBeginLoc(), diag::err_friend_specialization_def);
+}
+
   //   - There's a non-dependent scope specifier, in which case we
   // compute it and do a previous lookup there for a function
   // or function template.
diff --git a/clang/test/CXX/class.access/class.friend/p6.cpp 
b/clang/test/CXX/class.access/class.friend/p6.cpp
index 2fe20fe77fc8f21..47104e29dc6b3c7 100644
--- a/clang/test/CXX/class.access/class.friend/p6.cpp
+++ b/clang/test/CXX/class.access/class.friend/p6.cpp
@@ -22,3 +22,16 @@ void local() {
 friend void f() { } // expected-error{{friend function cannot be defined 
in a local class}}
   };
 }
+
+template void f3(T);
+
+namespace N {
+  template void f4(T);
+}
+
+template struct A {
+  friend void f3(T) {}
+  friend void f3(T) {} // expected-error{{friend function specialization 
cannot be defined}}
+  friend void N::f4(T) {} // expected-error{{friend function definition cannot 
be qualified with 'N::'}}
+  friend void N::f4(T) {} // expected-error{{friend function definition 
cannot be qualified with 'N::'}}
+};
diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp 
b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
index ab1b9f7a73eec89..974b080f2783934 100644
--- a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -17,7 +17,7 @@ template  struct Num {
   for (U count = n.count_; count; --count)
 x += a;
   return x;
-} 
+}
   };
 
   friend Num operator+(const Num &a, const Num &b) {
@@ -145,7 +145,7 @@ namespace test5 {
 
 namespace Dependent {
   template class X;
-  template 
+  template
   X operator+(const X&, const T*);
 
   template class X {
@@ -249,7 +249,7 @@ namespace test11 {
   };
 
   template struct Foo::IteratorImpl;
-  template struct Foo::IteratorImpl;  
+  template struct Fo

[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-27 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 57a11b7f75742ba74b563b8af75bc106a1e9d29e 
2dc6567a7054feb755351b8d403b228f3d4b91ea -- clang/lib/AST/Decl.cpp 
clang/lib/Sema/SemaDeclCXX.cpp clang/test/CXX/class.access/class.friend/p6.cpp 
clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp clang/test/SemaCXX/friend.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9dbfd92de7..b6748f8404 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17870,8 +17870,7 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
   LookupResult Previous(*this, NameInfo, LookupOrdinaryName,
 ForExternalRedeclaration);
 
-  bool isTemplateId =
-  D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId;
+  bool isTemplateId = D.getName().getKind() == 
UnqualifiedIdKind::IK_TemplateId;
 
   // There are five cases here.
   //   - There's no scope specifier and we're in a local class. Only look
@@ -18072,8 +18071,8 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 // FIXME: We should only do this if the scope specifier names the
 // innermost enclosing namespace; otherwise the fixit changes the
 // meaning of the code.
-SemaDiagnosticBuilder DB
-  = Diag(SS.getRange().getBegin(), diag::err_qualified_friend_def);
+SemaDiagnosticBuilder DB =
+Diag(SS.getRange().getBegin(), diag::err_qualified_friend_def);
 
 DB << SS.getScopeRep();
 if (DC->isFileContext())
@@ -18085,9 +18084,10 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
   }
   // Per [basic.pre]p4, a template-id is not a name. Therefore, if we have
   // a template-id, the function name is not unqualified because these is 
no
-  // name. While the wording requires some reading in-between the lines, 
GCC,
-  // MSVC, and EDG all consider a friend function specialization 
definitions
-  // to be de facto explicit specialization and diagnose them as such.
+  // name. While the wording requires some reading in-between the lines,
+  // GCC, MSVC, and EDG all consider a friend function specialization
+  // definitions to be de facto explicit specialization and diagnose them 
as
+  // such.
   else if (isTemplateId) {
 Diag(NameInfo.getBeginLoc(), diag::err_friend_specialization_def);
   }

``




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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-27 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/72863

>From 3e191f245325742338eba223a3f98b6bb5ad414b Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 20 Nov 2023 07:11:41 -0500
Subject: [PATCH 1/2] [Clang][Sema] Diagnose friend function specialization
 definitions

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/AST/Decl.cpp |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp | 14 ++
 clang/test/CXX/class.access/class.friend/p6.cpp| 13 +
 clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp  |  8 +---
 .../CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp|  3 ++-
 6 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3f6ca64baf23ae6..35acbb40a4b4f38 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1669,6 +1669,8 @@ def err_qualified_friend_def : Error<
   "friend function definition cannot be qualified with '%0'">;
 def err_friend_def_in_local_class : Error<
   "friend function cannot be defined in a local class">;
+def err_friend_specialization_def : Error<
+  "friend function specialization cannot be defined">;
 def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..527ea6042daa034 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4150,6 +4150,7 @@ 
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
   assert(TSK != TSK_Undeclared &&
  "Must specify the type of function template specialization");
   assert((TemplateOrSpecialization.isNull() ||
+  getFriendObjectKind() != FOK_None ||
   TSK == TSK_ExplicitSpecialization) &&
  "Member specialization must be an explicit specialization");
   FunctionTemplateSpecializationInfo *Info =
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..2bfb02da08bde54 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17960,6 +17960,20 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 
 DCScope = getScopeForDeclContext(S, DC);
 
+// C++ [class.friend]p6:
+//   A function may be defined in a friend declaration of a class if and
+//   only if the class is a non-local class, and the function name is
+//   unqualified.
+//
+// Per [basic.pre]p4, a template-id is not a name. Therefore, if we have
+// a template-id, the function name is not unqualified because these is no
+// name. While the wording requires some reading in-between the lines, GCC,
+// MSVC, and EDG all consider a friend function specialization definitions
+// to be de facto explicit specialization and diagnose them as such.
+if (D.isFunctionDefinition() && isTemplateId) {
+  Diag(NameInfo.getBeginLoc(), diag::err_friend_specialization_def);
+}
+
   //   - There's a non-dependent scope specifier, in which case we
   // compute it and do a previous lookup there for a function
   // or function template.
diff --git a/clang/test/CXX/class.access/class.friend/p6.cpp 
b/clang/test/CXX/class.access/class.friend/p6.cpp
index 2fe20fe77fc8f21..47104e29dc6b3c7 100644
--- a/clang/test/CXX/class.access/class.friend/p6.cpp
+++ b/clang/test/CXX/class.access/class.friend/p6.cpp
@@ -22,3 +22,16 @@ void local() {
 friend void f() { } // expected-error{{friend function cannot be defined 
in a local class}}
   };
 }
+
+template void f3(T);
+
+namespace N {
+  template void f4(T);
+}
+
+template struct A {
+  friend void f3(T) {}
+  friend void f3(T) {} // expected-error{{friend function specialization 
cannot be defined}}
+  friend void N::f4(T) {} // expected-error{{friend function definition cannot 
be qualified with 'N::'}}
+  friend void N::f4(T) {} // expected-error{{friend function definition 
cannot be qualified with 'N::'}}
+};
diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp 
b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
index ab1b9f7a73eec89..974b080f2783934 100644
--- a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -17,7 +17,7 @@ template  struct Num {
   for (U count = n.count_; count; --count)
 x += a;
   return x;
-} 
+}
   };
 
   friend Num operator+(const Num &a, const Num &b) {
@@ -145,7 +145,7 @@ namespace test5 {
 
 namespace Dependent {
   template class X;
-  template 
+  template
   X operator+(const X&, const T*);
 
   template class X {
@@ -249,7 +249,7 @@ namespace test11 {
   };
 
   template struct Foo::IteratorImpl;
-  template struct Foo::IteratorImpl;  
+  template struct Fo

[clang] [llvm] [clang, SystemZ] Pass HasDef flag to getMinGlobalAlign(). (PR #73511)

2023-11-27 Thread Jonas Paulsson via cfe-commits

https://github.com/JonPsson1 created 
https://github.com/llvm/llvm-project/pull/73511

External symbols created from a linker script may not get the ABI minimum 
alignment and must therefore be treated as unaligned by the compiler.

To implement this, getMinGlobalAlign() (and getAlignOfGlobalVar) gets a second 
parameter 'HasDef', which lets SystemZTargetInfo::getMinGlobalAlign() handle 
this.

My first idea was to pass a VarDecl to getMinGlobalAlign(), and assume the 
value to be external only in cases of (VD && !VD->hasDefiniton()). I got 
however link problems with 'ninja check', so opted to pass a boolean 'HasDef' 
instead. In SemaOpenMP.cpp the check with VD was added, and in 
CodeGenModule.cpp 'true' is
passed for strings (which I am hoping is correct as the strings seem to be 
passed to the functions which makes it look like they are being created for the 
module...)

The assumption generally would then be that everything is generated for the 
module except for a VarDecl that returns false in hasDefinition().

This is controlled by a new CL option '-munaligned-symbols', where I looked at 
-munaligned-access (e.g. RISCVTargetInfo::handleTargetFeatures() / 
FastUnalignedAccess).

SystemZ:

- Test: I reused Andreas' test for GCC and also added cases of char arrays and 
structs, but not sure if those are relevant/needed after all as they just 
worked without any extra handling...

- The backend seems to emit a GOT lookup also for the external and aligned 
cases - I suppose this is because the linker will fixup those...

>From c2f300a46eea861fac1a7f253e5f2998eb6740cd Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Thu, 23 Nov 2023 17:22:32 +0100
Subject: [PATCH] IP

---
 clang/include/clang/AST/ASTContext.h  |   4 +-
 clang/include/clang/Basic/TargetInfo.h|   7 +-
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/AST/ASTContext.cpp  |  15 ++-
 clang/lib/Basic/Targets/AArch64.cpp   |   5 +-
 clang/lib/Basic/Targets/AArch64.h |   2 +-
 clang/lib/Basic/Targets/CSKY.cpp  |   2 +-
 clang/lib/Basic/Targets/CSKY.h|   2 +-
 clang/lib/Basic/Targets/NVPTX.cpp |   3 +-
 clang/lib/Basic/Targets/SPIR.h|   3 +-
 clang/lib/Basic/Targets/SystemZ.cpp   |  10 ++
 clang/lib/Basic/Targets/SystemZ.h |   9 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   7 +-
 clang/lib/Driver/ToolChains/Arch/SystemZ.cpp  |   8 ++
 clang/lib/Sema/SemaOpenMP.cpp |   3 +-
 .../test/CodeGen/SystemZ/unaligned-symbols.c  | 104 ++
 llvm/lib/Target/SystemZ/SystemZFeatures.td|   5 +
 17 files changed, 171 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/unaligned-symbols.c

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3e46a5da3fc043f..9e60ca8fb2ea8c6 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2406,11 +2406,11 @@ class ASTContext : public RefCountedBase {
 
   /// Return the alignment in bits that should be given to a
   /// global variable with type \p T.
-  unsigned getAlignOfGlobalVar(QualType T) const;
+  unsigned getAlignOfGlobalVar(QualType T, bool HasDef) const;
 
   /// Return the alignment in characters that should be given to a
   /// global variable with type \p T.
-  CharUnits getAlignOfGlobalVarInChars(QualType T) const;
+  CharUnits getAlignOfGlobalVarInChars(QualType T, bool HasDef) const;
 
   /// Return a conservative estimate of the alignment of the specified
   /// decl \p D.
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 41f3c2e403cbef6..1a536b3448df162 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -705,8 +705,11 @@ class TargetInfo : public TransferrableTargetInfo,
   }
 
   /// getMinGlobalAlign - Return the minimum alignment of a global variable,
-  /// unless its alignment is explicitly reduced via attributes.
-  virtual unsigned getMinGlobalAlign (uint64_t) const {
+  /// unless its alignment is explicitly reduced via attributes. It may be
+  /// that an external symbol needs to be considered unaligned (like
+  /// artificial symbols created from a linker script). If \param HasDef is
+  /// false, this symbol does not have a definition and is external.
+  virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasDef) const {
 return MinGlobalAlign;
   }
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b2f2bcb6ac37910..1ad01c2307c3079 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4544,6 +4544,10 @@ def munaligned_access : Flag<["-"], 
"munaligned-access">, Group,
   HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
 def mno_unaligned_access : Flag<["-"], "m

[clang] [llvm] [clang, SystemZ] Pass HasDef flag to getMinGlobalAlign(). (PR #73511)

2023-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Jonas Paulsson (JonPsson1)


Changes

External symbols created from a linker script may not get the ABI minimum 
alignment and must therefore be treated as unaligned by the compiler.

To implement this, getMinGlobalAlign() (and getAlignOfGlobalVar) gets a second 
parameter 'HasDef', which lets SystemZTargetInfo::getMinGlobalAlign() handle 
this.

My first idea was to pass a VarDecl to getMinGlobalAlign(), and assume the 
value to be external only in cases of (VD && !VD->hasDefiniton()). I 
got however link problems with 'ninja check', so opted to pass a boolean 
'HasDef' instead. In SemaOpenMP.cpp the check with VD was added, and in 
CodeGenModule.cpp 'true' is
passed for strings (which I am hoping is correct as the strings seem to be 
passed to the functions which makes it look like they are being created for the 
module...)

The assumption generally would then be that everything is generated for the 
module except for a VarDecl that returns false in hasDefinition().

This is controlled by a new CL option '-munaligned-symbols', where I looked at 
-munaligned-access (e.g. RISCVTargetInfo::handleTargetFeatures() / 
FastUnalignedAccess).

SystemZ:

- Test: I reused Andreas' test for GCC and also added cases of char arrays and 
structs, but not sure if those are relevant/needed after all as they just 
worked without any extra handling...

- The backend seems to emit a GOT lookup also for the external and aligned 
cases - I suppose this is because the linker will fixup those...

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


17 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+2-2) 
- (modified) clang/include/clang/Basic/TargetInfo.h (+5-2) 
- (modified) clang/include/clang/Driver/Options.td (+4) 
- (modified) clang/lib/AST/ASTContext.cpp (+9-6) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+3-2) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+1-1) 
- (modified) clang/lib/Basic/Targets/CSKY.cpp (+1-1) 
- (modified) clang/lib/Basic/Targets/CSKY.h (+1-1) 
- (modified) clang/lib/Basic/Targets/NVPTX.cpp (+2-1) 
- (modified) clang/lib/Basic/Targets/SPIR.h (+2-1) 
- (modified) clang/lib/Basic/Targets/SystemZ.cpp (+10) 
- (modified) clang/lib/Basic/Targets/SystemZ.h (+8-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4-3) 
- (modified) clang/lib/Driver/ToolChains/Arch/SystemZ.cpp (+8) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+2-1) 
- (added) clang/test/CodeGen/SystemZ/unaligned-symbols.c (+104) 
- (modified) llvm/lib/Target/SystemZ/SystemZFeatures.td (+5) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3e46a5da3fc043f..9e60ca8fb2ea8c6 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2406,11 +2406,11 @@ class ASTContext : public RefCountedBase {
 
   /// Return the alignment in bits that should be given to a
   /// global variable with type \p T.
-  unsigned getAlignOfGlobalVar(QualType T) const;
+  unsigned getAlignOfGlobalVar(QualType T, bool HasDef) const;
 
   /// Return the alignment in characters that should be given to a
   /// global variable with type \p T.
-  CharUnits getAlignOfGlobalVarInChars(QualType T) const;
+  CharUnits getAlignOfGlobalVarInChars(QualType T, bool HasDef) const;
 
   /// Return a conservative estimate of the alignment of the specified
   /// decl \p D.
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 41f3c2e403cbef6..1a536b3448df162 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -705,8 +705,11 @@ class TargetInfo : public TransferrableTargetInfo,
   }
 
   /// getMinGlobalAlign - Return the minimum alignment of a global variable,
-  /// unless its alignment is explicitly reduced via attributes.
-  virtual unsigned getMinGlobalAlign (uint64_t) const {
+  /// unless its alignment is explicitly reduced via attributes. It may be
+  /// that an external symbol needs to be considered unaligned (like
+  /// artificial symbols created from a linker script). If \param HasDef is
+  /// false, this symbol does not have a definition and is external.
+  virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasDef) const {
 return MinGlobalAlign;
   }
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b2f2bcb6ac37910..1ad01c2307c3079 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4544,6 +4544,10 @@ def munaligned_access : Flag<["-"], 
"munaligned-access">, Group,
   HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
   HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+def munaligned_symbols : Flag<["-"], "

[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2023-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 047249032d70e486380e8790915a8edeb70add56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 27 Nov 2023 12:10:48 +0100
Subject: [PATCH 1/2] [clang][Interp][NFC] Remove unused include

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f45e8624a7741a5..f7f8e6c73d84e21 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -15,7 +15,6 @@
 #include "Function.h"
 #include "PrimType.h"
 #include "Program.h"
-#include "State.h"
 
 using namespace clang;
 using namespace clang::interp;

>From 63542819d018c6cfec64af759b79af15fb2eb1e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 31 Oct 2023 14:57:51 +0100
Subject: [PATCH 2/2] EvaluationResult

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/ExprConstant.cpp|  23 ++-
 clang/lib/AST/Interp/ByteCodeEmitter.cpp  |  13 +-
 clang/lib/AST/Interp/ByteCodeEmitter.h|   5 +-
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  |   4 +-
 clang/lib/AST/Interp/ByteCodeExprGen.h|   4 -
 clang/lib/AST/Interp/Context.cpp  | 106 
 clang/lib/AST/Interp/Context.h|   3 +
 clang/lib/AST/Interp/EvalEmitter.cpp  | 153 +
 clang/lib/AST/Interp/EvalEmitter.h|  11 +-
 clang/lib/AST/Interp/EvaluationResult.cpp | 196 ++
 clang/lib/AST/Interp/EvaluationResult.h   | 111 
 clang/lib/AST/Interp/Interp.cpp   |  92 --
 clang/lib/AST/Interp/Interp.h |  16 +-
 clang/lib/AST/Interp/Opcodes.td   |   2 -
 clang/lib/AST/Interp/Pointer.cpp  | 132 ---
 clang/lib/AST/Interp/Pointer.h|   3 +-
 clang/test/AST/Interp/records.cpp |   1 -
 18 files changed, 574 insertions(+), 302 deletions(-)
 create mode 100644 clang/lib/AST/Interp/EvaluationResult.cpp
 create mode 100644 clang/lib/AST/Interp/EvaluationResult.h

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..ebcb3952198a5b5 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/EvaluationResult.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 16697e5f076a8f8..6555ed884b9effd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15405,11 +15405,13 @@ static bool EvaluateAsRValue(EvalInfo &Info, const 
Expr *E, APValue &Result) {
   if (Info.EnableNewConstInterp) {
 if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, E, Result))
   return false;
-  } else {
-if (!::Evaluate(Result, Info, E))
-  return false;
+return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result,
+   ConstantExprKind::Normal);
   }
 
+  if (!::Evaluate(Result, Info, E))
+return false;
+
   // Implicit lvalue-to-rvalue cast.
   if (E->isGLValue()) {
 LValue LV;
@@ -15637,6 +15639,13 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   EvalInfo Info(Ctx, Result, EM);
   Info.InConstantContext = true;
 
+  if (Info.EnableNewConstInterp) {
+if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val))
+  return false;
+return CheckConstantExpression(Info, getExprLoc(),
+   getStorageType(Ctx, this), Result.Val, 
Kind);
+  }
+
   // The type of the object we're initializing is 'const T' for a class NTTP.
   QualType T = getType();
   if (Kind == ConstantExprKind::ClassTemplateArgument)
@@ -15712,10 +15721,16 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
   Info.setEvaluatingDecl(VD, Value);
   Info.InConstantContext = IsConstantInitialization;
 
+  SourceLocation DeclLoc = VD->getLocation();
+  QualType DeclTy = VD->getType();
+
   if (Info.EnableNewConstInterp) {
 auto &InterpCtx = const_cast(Ctx).getInterpContext();
 if (!InterpCtx.evaluateAsInitializer(Info, VD, Value))
   return false;
+
+return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
+   ConstantExprKind::Normal);
   } else {
 LValue LVal;
 LVal.set(VD);
@@ -15733,8 +15748,6 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const 
ASTContext &Ctx,
   llvm_unreachable("Unhandled cleanup; missing full expression marker?");
   }
 
-  SourceLocation DeclLoc = VD->getLocation();
-  QualType DeclTy = VD->getType();
   return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
  

[clang] [llvm] [clang-tools-extra] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)

2023-11-27 Thread Björn Pettersson via cfe-commits

bjope wrote:

Tracked down some miscompiles found downstream that points at this commit.
Also wrote a new issue here about it: 
https://github.com/llvm/llvm-project/issues/73512

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


[clang] d7c03a1 - [clang][AArch64][NFC] Remove trailing space in SME intriniscs header

2023-11-27 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2023-11-27T13:31:15Z
New Revision: d7c03a196edb1e5f5a45121bb51899e8f5e72ca6

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

LOG: [clang][AArch64][NFC] Remove trailing space in SME intriniscs header

Added: 


Modified: 
clang/utils/TableGen/SveEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/SveEmitter.cpp 
b/clang/utils/TableGen/SveEmitter.cpp
index d00989ac0f3beb5..b380bd9dfe6643a 100644
--- a/clang/utils/TableGen/SveEmitter.cpp
+++ b/clang/utils/TableGen/SveEmitter.cpp
@@ -1571,7 +1571,7 @@ void SVEEmitter::createSMEHeader(raw_ostream &OS) {
   OS << "#error \"Big endian is currently not supported for 
arm_sme_draft_spec_subject_to_change.h\"\n";
   OS << "#endif\n";
 
-  OS << "#include  \n\n";
+  OS << "#include \n\n";
 
   OS << "/* Function attributes */\n";
   OS << "#define __ai static __inline__ __attribute__((__always_inline__, "



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


[clang] 5bd643e - [clang][dataflow] Strengthen widening of boolean values. (#73484)

2023-11-27 Thread via cfe-commits

Author: martinboehme
Date: 2023-11-27T14:55:49+01:00
New Revision: 5bd643e1456bd2acc53ac0bf594d285be89a44fe

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

LOG: [clang][dataflow] Strengthen widening of boolean values. (#73484)

Before we widen to top, we now check if both values can be proved either
true or
false in their respective environments; if so, widening returns a true
or false
literal. The idea is that we avoid losing information if posssible.

This patch includes a test that fails without this change to widening.

This change does mean that we call the SAT solver in more places, but
this seems
acceptable given the additional precision we gain.

In tests on an internal codebase, the number of SAT solver timeouts we
observe
with Crubit's nullability checker does increase by about 25%. They can
be
brought back to the previous level by doubling the SAT solver work
limit.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 1a38be9c1374f65..525ab188b01b8aa 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -157,12 +157,25 @@ static Value &widenDistinctValues(QualType Type, Value 
&Prev,
   Environment &CurrentEnv,
   Environment::ValueModel &Model) {
   // Boolean-model widening.
-  if (isa(&Prev)) {
-assert(isa(Current));
-// Widen to Top, because we know they are 
diff erent values. If previous was
-// already Top, re-use that to (implicitly) indicate that no change 
occured.
+  if (auto *PrevBool = dyn_cast(&Prev)) {
+// If previous value was already Top, re-use that to (implicitly) indicate
+// that no change occurred.
 if (isa(Prev))
   return Prev;
+
+// We may need to widen to Top, but before we do so, check whether both
+// values are implied to be either true or false in the current 
environment.
+// In that case, we can simply return a literal instead.
+auto &CurBool = cast(Current);
+bool TruePrev = PrevEnv.proves(PrevBool->formula());
+bool TrueCur = CurrentEnv.proves(CurBool.formula());
+if (TruePrev && TrueCur)
+  return CurrentEnv.getBoolLiteralValue(true);
+if (!TruePrev && !TrueCur &&
+PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool->formula())) &&
+CurrentEnv.proves(CurrentEnv.arena().makeNot(CurBool.formula(
+  return CurrentEnv.getBoolLiteralValue(false);
+
 return CurrentEnv.makeTopBoolValue();
   }
 

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ade0d202ced2f37..8da55953a329869 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4167,6 +4167,34 @@ TEST(TransferTest, 
LoopWithShortCircuitedConditionConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopCanProveInvariantForBoolean) {
+  // Check that we can prove `b` is always false in the loop.
+  // This test exercises the logic in `widenDistinctValues()` that preserves
+  // information if the boolean can be proved to be either true or false in 
both
+  // the previous and current iteration.
+  std::string Code = R"cc(
+int return_int();
+void target() {
+  bool b = return_int() == 0;
+  if (b) return;
+  while (true) {
+b;
+// [[p]]
+b = return_int() == 0;
+if (b) return;
+  }
+}
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+auto &BVal = getValueForDecl(ASTCtx, Env, "b");
+EXPECT_TRUE(Env.proves(Env.arena().makeNot(BVal.formula(;
+  });
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {



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


[clang] [clang][dataflow] Strengthen widening of boolean values. (PR #73484)

2023-11-27 Thread via cfe-commits

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


[flang] [clang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Kiran Chandramohan via cfe-commits

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


[clang] [flang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Kiran Chandramohan via cfe-commits

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

LGTM.

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


[clang] [flang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Kiran Chandramohan via cfe-commits


@@ -142,6 +142,26 @@ void Flang::addCodegenOptions(const ArgList &Args,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);

kiranchandramohan wrote:

> That's fine, but then one has to decide whether -f{no}-alias-analysis 
> overrides -O{n} or not? I think that "explicit" request from a user should 
> always take precedence. This leads to (pseudo code):
>
> opts.AliasAnalysis = 0;
> if (opt level requiring alias analysis)
>  opts.AliasAnalysis  = 1;
> 
> / / User request takes precedence when it comes to alias analysis.
> if (-falias-analysis or -fno-alias-analysis) then
>  "do whatever the user requested"
>Separately, could you check what Clang does and make sure that that would be 
>consistent?

@banach-space This is exactly the handling in the front-end driver as given 
below (and in `lib/Frontend/CompilerInvocation`). The flang driver is only 
deciding whether to forward or not.

```
  opts.AliasAnalysis = opts.OptimizationLevel > 0;
  if (auto *arg =
  args.getLastArg(clang::driver::options::OPT_falias_analysis,
  clang::driver::options::OPT_fno_alias_analysis))
opts.AliasAnalysis =
arg->getOption().matches(clang::driver::options::OPT_falias_analysis);
```

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


[clang] piper export cl 583969847 (PR #73518)

2023-11-27 Thread via cfe-commits

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

- [clang][dataflow] Strengthen widening of boolean values.
- [clang][dataflow] Defer initialization of `Environment`.
- [clang][dataflow] Add synthetic fields to `RecordStorageLocation`.
- [clang][dataflow] Make UncheckedOptionalAccessModel use synthetic fields.


>From 15433f46c4abd135128e5b366d4d7279aca4320c Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 27 Nov 2023 14:06:41 +
Subject: [PATCH 1/4] [clang][dataflow] Strengthen widening of boolean values.

Before we widen to top, we now check if both values can be proved either true or
false in their respective environments; if so, widening returns a true or false
literal. The idea is that we avoid losing information if posssible.

This patch includes a test that fails without this change to widening.

This change does mean that we call the SAT solver in more places, but this seems
acceptable given the additional precision we gain.

In tests on an internal codebase, the number of SAT solver timeouts we observe
with Crubit's nullability checker does increase by about 25%. They can be
brought back to the previous level by doubling the SAT solver work limit.
---
 .../FlowSensitive/DataflowEnvironment.cpp | 21 +++---
 .../Analysis/FlowSensitive/TransferTest.cpp   | 28 +++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 1a38be9c1374f65..525ab188b01b8aa 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -157,12 +157,25 @@ static Value &widenDistinctValues(QualType Type, Value 
&Prev,
   Environment &CurrentEnv,
   Environment::ValueModel &Model) {
   // Boolean-model widening.
-  if (isa(&Prev)) {
-assert(isa(Current));
-// Widen to Top, because we know they are different values. If previous was
-// already Top, re-use that to (implicitly) indicate that no change 
occured.
+  if (auto *PrevBool = dyn_cast(&Prev)) {
+// If previous value was already Top, re-use that to (implicitly) indicate
+// that no change occurred.
 if (isa(Prev))
   return Prev;
+
+// We may need to widen to Top, but before we do so, check whether both
+// values are implied to be either true or false in the current 
environment.
+// In that case, we can simply return a literal instead.
+auto &CurBool = cast(Current);
+bool TruePrev = PrevEnv.proves(PrevBool->formula());
+bool TrueCur = CurrentEnv.proves(CurBool.formula());
+if (TruePrev && TrueCur)
+  return CurrentEnv.getBoolLiteralValue(true);
+if (!TruePrev && !TrueCur &&
+PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool->formula())) &&
+CurrentEnv.proves(CurrentEnv.arena().makeNot(CurBool.formula(
+  return CurrentEnv.getBoolLiteralValue(false);
+
 return CurrentEnv.makeTopBoolValue();
   }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ade0d202ced2f37..8da55953a329869 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4167,6 +4167,34 @@ TEST(TransferTest, 
LoopWithShortCircuitedConditionConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopCanProveInvariantForBoolean) {
+  // Check that we can prove `b` is always false in the loop.
+  // This test exercises the logic in `widenDistinctValues()` that preserves
+  // information if the boolean can be proved to be either true or false in 
both
+  // the previous and current iteration.
+  std::string Code = R"cc(
+int return_int();
+void target() {
+  bool b = return_int() == 0;
+  if (b) return;
+  while (true) {
+b;
+// [[p]]
+b = return_int() == 0;
+if (b) return;
+  }
+}
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+auto &BVal = getValueForDecl(ASTCtx, Env, "b");
+EXPECT_TRUE(Env.proves(Env.arena().makeNot(BVal.formula(;
+  });
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {

>From 8bf96b195f30933804cdf45f8616a385cf6ab95f Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 27 Nov 2023 14:06:58 +
Subject: [PATCH 2/4] [clang][dataflow] Defer initialization of `Environment`.

The `Environment` is now only initialized with storage locations and values for
global variables, parameters, and the like after the analysis has been created.

Followup commits will add the ab

[clang] piper export cl 583969847 (PR #73518)

2023-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

- [clang][dataflow] Strengthen widening of boolean values.
- [clang][dataflow] Defer initialization of `Environment`.
- [clang][dataflow] Add synthetic fields to `RecordStorageLocation`.
- [clang][dataflow] Make UncheckedOptionalAccessModel use synthetic fields.


---

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


19 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
(+17-1) 
- (modified) 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h (+46) 
- (modified) clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
(+19-6) 
- (modified) 
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 (+1-12) 
- (modified) clang/include/clang/Analysis/FlowSensitive/RecordOps.h (+9-8) 
- (modified) clang/include/clang/Analysis/FlowSensitive/StorageLocation.h 
(+26-6) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
(+39-1) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+37-57) 
- (modified) clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp (+4) 
- (modified) 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
(+108-270) 
- (modified) clang/lib/Analysis/FlowSensitive/RecordOps.cpp (+24) 
- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+12-14) 
- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+59-2) 
- (modified) clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
(+5) 
- (modified) clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp (+50-9) 
- (modified) clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp (+6-3) 
- (modified) clang/unittests/Analysis/FlowSensitive/TestingSupport.h (+3-1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+28) 
- (modified) 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp 
(+2-2) 


``diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index c5f14cfcd4f7bee..1dffbe8a09c3609 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -234,6 +234,22 @@ runDataflowAnalysis(
   return std::move(BlockStates);
 }
 
+// Create an analysis class that is derived from `DataflowAnalysis`. This is an
+// SFINAE adapter that allows us to call two different variants of constructor
+// (either with or without the optional `Environment` parameter).
+// FIXME: Make all classes derived from `DataflowAnalysis` take an 
`Environment`
+// parameter in their constructor so that we can get rid of this abomination.
+template 
+auto createAnalysis(ASTContext &ASTCtx, Environment &Env)
+-> decltype(AnalysisT(ASTCtx, Env)) {
+  return AnalysisT(ASTCtx, Env);
+}
+template 
+auto createAnalysis(ASTContext &ASTCtx, Environment &Env)
+-> decltype(AnalysisT(ASTCtx)) {
+  return AnalysisT(ASTCtx);
+}
+
 /// Runs a dataflow analysis over the given function and then runs `Diagnoser`
 /// over the results. Returns a list of diagnostics for `FuncDecl` or an
 /// error. Currently, errors can occur (at least) because the analysis requires
@@ -262,7 +278,7 @@ llvm::Expected> 
diagnoseFunction(
   const WatchedLiteralsSolver *Solver = OwnedSolver.get();
   DataflowAnalysisContext AnalysisContext(std::move(OwnedSolver));
   Environment Env(AnalysisContext, FuncDecl);
-  AnalysisT Analysis(ASTCtx);
+  AnalysisT Analysis = createAnalysis(ASTCtx, Env);
   llvm::SmallVector Diagnostics;
   if (llvm::Error Err =
   runTypeErasedDataflowAnalysis(
diff --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index c1aa8484817a9d9..20e45cc27b01fa8 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -58,6 +58,10 @@ using FieldSet = llvm::SmallSetVector;
 /// Returns the set of all fields in the type.
 FieldSet getObjectFields(QualType Type);
 
+/// Returns whether `Fields` and `FieldLocs` contain the same fields.
+bool containsSameFields(const FieldSet &Fields,
+const RecordStorageLocation::FieldToLoc &FieldLocs);
+
 struct ContextSensitiveOptions {
   /// The maximum depth to analyze. A value of zero is equivalent to disabling
   /// context-sensitive analysis entirely.
@@ -92,11 +96,39 @@ class DataflowAnalysisContext {
   /*Logger=*/nullptr});
   ~DataflowAnalysisContext();
 
+  /// Sets a callback that returns the names and types of the synthetic fields
+  /// to add to a `RecordStorageLocation` of a given type.
+  /// Typically, this is

[clang] piper export cl 583969847 (PR #73518)

2023-11-27 Thread via cfe-commits

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


[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-27 Thread David Sherwood via cfe-commits

https://github.com/david-arm updated 
https://github.com/llvm/llvm-project/pull/73326

>From af76f6b6b3469fd0f5f24427c5a175c8d9d7c83a Mon Sep 17 00:00:00 2001
From: David Sherwood 
Date: Fri, 24 Nov 2023 13:20:23 +
Subject: [PATCH 1/2] [Clang] Emit TBAA info for enums in C

When emitting TBAA information for enums in C code we
currently just treat the data as an 'omnipotent char'.
However, with C strict aliasing this means we fail to
optimise certain cases. For example, in the SPEC2017
xz benchmark there are structs that contain arrays of
enums, and clang pessmistically assumes that accesses
to those enums could alias with other struct members
that have a different type.

According to

https://en.cppreference.com/w/c/language/enum

enums should be treated as 'int' types unless
explicitly specified (C23) or if 'int' would not be
large enough to hold all the enumerated values. In the
latter case the compiler is free to choose a suitable
integer that would hold all such values.

When compiling C code this patch generates TBAA
information for the enum by using an equivalent integer
of the size clang has already chosen for the enum. I
have ignored C++ for now because the rules are more
complex.

New test added here:

  clang/test/CodeGen/tbaa.c
---
 clang/lib/CodeGen/CodeGenTBAA.cpp |   5 +-
 clang/test/CodeGen/tbaa.c | 116 ++
 2 files changed, 120 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/tbaa.c

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..f59d3d422d5209d 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));
+
 // In C++ mode, types have linkage, so we can rely on the ODR and
 // on their mangled names, if they're external.
 // TODO: Is there a way to get a program-wide unique name for a
 // decl with local linkage or no linkage?
-if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
+if (!ETy->getDecl()->isExternallyVisible())
   return getChar();
 
 SmallString<256> OutName;
diff --git a/clang/test/CodeGen/tbaa.c b/clang/test/CodeGen/tbaa.c
new file mode 100644
index 000..0ab81f60a71941c
--- /dev/null
+++ b/clang/test/CodeGen/tbaa.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefixes=PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -relaxed-aliasing 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// Test TBAA metadata generated by front-end.
+//
+// NO-TBAA-NOT: !tbaa
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef enum {
+  RED_AUTO_32,
+  GREEN_AUTO_32,
+  BLUE_AUTO_32
+} EnumAuto32;
+
+typedef enum {
+  RED_AUTO_64,
+  GREEN_AUTO_64,
+  BLUE_AUTO_64 = 0x1ull
+} EnumAuto64;
+
+typedef enum : uint16_t {
+  RED_16,
+  GREEN_16,
+  BLUE_16
+} Enum16;
+
+typedef enum : uint8_t {
+  RED_8,
+  GREEN_8,
+  BLUE_8
+} Enum8;
+
+uint32_t g0(EnumAuto32 *E, uint32_t *val) {
+// CHECK-LABEL: define{{.*}} i32 @g0(
+// CHECK: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// CHECK: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// CHECK: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// PATH-LABEL: define{{.*}} i32 @g0(
+// PATH: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// PATH: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// PATH: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+  *val = 5;
+  *E = RED_AUTO_32;
+  return *val;
+}
+
+uint64_t g1(EnumAuto64 *E, uint64_t *val) {
+// CHECK-LABEL: define{{.*}} i64 @g1(
+// CHECK: store i64 5, ptr %{{.*}}, align 8, !tbaa [[TAG_i64:!.*]]
+// CHECK: store i64 0, ptr %{{.*}}, align 8, !tbaa [[TAG_long:!.*]]
+// CHECK: load i64, ptr %{{.*}}, align 8, !tbaa [[TAG_i64]]
+// PATH-LABEL: define{{.*}} i64 @g1(
+// PATH: store i64 5, ptr %{{.*}}, align 8, !tbaa [[TAG_i64:!.*]]
+// PATH: store i64 0, ptr %{{.*}}, align 8, !tbaa [[TAG_long:!.*]]
+// PATH: load i64, ptr %{{.*}}, align 8, !tbaa [[TAG_i64]]
+  *val = 5;
+  *E = RED_AUTO_64;
+  return *val;
+}
+
+uint16_t g2(Enum16 *E, uint16_t *val) {
+// CHECK-LABEL: define{{.*}} i16 @g2(
+// CHECK: store i16 5, ptr %{{.*}}, align 2, !tbaa [[TA

[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-27 Thread David Sherwood via cfe-commits


@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));

david-arm wrote:

Good suggestion - thanks!

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


[llvm] [clang] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (PR #73317)

2023-11-27 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/73317

>From f5b909e24e3cea49d98b40797880e4329a7a1e4f Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 15:50:28 +
Subject: [PATCH 1/2] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 
---
 clang/include/clang/Basic/arm_sme.td  |   8 +
 .../acle_sme2_luti2_lane_zt_x4.c  | 201 ++
 .../acle_sme2_luti4_lane_zt_x4.c  | 148 +
 .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp |  31 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  11 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  55 -
 .../Target/AArch64/AArch64RegisterInfo.cpp|   6 +
 llvm/lib/Target/AArch64/SMEInstrFormats.td|  11 +-
 .../AArch64/sme2-intrinsics-luti2-lane-x4.ll  |  35 +++
 .../AArch64/sme2-intrinsics-luti4-lane-x4.ll  |  25 +++
 10 files changed, 525 insertions(+), 6 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c
 create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x4.ll
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x4.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..53319a57d73fdd2 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand four contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X4 : Inst<"svluti2_lane_zt[_{d}]_x4", "4.didi", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x4", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+  def SVLUTI4_LANE_ZT_X4 : Inst<"svluti4_lane_zt[_{d}]_x4", "4.didi", 
"sUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x4", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_1>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
new file mode 100644
index 000..5479fa109e839c5
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
@@ -0,0 +1,201 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sme.luti2.lane.zt.x4.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , , ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , , ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , , ,  } [[TMP0]], 2
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 32)
+// CHECK-NEXT:[[TMP7:%.*]] = extractvalue { , , ,  } [[TMP0]], 3
+// CHECK-NEXT:[[TMP8:%.*]] = tail call  
@llvm.vector.insert

[flang] [clang] [flang] Enable alias tags pass by default (PR #73111)

2023-11-27 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space commented:

I think that what's being proposed here is quite non-standard. In particular, 
what should happen here:
```bash
flang-new {A very long list of options copied from somewhere, including 
-fno-alias-analysis) -O3 file.f90
```

How is the user meant to know that they need to add `-falias-analysis` at the 
end to enable alias analysis? And in general, how are they supposed to know 
that `-fno-alias-analysis` overrides `-O3`?

If it was the case of "the last relevant option takes priority" (as is the case 
with most/all options) then that would be easy - identical logic would always 
apply. 

This should be easy to fix if you use this instead of what's currently 
implemented (apologies for GitHub being unable to format this properly):
```cpp
Args.getLastArg(options::OPT_falias_analysis,
  options::OPT_fno_alias_analysis,
   options::OPT_Ofast,
   options::OPT_O,
   options::OPT_O4);
```
(I'm skipping other changes that would also be required - hopefully this is 
clear enough). This should still give you all the flexibility that you need for 
testing and be less surprising for end users.

If you are in a rush to land this then this LGTM, but I would like the 
relationship between `-O{1|2|3|4}` and `-f{no}-alias-analysis` to be refined in 
a follow-up patch. Unless there's a good reason to avoid that? WDYT?

Sorry, I've only really realised this after @tblah updated 
[falias-analysis.f90](https://github.com/llvm/llvm-project/pull/73111/files#diff-9e3d54cea408f6f309c22f64040afb821ceba52f3b73e2001b3a4b72114f2a10).
 

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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-27 Thread Dinar Temirbulatov via cfe-commits


@@ -1,10 +1,17 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme -target-feature +sme2 -S -O1 -Werror -emit-llvm -o - %s | 
FileCheck %s

dtemirbulatov wrote:

According to 
https://developer.arm.com/documentation/ddi0602/2022-09/SVE-Instructions/PSEL--Predicate-select-between-predicate-register-or-all-false-?lang=en
 , I think that we should enable `-target-feature +sme` and `-target-feature 
+sve2p1 ` and remove `-target-feature +sme2` in order to produce PSEL 
instruction.

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


[llvm] [clang] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (PR #73317)

2023-11-27 Thread Kerry McLaughlin via cfe-commits


@@ -5098,6 +5099,12 @@ void AArch64DAGToDAGISel::Select(SDNode *Node) {
AArch64::LUTI2_4ZTZI_S}))
 // Second Immediate must be <= 3:
 SelectMultiVectorLuti<3>(Node, 4, Opc);
+  else if (auto Opc = SelectOpcodeFromVT(

kmclaughlin-arm wrote:

Can you instead just pass `` in the if statement above?

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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-27 Thread Dinar Temirbulatov via cfe-commits


@@ -1859,19 +1859,28 @@ def SVBGRP   : SInst<"svbgrp[_{d}]",   "ddd", 
"UcUsUiUl", MergeNone, "aarch64_sv
 def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bgrp_x">;
 }
 
+let TargetGuard = "sve2p1|sme" in {

dtemirbulatov wrote:

Accroding to 
https://developer.arm.com/documentation/ddi0602/2022-09/SVE-Instructions/PSEL--Predicate-select-between-predicate-register-or-all-false-?lang=en,
 it is "sve2p1" and "sme" both enabled, I think now it is `sve2p1,sme` should 
work.

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


[llvm] [libc] [libcxx] [compiler-rt] [flang] [clang] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

2023-11-27 Thread Aaron Ballman via cfe-commits


@@ -940,7 +940,7 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
&CGF,
 
 if (const ValueDecl *VD = CGF.FindCountedByField(Base)) {
   IndexedType = Base->getType();
-  const Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
+  Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);

AaronBallman wrote:

Same question here.

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


[compiler-rt] [llvm] [libc] [flang] [clang] [libcxx] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

2023-11-27 Thread Aaron Ballman via cfe-commits


@@ -956,37 +956,55 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
&CGF,
   return nullptr;
 }
 
-const Expr *
-CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
- const ValueDecl *CountedByVD) {
+Expr *CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
+   const ValueDecl *CountedByVD) {
   // Find the outer struct expr (i.e. p in p->a.b.c.d).
   Expr *CountedByExpr = const_cast(Base)->IgnoreParenImpCasts();
 
+  // Get the enclosing struct, but not the outermost enclosing struct.
+  const DeclContext *DC = CountedByVD->getLexicalDeclContext();
+  const RecordDecl *CountedByRD = dyn_cast(DC);

AaronBallman wrote:

```suggestion
  const auto *CountedByRD = dyn_cast(DC);
```

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


[libc] [llvm] [compiler-rt] [libcxx] [flang] [clang] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

2023-11-27 Thread Aaron Ballman via cfe-commits


@@ -916,7 +916,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
 
   // Build a load of the counted_by field.
   bool IsSigned = CountedByFD->getType()->isSignedIntegerType();
-  const Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
+  Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);

AaronBallman wrote:

Why did we need to drop the `const` here?

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2023-11-27 Thread Aaron Ballman via cfe-commits


@@ -3,8 +3,8 @@ extern groupshared float f;
 extern float groupshared f; // Ok, redeclaration?
 
 
-// NOTE:lambda is not enabled except for hlsl202x.
-// expected-error@+2 {{expected expression}}
+// expected-warning@+3 {{lambdas are a C++11 extension}}
+// expected-error@+2   {{expected body of lambda expression}}

AaronBallman wrote:

CC @llvm-beanz 

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


[clang] ba1c869 - [OpenACC] Implement 'routine' construct parsing (#73143)

2023-11-27 Thread via cfe-commits

Author: Erich Keane
Date: 2023-11-27T06:49:29-08:00
New Revision: ba1c869f0026923e0db80ffbd94d02e4718cc1f1

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

LOG: [OpenACC] Implement 'routine' construct parsing (#73143)

The 'routine' construct applies either to a function directly, or, when
provided a name, applies to the function named (and is visible in the
current scope). This patch implements the parsing for this.  The
identifier provided (or Id Expression) is required to be a valid,
declared identifier, though the semantic analysis portion of the Routine
directive will need to enforce it being a function/overload set.

Added: 
clang/test/ParserOpenACC/parse-constructs.cpp

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/OpenACCKinds.h
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseOpenACC.cpp
clang/test/ParserOpenACC/parse-constructs.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 54b5ba6e6414b2d..2fd7165a422859a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1364,6 +1364,8 @@ def warn_pragma_acc_unimplemented_clause_parsing
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive '%select{%1|%1 %2}0'">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
+def err_acc_invalid_open_paren
+: Error<"expected clause-list or newline in OpenACC directive">;
 
 // OpenMP support.
 def warn_pragma_omp_ignored : Warning<

diff  --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index cf4bad9ce0cb9ff..1a5bf7e0e831ce3 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -55,7 +55,8 @@ enum class OpenACCDirectiveKind {
   Update,
   // FIXME: wait construct.
 
-  // FIXME: routine construct.
+  // Procedure Calls in Compute Regions.
+  Routine,
 
   // Invalid.
   Invalid,

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 465453826c0b982..ca29ce46873e8a4 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3532,9 +3532,14 @@ class Parser : public CodeCompletionHandler {
   /// Placeholder for now, should just ignore the directives after emitting a
   /// diagnostic. Eventually will be split into a few functions to parse
   /// 
diff erent situations.
+public:
   DeclGroupPtrTy ParseOpenACCDirectiveDecl();
   StmtResult ParseOpenACCDirectiveStmt();
 
+private:
+  void ParseOpenACCDirective();
+  ExprResult ParseOpenACCRoutineName();
+
 private:
   
//======//
   // C++ 14: Templates [temp]

diff  --git a/clang/lib/Parse/ParseOpenACC.cpp 
b/clang/lib/Parse/ParseOpenACC.cpp
index 978a07ec82e4288..4021d50318561fd 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -46,6 +46,7 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(StringRef 
Name) {
   .Case("host_data", OpenACCDirectiveKind::HostData)
   .Case("loop", OpenACCDirectiveKind::Loop)
   .Case("atomic", OpenACCDirectiveKind::Atomic)
+  .Case("routine", OpenACCDirectiveKind::Routine)
   .Case("declare", OpenACCDirectiveKind::Declare)
   .Case("init", OpenACCDirectiveKind::Init)
   .Case("shutdown", OpenACCDirectiveKind::Shutdown)
@@ -97,6 +98,8 @@ bool isOpenACCDirectiveKind(OpenACCDirectiveKind Kind, 
StringRef Tok) {
 
   case OpenACCDirectiveKind::Atomic:
 return Tok == "atomic";
+  case OpenACCDirectiveKind::Routine:
+return Tok == "routine";
   case OpenACCDirectiveKind::Declare:
 return Tok == "declare";
   case OpenACCDirectiveKind::Init:
@@ -232,24 +235,79 @@ void ParseOpenACCClauseList(Parser &P) {
 P.Diag(P.getCurToken(), 
diag::warn_pragma_acc_unimplemented_clause_parsing);
 }
 
-void ParseOpenACCDirective(Parser &P) {
-  OpenACCDirectiveKind DirKind = ParseOpenACCDirectiveKind(P);
+} // namespace
+
+// Routine has an optional paren-wrapped name of a function in the local scope.
+// We parse the name, emitting any diagnostics
+ExprResult Parser::ParseOpenACCRoutineName() {
+
+  ExprResult Res;
+  if (getLangOpts().CPlusPlus) {
+Res = ParseCXXIdExpression(/*isAddressOfOperand=*/false);
+  } else {
+// There isn't anything quite the same as ParseCXXIdExpression for C, so we
+// need to get the identifier, then call into Sema ourselves.
+
+if (expectIdentifier())
+  return ExprError();
+
+Token FuncName = getCurToken();
+UnqualifiedId Name;
+CXXScopeSpec ScopeSpec;
+SourceLocation 

  1   2   3   4   >