[clang] [clang][flang][windows] Prefer user-provided library paths (-L) (PR #90758)

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

banach-space wrote:

> I've left the flang test as the flang directory doesn't change with 
> `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` and removed the other test. I hope this 
> is what you meant @MaskRay 👍

That's matches how I read that suggestion re 
`LLVM_ENABLE_PER_TARGET_RUNTIME_DIR`, thanks! 

From what I can tell, you've already made all the changes requested from 
@MaskRay . If there are no new comments today, I suggest landing this. 

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


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

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

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

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

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

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

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

[clang] Avoid unevaluated implicit private (PR #92055)

2024-05-15 Thread via cfe-commits

https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/92055

>From 6946c9f1285d5a27eafcdbf13f79c0641736198d Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Thu, 9 May 2024 12:09:15 -0500
Subject: [PATCH 1/4] Avoiding DeclRefExpr with "non_odr_use_unevaluated" to
 declare "Implicit Private variable" DeclRefExpr.

  Changes to be committed:
modified:   clang/lib/Sema/SemaOpenMP.cpp
---
 clang/lib/Sema/SemaOpenMP.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index cf5447f223d45..bb6518099b4df 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3757,7 +3757,8 @@ class DSAAttrChecker final : public 
StmtVisitor {
   void VisitDeclRefExpr(DeclRefExpr *E) {
 if (TryCaptureCXXThisMembers || E->isTypeDependent() ||
 E->isValueDependent() || E->containsUnexpandedParameterPack() ||
-E->isInstantiationDependent())
+E->isInstantiationDependent() ||
+E->isNonOdrUse() == clang::NOUR_Unevaluated)
   return;
 if (auto *VD = dyn_cast(E->getDecl())) {
   // Check the datasharing rules for the expressions in the clauses.

>From 862907f4a6d7cebfb1b816e9ec890c39d0da112e Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Mon, 13 May 2024 01:28:59 -0500
Subject: [PATCH 2/4] Adding checks for proper declaration of DeclRefExpr under
 the task directive (when variable can be non_odr_use_unevaluated).

  Changes to be committed:
modified:   clang/test/OpenMP/task_ast_print.cpp
---
 clang/test/OpenMP/task_ast_print.cpp | 34 
 1 file changed, 34 insertions(+)

diff --git a/clang/test/OpenMP/task_ast_print.cpp 
b/clang/test/OpenMP/task_ast_print.cpp
index 12923e6ab4244..9d545c5f6716c 100644
--- a/clang/test/OpenMP/task_ast_print.cpp
+++ b/clang/test/OpenMP/task_ast_print.cpp
@@ -5,6 +5,7 @@
 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify -Wno-vla 
%s -ast-print | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump  %s | 
FileCheck %s --check-prefix=DUMP
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -208,4 +209,37 @@ int main(int argc, char **argv) {
 extern template int S::TS;
 extern template long S::TS;
 
+int
+implicit_firstprivate() {
+
+#pragma omp parallel num_threads(1)
+  {
+int i = 0;
+// DUMP : OMPTaskDirective
+// DUMP-NEXT : OMPFirstprivateClause
+// DUMP-NEXT : DeclRefExpr {{.+}} 'i' {{.+}} 
refers_to_enclosing_variable_or_capture
+#pragma omp task
+{
+   int j = sizeof(i);
+   j = i;
+}
+  }
+}
+
+int
+no_implicit_firstprivate() {
+
+#pragma omp parallel num_threads(1)
+  {
+int i = 0;
+// DUMP : OMPTaskDirective
+// DUMP-NEXT : CapturedStmt
+// DUMP : DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated 
refers_to_enclosing_variable_or_capture
+#pragma omp task
+{
+   int j = sizeof(i);
+}
+  }
+}
+
 #endif

>From 96c997ad09d87e48af7929b527259c5037242e10 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Tue, 14 May 2024 04:47:00 -0500
Subject: [PATCH 3/4] Minor changes to the test case.   Changes to be
 committed: modified:   clang/test/OpenMP/task_ast_print.cpp

---
 clang/test/OpenMP/task_ast_print.cpp | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/clang/test/OpenMP/task_ast_print.cpp 
b/clang/test/OpenMP/task_ast_print.cpp
index 9d545c5f6716c..cb2cc63f63214 100644
--- a/clang/test/OpenMP/task_ast_print.cpp
+++ b/clang/test/OpenMP/task_ast_print.cpp
@@ -209,15 +209,16 @@ int main(int argc, char **argv) {
 extern template int S::TS;
 extern template long S::TS;
 
-int
+// DUMP-LABEL:  FunctionDecl {{.*}} implicit_firstprivate
+void
 implicit_firstprivate() {
 
 #pragma omp parallel num_threads(1)
   {
 int i = 0;
-// DUMP : OMPTaskDirective
-// DUMP-NEXT : OMPFirstprivateClause
-// DUMP-NEXT : DeclRefExpr {{.+}} 'i' {{.+}} 
refers_to_enclosing_variable_or_capture
+// DUMP: OMPTaskDirective 
+// DUMP-NEXT: OMPFirstprivateClause
+// DUMP-NEXT: DeclRefExpr {{.+}} 'i' {{.+}} 
refers_to_enclosing_variable_or_capture
 #pragma omp task
 {
int j = sizeof(i);
@@ -226,15 +227,16 @@ implicit_firstprivate() {
   }
 }
 
-int
+// DUMP-LABEL:  FunctionDecl {{.*}} no_implicit_firstprivate
+void
 no_implicit_firstprivate() {
 
 #pragma omp parallel num_threads(1)
   {
 int i = 0;
-// DUMP : OMPTaskDirective
-// DUMP-NEXT : CapturedStmt
-// DUMP : DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated 
refers_to_enclosing_variable_or_capture
+// DUMP: OMPTaskDirective
+// DUMP-NEXT: CapturedStmt
+// DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated 
refers_to_enclosing_variable_or_captur

[clang] [flang] [flang] Add nsw flag to do-variable increment with a new option (PR #91579)

2024-05-15 Thread via cfe-commits

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

Thank you!

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


[clang] 7f3ac51 - [clang][Interp] Only accept constant variables in c++98

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

Author: Timm Bäder
Date: 2024-05-15T09:49:57+02:00
New Revision: 7f3ac51b946bf6d6fa8c8443457ebee219879302

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

LOG: [clang][Interp] Only accept constant variables in c++98

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/cxx98.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 2607e07432516..3e4da487e43c3 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -302,7 +302,9 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc) {
 
 QualType T = VD->getType();
 if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11)
-  return T->isSignedIntegerOrEnumerationType() || 
T->isUnsignedIntegerOrEnumerationType();
+  return (T->isSignedIntegerOrEnumerationType() ||
+  T->isUnsignedIntegerOrEnumerationType()) &&
+ T.isConstQualified();
 
 if (T.isConstQualified())
   return true;
@@ -316,12 +318,10 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc) {
 return false;
   };
 
-  if (const auto *D = Desc->asValueDecl()) {
-if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() && !IsConstType(VD)) {
-  diagnoseNonConstVariable(S, OpPC, VD);
-  return S.inConstantContext();
-}
+  if (const auto *D = Desc->asVarDecl();
+  D && D->hasGlobalStorage() && !IsConstType(D)) {
+diagnoseNonConstVariable(S, OpPC, D);
+return S.inConstantContext();
   }
 
   return true;

diff  --git a/clang/test/AST/Interp/cxx98.cpp b/clang/test/AST/Interp/cxx98.cpp
index ba6bcd97d920d..be81735329db8 100644
--- a/clang/test/AST/Interp/cxx98.cpp
+++ b/clang/test/AST/Interp/cxx98.cpp
@@ -45,3 +45,8 @@ struct C0 {
 };
 const int c0_test = C0::Data;
 _Static_assert(c0_test == 0, "");
+
+
+int a = 0; // both-note {{declared here}}
+_Static_assert(a == 0, ""); // both-error {{static assertion expression is not 
an integral constant expression}} \
+// both-note {{read of non-const variable 'a' is 
not allowed in a constant expression}}



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


[clang] [Serialization] Read the initializer for interesting static variables before consuming it (PR #92218)

2024-05-15 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.
+  Environment(DataflowAnalysisContext &DACtx, Stmt &S) : Environment(DACtx) {
+InitialTargetStmt = &S;
+  }
 
-  /// Assigns storage locations and values to all parameters, captures, global
-  /// variables, fields and functions referenced in the function currently 
being
-  /// analyzed.
+  /// Creates an environment that uses `DACtx` to store objects that encompass
+  /// the state of a program, with `FD` as the initial analysis target.

martinboehme wrote:

```suggestion
  /// the state of a program, with `FD` as the function to analyze.
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -736,11 +756,20 @@ class Environment {
   // shared between environments in the same call.
   // https://github.com/llvm/llvm-project/issues/59005
 
-  // `DeclContext` of the block being analysed if provided.
-  std::vector CallStack;
+  // The stack of functions called from the initial analysis target and
+  // recursively being analyzed.
+  std::vector CallStack;
+
+  // If the initial analysis target is a function, this is the function
+  // declaration. Otherwise, this is null.
+  const FunctionDecl *InitialTargetFunc = nullptr;
+  // If the initial analysis target is a function, this is its body. If the
+  // initial analysis target was not provided, this is null. Otherwise, this is
+  // the initial analysis target.

martinboehme wrote:

Similarly:

```suggestion
  // Top-level statement of the initial analysis target.
  // If a function was passed to the constructor, this is its body.
  // If a statement was passed to the constructor, this is that statement.
  // Null if no analysis target was passed to the constructor.
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.
+  Environment(DataflowAnalysisContext &DACtx, Stmt &S) : Environment(DACtx) {
+InitialTargetStmt = &S;
+  }
 
-  /// Assigns storage locations and values to all parameters, captures, global
-  /// variables, fields and functions referenced in the function currently 
being
-  /// analyzed.
+  /// Creates an environment that uses `DACtx` to store objects that encompass
+  /// the state of a program, with `FD` as the initial analysis target.
   ///
   /// Requirements:
   ///
   ///  The function must have a body, i.e.
   ///  `FunctionDecl::doesThisDecalarationHaveABody()` must be true.
+  Environment(DataflowAnalysisContext &DACtx, const FunctionDecl &FD)
+  : Environment(DACtx, *FD.getBody()) {
+InitialTargetFunc = &FD;
+  }

martinboehme wrote:

As we're touching the constructors anyway, maybe we can use the opportunity to 
group all of the constructors together (i.e. group these with the explicit 
constructor above on line 161).

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -290,13 +295,13 @@ widenKeyToValueMap(const llvm::MapVector 
&CurMap,
 namespace {
 
 // Visitor that builds a map from record prvalues to result objects.
-// This traverses the body of the function to be analyzed; for each result
-// object that it encounters, it propagates the storage location of the result
-// object to all record prvalues that can initialize it.
+// This traverses the AST sub-tree to be visited; for each result object that
+// it encounters, it propagates the storage location of the result object to 
all
+// record prvalues that can initialize it.
 class ResultObjectVisitor : public RecursiveASTVisitor {
 public:
   // `ResultObjectMap` will be filled with a map from record prvalues to result
-  // object. If the function being analyzed returns a record by value,
+  // object. If the sub-tree to be visited returns a record by value,

martinboehme wrote:

"sub-tree to be visited returns a record by value": This only makes sense if 
this sub-tree is actually a function, so I would suggest keeping the wording 
more specific.

```suggestion
  // object. If the analysis target is a function that returns a record by 
value,
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.

martinboehme wrote:

I don't think we've used the term "initial analysis target" elsewhere, so maybe 
this is worth clarifying?

OTOH, maybe it's clearer not to introduce this term at all (at least outside 
the implementation). This is the constructor, so it's pretty clear that `S` is 
what we will start analyzing, before we potentially analyze functions called by 
it. And even if/when we do do context-sensitive analysis of other functions, 
the ultimate purpose of that is to analyze `S` better. So I would suggest 
simply saying "...with `S` as the statement to analyze".

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -641,23 +656,20 @@ class Environment {
   /// (or the flow condition is overly constraining) or if the solver times 
out.
   bool allows(const Formula &) const;
 
-  /// Returns the `DeclContext` of the block being analysed, if any. Otherwise,
-  /// returns null.
-  const DeclContext *getDeclCtx() const { return CallStack.back(); }
-
   /// Returns the function currently being analyzed, or null if the code being
   /// analyzed isn't part of a function.
   const FunctionDecl *getCurrentFunc() const {
-return dyn_cast(getDeclCtx());
+return CallStack.empty() ? InitialTargetFunc : CallStack.back();
   }
 
   /// Returns the size of the call stack.
   size_t callStackSize() const { return CallStack.size(); }
 
   /// Returns whether this `Environment` can be extended to analyze the given
   /// `Callee` (i.e. if `pushCall` can be used), with recursion disallowed and 
a
-  /// given `MaxDepth`.
-  bool canDescend(unsigned MaxDepth, const DeclContext *Callee) const;
+  /// given `MaxDepth`. Note that the `MaxDepth` does not count any initial
+  /// target function, which was not called.
+  bool canDescend(unsigned MaxDepth, const FunctionDecl *Callee) const;

martinboehme wrote:

Suggestion (can't make this a suggested edit as I'm suggesting to change a line 
that this PR doesn't touch):

```cxx
  /// Returns whether this `Environment` can be extended to analyze the given
  /// `Callee` (i.e. if `pushCall` can be used).
  /// Recursion is not allowed. `MaxDepth` is the maximum size of the call stack
  /// (i.e. the maximum value that `callStackSize()` may assume after the call).
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -736,11 +756,20 @@ class Environment {
   // shared between environments in the same call.
   // https://github.com/llvm/llvm-project/issues/59005
 
-  // `DeclContext` of the block being analysed if provided.
-  std::vector CallStack;
+  // The stack of functions called from the initial analysis target and
+  // recursively being analyzed.
+  std::vector CallStack;
+
+  // If the initial analysis target is a function, this is the function
+  // declaration. Otherwise, this is null.

martinboehme wrote:

Would suggest putting the description of what this is at the front, and putting 
the condition behind that.

```suggestion
  // Initial function to analyze, if a function was passed to the constructor.
  // Null otherwise.
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.
+  Environment(DataflowAnalysisContext &DACtx, Stmt &S) : Environment(DACtx) {
+InitialTargetStmt = &S;
+  }
 
-  /// Assigns storage locations and values to all parameters, captures, global
-  /// variables, fields and functions referenced in the function currently 
being
-  /// analyzed.
+  /// Creates an environment that uses `DACtx` to store objects that encompass
+  /// the state of a program, with `FD` as the initial analysis target.
   ///
   /// Requirements:
   ///
   ///  The function must have a body, i.e.
   ///  `FunctionDecl::doesThisDecalarationHaveABody()` must be true.
+  Environment(DataflowAnalysisContext &DACtx, const FunctionDecl &FD)
+  : Environment(DACtx, *FD.getBody()) {
+InitialTargetFunc = &FD;
+  }
+
+  /// Assigns storage locations and values to all parameters, captures, global
+  /// variables, fields and functions referenced in the initial analysis 
target.
+  ///
+  /// If the target is a non-static member function, initializes the 
environment
+  /// with a symbolic representation of the `this` pointee.

martinboehme wrote:

Nit: Maybe just leave this detail out? `this` is a parameter too (albeit an 
implicit one), so it's covered by the statement above.

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -762,7 +791,8 @@ class Environment {
   RecordStorageLocation *LocForRecordReturnVal = nullptr;
 
   // The storage location of the `this` pointee. Should only be null if the
-  // function being analyzed is only a function and not a method.
+  // analysis target is not a function or is a function but not a
+  // method.

martinboehme wrote:

(Shorter but says the same thing.)

```suggestion
  // analysis target is not a method.
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -290,13 +295,13 @@ widenKeyToValueMap(const llvm::MapVector 
&CurMap,
 namespace {
 
 // Visitor that builds a map from record prvalues to result objects.
-// This traverses the body of the function to be analyzed; for each result
-// object that it encounters, it propagates the storage location of the result
-// object to all record prvalues that can initialize it.
+// This traverses the AST sub-tree to be visited; for each result object that

martinboehme wrote:

Nit: Maybe the original "analyzed" is more specific than "visited"?

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.
+  Environment(DataflowAnalysisContext &DACtx, Stmt &S) : Environment(DACtx) {
+InitialTargetStmt = &S;
+  }
 
-  /// Assigns storage locations and values to all parameters, captures, global
-  /// variables, fields and functions referenced in the function currently 
being
-  /// analyzed.
+  /// Creates an environment that uses `DACtx` to store objects that encompass
+  /// the state of a program, with `FD` as the initial analysis target.
   ///
   /// Requirements:
   ///
   ///  The function must have a body, i.e.
   ///  `FunctionDecl::doesThisDecalarationHaveABody()` must be true.
+  Environment(DataflowAnalysisContext &DACtx, const FunctionDecl &FD)
+  : Environment(DACtx, *FD.getBody()) {
+InitialTargetFunc = &FD;
+  }
+
+  /// Assigns storage locations and values to all parameters, captures, global
+  /// variables, fields and functions referenced in the initial analysis 
target.

martinboehme wrote:

```suggestion
  /// variables, fields and functions referenced in the `Stmt` or `FunctionDecl`
  /// passed to the constructor.
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -718,16 +730,24 @@ class Environment {
   void pushCallInternal(const FunctionDecl *FuncDecl,
 ArrayRef Args);
 
+  // FIXME: Add support for resetting globals after function calls to enable
+  // the implementation of sound analyses.

martinboehme wrote:

Not sure why this comment is being moved here? It seems to be more removed from 
the place where we would make this change than where it previously was (i.e. 
next to the implementation of `initFieldsGlobalsAndFuncs()`.

That said, I'm not sure what this comment is trying to say exactly -- but in 
any case, I would recommend keeping it where it is. IIUC, this PR isn't making 
any changes to this behavior?

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.
+  Environment(DataflowAnalysisContext &DACtx, Stmt &S) : Environment(DACtx) {
+InitialTargetStmt = &S;
+  }
 
-  /// Assigns storage locations and values to all parameters, captures, global
-  /// variables, fields and functions referenced in the function currently 
being
-  /// analyzed.
+  /// Creates an environment that uses `DACtx` to store objects that encompass
+  /// the state of a program, with `FD` as the initial analysis target.
   ///
   /// Requirements:
   ///
   ///  The function must have a body, i.e.
   ///  `FunctionDecl::doesThisDecalarationHaveABody()` must be true.
+  Environment(DataflowAnalysisContext &DACtx, const FunctionDecl &FD)
+  : Environment(DACtx, *FD.getBody()) {
+InitialTargetFunc = &FD;

martinboehme wrote:

Can you preserve this assertion here (which was originally in 
`initFieldsGlobalsAndFuncs()`)?

```cxx
assert(FuncDecl->doesThisDeclarationHaveABody());
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -403,4 +405,35 @@ TEST_F(EnvironmentTest,
   Contains(Member));
 }
 
+TEST_F(EnvironmentTest, Stmt) {
+  using namespace ast_matchers;
+
+  std::string Code = R"cc(
+  struct S {int i;};
+  void foo() {
+S AnS = S{1};
+  }

martinboehme wrote:

Is there a reason the variable declaration needs to be wrapped in a function? 
Seems it would be easier to do this with a global variable, and at the same 
time, this would demonstrate that we can analyze code that lives outside a 
function.
```suggestion
  S AnS = S{1};
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -146,6 +146,30 @@ TEST_F(DataflowAnalysisTest, 
DiagnoseFunctionDiagnoserCalledOnEachElement) {
" (Lifetime ends)\n")));
 }
 
+TEST_F(DataflowAnalysisTest, CanAnalyzeStmt) {
+  std::string Code = R"cc(
+  struct S {int i;};
+  S getAnS() {return S{1};};
+  void foo() {
+S AnS = getAnS();
+  }
+)cc";
+  AST = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++11"});
+  const auto &DeclStatement = matchNode(declStmt());

martinboehme wrote:

As above: Match the name of the declaration?

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -146,6 +146,30 @@ TEST_F(DataflowAnalysisTest, 
DiagnoseFunctionDiagnoserCalledOnEachElement) {
" (Lifetime ends)\n")));
 }
 
+TEST_F(DataflowAnalysisTest, CanAnalyzeStmt) {
+  std::string Code = R"cc(
+  struct S {int i;};
+  S getAnS() {return S{1};};
+  void foo() {
+S AnS = getAnS();
+  }

martinboehme wrote:

```suggestion
  struct S { int i; };
  S getAnS() {return S{1};};
  S AnS = getAnS();
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -164,23 +169,28 @@ class Environment {
   Environment &operator=(Environment &&Other) = default;
 
   /// Creates an environment that uses `DACtx` to store objects that encompass
-  /// the state of a program.
-  ///
-  /// If `DeclCtx` is a function, initializes the environment with symbolic
-  /// representations of the function parameters.
-  ///
-  /// If `DeclCtx` is a non-static member function, initializes the environment
-  /// with a symbolic representation of the `this` pointee.
-  Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
+  /// the state of a program, with `S` as the initial analysis target.
+  Environment(DataflowAnalysisContext &DACtx, Stmt &S) : Environment(DACtx) {
+InitialTargetStmt = &S;
+  }
 
-  /// Assigns storage locations and values to all parameters, captures, global
-  /// variables, fields and functions referenced in the function currently 
being
-  /// analyzed.
+  /// Creates an environment that uses `DACtx` to store objects that encompass
+  /// the state of a program, with `FD` as the initial analysis target.
   ///
   /// Requirements:
   ///
   ///  The function must have a body, i.e.
   ///  `FunctionDecl::doesThisDecalarationHaveABody()` must be true.
+  Environment(DataflowAnalysisContext &DACtx, const FunctionDecl &FD)
+  : Environment(DACtx, *FD.getBody()) {
+InitialTargetFunc = &FD;
+  }
+
+  /// Assigns storage locations and values to all parameters, captures, global
+  /// variables, fields and functions referenced in the initial analysis 
target.
+  ///
+  /// If the target is a non-static member function, initializes the 
environment
+  /// with a symbolic representation of the `this` pointee.
   void initialize();

martinboehme wrote:

This now uses the member variables `InitiialTargetFunc` and 
`InitialTargetStmt`. It seems it would be an error to call this if the call 
stack is non-empty -- so should we add a precondition for this (both as an 
assertion and as documentation here)?

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -146,6 +146,30 @@ TEST_F(DataflowAnalysisTest, 
DiagnoseFunctionDiagnoserCalledOnEachElement) {
" (Lifetime ends)\n")));
 }
 
+TEST_F(DataflowAnalysisTest, CanAnalyzeStmt) {
+  std::string Code = R"cc(
+  struct S {int i;};
+  S getAnS() {return S{1};};
+  void foo() {
+S AnS = getAnS();
+  }
+)cc";
+  AST = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++11"});
+  const auto &DeclStatement = matchNode(declStmt());
+  const auto &Func = matchNode(functionDecl(hasName("foo")));
+
+  ACFG = std::make_unique(llvm::cantFail(AdornedCFG::build(
+  Func, const_cast(DeclStatement), AST->getASTContext(;
+
+  NoopAnalysis Analysis = NoopAnalysis(AST->getASTContext());
+  DACtx = std::make_unique(
+  std::make_unique());
+  Environment Env(*DACtx, const_cast(DeclStatement));
+
+  ASSERT_THAT_ERROR(runDataflowAnalysis(*ACFG, Analysis, Env).takeError(),
+llvm::Succeeded());

martinboehme wrote:

Again, can we make this test stronger than simply asserting that we don't error 
out?

For example, if we made the member variable of `S` a bool instead of an 
integer, we could verify that it was initialized with a specific boolean 
literal.

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -641,23 +656,20 @@ class Environment {
   /// (or the flow condition is overly constraining) or if the solver times 
out.
   bool allows(const Formula &) const;
 
-  /// Returns the `DeclContext` of the block being analysed, if any. Otherwise,
-  /// returns null.
-  const DeclContext *getDeclCtx() const { return CallStack.back(); }
-
   /// Returns the function currently being analyzed, or null if the code being
   /// analyzed isn't part of a function.
   const FunctionDecl *getCurrentFunc() const {
-return dyn_cast(getDeclCtx());
+return CallStack.empty() ? InitialTargetFunc : CallStack.back();
   }
 
   /// Returns the size of the call stack.

martinboehme wrote:

Can we make this more precise, particularly given that this PR actually changes 
what this function returns? See suggestion.

```suggestion
  /// Returns the size of the call stack, not counting the initial analysis 
target.
```

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


[clang] [clang][dataflow] Fully support Environment construction for Stmt analysis. (PR #91616)

2024-05-15 Thread via cfe-commits


@@ -403,4 +405,35 @@ TEST_F(EnvironmentTest,
   Contains(Member));
 }
 
+TEST_F(EnvironmentTest, Stmt) {
+  using namespace ast_matchers;
+
+  std::string Code = R"cc(
+  struct S {int i;};
+  void foo() {
+S AnS = S{1};
+  }
+)cc";
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"});
+  auto &Context = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  auto *DeclStatement = const_cast(
+  selectFirst("d", match(declStmt().bind("d"), Context)));

martinboehme wrote:

Can we make this matcher a bit stronger, i.e. match against the name `AnS`?

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


[clang] 6479e3c - [clang][Interp] Use proper type for non-primitive reference dummies

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

Author: Timm Bäder
Date: 2024-05-15T10:17:09+02:00
New Revision: 6479e3cb66895754089dc017a33478e9eb4b8d65

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

LOG: [clang][Interp] Use proper type for non-primitive reference dummies

Added: 


Modified: 
clang/lib/AST/Interp/Program.cpp
clang/test/AST/Interp/bitfields.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 31a64e13d2b15..e3d48d5a8ddb4 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -152,8 +152,7 @@ std::optional Program::getOrCreateDummy(const 
ValueDecl *VD) {
   if (std::optional T = Ctx.classify(QT))
 Desc = createDescriptor(VD, *T, std::nullopt, true, false);
   else
-Desc = createDescriptor(VD, VD->getType().getTypePtr(), std::nullopt, true,
-false);
+Desc = createDescriptor(VD, QT.getTypePtr(), std::nullopt, true, false);
   if (!Desc)
 Desc = allocateDescriptor(VD);
 

diff  --git a/clang/test/AST/Interp/bitfields.cpp 
b/clang/test/AST/Interp/bitfields.cpp
index d3a8a083063ab..5fc34bb1229d9 100644
--- a/clang/test/AST/Interp/bitfields.cpp
+++ b/clang/test/AST/Interp/bitfields.cpp
@@ -102,3 +102,24 @@ namespace Compound {
   }
   static_assert(div() == 1, "");
 }
+
+namespace test0 {
+  extern int int_source();
+  struct A {
+int aField;
+int bField;
+  };
+
+  struct B {
+int onebit : 2;
+int twobit : 6;
+int intField;
+  };
+
+  struct C : A, B {
+  };
+
+  void b(C &c) {
+c.onebit = int_source();
+  }
+}



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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

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

>From 20947c1a34fae3593a98dba125e5d70d652c7190 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 10:54:12 +0200
Subject: [PATCH 1/2] [clang] CTAD: implement the missing IsDeducible
 constraint for alias templates.

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

- rebase to main
- add release note for __is_deducible
- implement diagnostics for bad argument types for __is_deducible

Don't expose __is_deducible trait.

Refine the implementation of hiding __is_deducible type trait.

Apply approach 3.
---
 clang/include/clang/Basic/TokenKinds.def |  3 +
 clang/include/clang/Sema/Sema.h  |  9 ++
 clang/lib/Basic/TypeTraits.cpp   | 10 +++
 clang/lib/Sema/SemaExprCXX.cpp   | 10 ++-
 clang/lib/Sema/SemaTemplate.cpp  | 82 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 86 
 clang/test/AST/ast-dump-ctad-alias.cpp   | 20 +++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 27 --
 clang/test/SemaTemplate/deduction-guide.cpp  | 16 ++--
 clang/www/cxx_status.html|  4 +-
 10 files changed, 238 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..b5a0e9df9f7ae 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -538,6 +538,9 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary, KEYCXX)
+// IsDeducible is only used internally by clang for CTAD implementation and
+// is not exposed to users.
+TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4efd3878e861b..8cee7ab2c7b4e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9597,6 +9597,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Basic/TypeTraits.cpp b/clang/lib/Basic/TypeTraits.cpp
index 4dbf678dc395b..8d6794223ccaf 100644
--- a/clang/lib/Basic/TypeTraits.cpp
+++ b/clang/lib/Basic/TypeTraits.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 using namespace clang;
 
 static constexpr const char *TypeTraitNames[] = {
@@ -81,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
 
 const char *clang::getTraitSpelling(TypeTrait T) {
   assert(T <= TT_Last && "invalid enum value!");
+  if (T == BTT_IsDeducible) {
+// The __is_deducible is an internal-only type trait. To hide it from
+// external users, we define it with an empty spelling name, preventing the
+// clang parser from recognizing its token kind.
+// However, other components such as the AST dump still require the real
+// type trait name. Therefore, we return the real name when needed.
+assert(std::strlen(TypeTraitSpellings[T]) == 0);
+return "__is_deducible";
+  }
   return TypeTraitSpellings[T];
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c181092113e1f..1cd912e3863d8 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6142,7 +6142,15 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }
-default: llvm_unreachable("not a BTT");
+  case BTT_IsDeducible: {
+const auto *TSTToBeDeduced = cast(LhsT);
+sema::TemplateDeductionInfo Info(KeyLoc);
+return Self.DeduceTemplateArgumentsFromType(
+   TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT,
+   Info) == TemplateDeductionResult::Success;
+  }
+  default:
+llvm_unreachable("not a BTT");
   }
   llvm_unreachable("Unknow

[clang] [llvm] [MC] Remove UseAssemblerInfoForParsing (PR #91082)

2024-05-15 Thread Peter Smith via cfe-commits

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

I think it is reasonable to proceed given the RFC and the response.

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

hokein wrote:

Thanks for the review.

> I'll approve that modulo nit but i think we want
> 
> * An issue to keep track of the duplication in 
> `FinishTemplateArgumentDeduction`

Filed #92224.

> * A follow up PR to improve diagnostics

Filed #92225, and assigned to myself. Will do it.

> Thanks!



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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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


@@ -2774,6 +2775,41 @@ Expr *transformRequireClause(Sema &SemaRef, 
FunctionTemplateDecl *FTD,
   return E.getAs();
 }
 
+// Build the associated constraints for the alias deduction guides.
+// C++ [over.match.class.deduct]p3.3:
+//   The associated constraints ([temp.constr.decl]) are the conjunction of the
+//   associated constraints of g and a constraint that is satisfied if and only
+//   if the arguments of A are deducible (see below) from the return type.
+Expr *
+buildAssociatedConstraints(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
+   FunctionTemplateDecl *FTD,
+   llvm::ArrayRef TransformedArgs,
+   QualType ReturnType) {
+  auto &Context = SemaRef.Context;

hokein wrote:

Oops,  it looks like I forgot to push one commit.

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


[clang] [llvm] [RISCV] Gate unratified profiles behind -menable-experimental-extensions (PR #92167)

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

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

LGTM

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


[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)

2024-05-15 Thread Akash Banerjee via cfe-commits

TIFitis wrote:

Ping for review 😄 

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

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

>From 659cf5b5c1216ab9f6a8dbb63b4f93de41cd173d Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 10:54:12 +0200
Subject: [PATCH 1/2] [clang] CTAD: implement the missing IsDeducible
 constraint for alias templates.

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

- rebase to main
- add release note for __is_deducible
- implement diagnostics for bad argument types for __is_deducible

Don't expose __is_deducible trait.

Refine the implementation of hiding __is_deducible type trait.

Apply approach 3.
---
 clang/include/clang/Basic/TokenKinds.def |  3 +
 clang/include/clang/Sema/Sema.h  |  9 ++
 clang/lib/Basic/TypeTraits.cpp   | 10 +++
 clang/lib/Sema/SemaExprCXX.cpp   | 10 ++-
 clang/lib/Sema/SemaTemplate.cpp  | 82 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 86 
 clang/test/AST/ast-dump-ctad-alias.cpp   | 20 +++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 27 --
 clang/test/SemaTemplate/deduction-guide.cpp  | 16 ++--
 clang/www/cxx_status.html|  4 +-
 10 files changed, 238 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..b5a0e9df9f7ae 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -538,6 +538,9 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary, KEYCXX)
+// IsDeducible is only used internally by clang for CTAD implementation and
+// is not exposed to users.
+TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..66d5e2d4a4ade 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9492,6 +9492,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Basic/TypeTraits.cpp b/clang/lib/Basic/TypeTraits.cpp
index 4dbf678dc395b..8d6794223ccaf 100644
--- a/clang/lib/Basic/TypeTraits.cpp
+++ b/clang/lib/Basic/TypeTraits.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 using namespace clang;
 
 static constexpr const char *TypeTraitNames[] = {
@@ -81,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
 
 const char *clang::getTraitSpelling(TypeTrait T) {
   assert(T <= TT_Last && "invalid enum value!");
+  if (T == BTT_IsDeducible) {
+// The __is_deducible is an internal-only type trait. To hide it from
+// external users, we define it with an empty spelling name, preventing the
+// clang parser from recognizing its token kind.
+// However, other components such as the AST dump still require the real
+// type trait name. Therefore, we return the real name when needed.
+assert(std::strlen(TypeTraitSpellings[T]) == 0);
+return "__is_deducible";
+  }
   return TypeTraitSpellings[T];
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 34e12078a8c92..e4601f7d6c47d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6143,7 +6143,15 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }
-default: llvm_unreachable("not a BTT");
+  case BTT_IsDeducible: {
+const auto *TSTToBeDeduced = cast(LhsT);
+sema::TemplateDeductionInfo Info(KeyLoc);
+return Self.DeduceTemplateArgumentsFromType(
+   TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT,
+   Info) == TemplateDeductionResult::Success;
+  }
+  default:
+llvm_unreachable("not a BTT");
   }
   llvm_unreachable("Unknow

[clang] 1d43ec8 - [clang][Interp][NFC] Remove unnecessary if condition

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

Author: Timm Bäder
Date: 2024-05-15T10:17:09+02:00
New Revision: 1d43ec8191e55d6efd552a1510ce63dbdea00cc0

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

LOG: [clang][Interp][NFC] Remove unnecessary if condition

This is already in a if(isBlockPointer()) block.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index d2e34f2c7f09e..ee8cedccb8d4b 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -191,7 +191,7 @@ void Pointer::print(llvm::raw_ostream &OS) const {
 else
   OS << Offset << ", ";
 
-if (isBlockPointer() && PointeeStorage.BS.Pointee)
+if (PointeeStorage.BS.Pointee)
   OS << PointeeStorage.BS.Pointee->getSize();
 else
   OS << "nullptr";



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


[clang] afba3da - [clang][Interp] Add basic support for AddrLabelExprs

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

Author: Timm Bäder
Date: 2024-05-15T10:17:10+02:00
New Revision: afba3daf822c839db1be40464041307679c803a9

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

LOG: [clang][Interp] Add basic support for AddrLabelExprs

Just create a local variable for them.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7b10482dff23f..1da74ac7c8bd1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2488,6 +2488,16 @@ bool ByteCodeExprGen::VisitRecoveryExpr(const 
RecoveryExpr *E) {
   return this->emitError(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitAddrLabelExpr(const AddrLabelExpr *E) {
+  assert(E->getType()->isVoidPointerType());
+
+  unsigned Offset = allocateLocalPrimitive(
+  E->getLabel(), PT_Ptr, /*IsConst=*/true, /*IsExtended=*/false);
+
+  return this->emitGetLocal(PT_Ptr, Offset, E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true,
  /*NewInitializing=*/false);

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 9f83d173bbae3..6039a54d32a5b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -122,6 +122,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitPseudoObjectExpr(const PseudoObjectExpr *E);
   bool VisitPackIndexingExpr(const PackIndexingExpr *E);
   bool VisitRecoveryExpr(const RecoveryExpr *E);
+  bool VisitAddrLabelExpr(const AddrLabelExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 2c675f4418ef3..2a75457a4693f 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -273,3 +273,8 @@ int test3(void) {
 /// This tests that we have full type info, even for values we cannot read.
 int dummyarray[5];
 _Static_assert(&dummyarray[0] < &dummyarray[1], ""); // pedantic-warning {{GNU 
extension}}
+
+void addrlabelexpr(void) {
+ a0: ;
+  static void *ps[] = { &&a0 }; // pedantic-warning {{use of GNU 
address-of-label extension}}
+}



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


[clang] ca4a405 - [analyzer] Refactor recognition of the errno getter functions (#91531)

2024-05-15 Thread via cfe-commits

Author: Donát Nagy
Date: 2024-05-15T10:53:54+02:00
New Revision: ca4a405232cf170f20a2f111bf72beab82095935

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

LOG: [analyzer] Refactor recognition of the errno getter functions (#91531)

There are many environments where `errno` is a macro that expands to
something like `(*__errno())` (different standard library
implementations use different names instead of "__errno").

In these environments the ErrnoModeling checker creates a symbolic
region which will be used to represent the return value of this "get the
location of errno" function.

Previously this symbol was only created when the checker was able to
find the declaration of the "get the location of errno" function; but
this commit eliminates the complex logic that was responsible for this
and always creates the symbolic region when `errno` is not available as
a "regular" global variable.

This significantly simplifies a code and only introduces a minimal
performance reduction (one extra symbol) in the case when `errno` is not
declared (neither as a variable nor as a function).


In addition to this simplification, this commit specifies that the
`CallDescription`s for the "get the location of errno" functions are
matched in `CDM::CLibrary` mode. (This was my original goal, but I was
sidetracked by resolving a FIXME above the `CallDescriptionSet` in
`ErrnoModeling.cpp`.)

This change is very close to being NFC, but it fixes weird corner cases
like the handling of a C++ method that happens to be named "__errno()"
(previously it could've been recognized as an errno location getter
function).

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
clang/test/Analysis/memory-model.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
index 18e718e085536..72fd6781a7561 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
@@ -205,7 +205,7 @@ void ErrnoChecker::checkPreCall(const CallEvent &Call,
   // Probably 'strerror'?
   if (CallF->isExternC() && CallF->isGlobal() &&
   C.getSourceManager().isInSystemHeader(CallF->getLocation()) &&
-  !isErrno(CallF)) {
+  !isErrnoLocationCall(Call)) {
 if (getErrnoState(C.getState()) == MustBeChecked) {
   std::optional ErrnoLoc = getErrnoLoc(C.getState());
   assert(ErrnoLoc && "ErrnoLoc should exist if an errno state is set.");

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
index 1b34ea0e056e5..6ffc05f06742b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -39,10 +39,15 @@ namespace {
 // Name of the "errno" variable.
 // FIXME: Is there a system where it is not called "errno" but is a variable?
 const char *ErrnoVarName = "errno";
+
 // Names of functions that return a location of the "errno" value.
 // FIXME: Are there other similar function names?
-const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno",
-"__errno", "_errno", "__error"};
+CallDescriptionSet ErrnoLocationCalls{
+{CDM::CLibrary, {"__errno_location"}, 0, 0},
+{CDM::CLibrary, {"___errno"}, 0, 0},
+{CDM::CLibrary, {"__errno"}, 0, 0},
+{CDM::CLibrary, {"_errno"}, 0, 0},
+{CDM::CLibrary, {"__error"}, 0, 0}};
 
 class ErrnoModeling
 : public Checker, check::BeginFunction,
@@ -54,16 +59,10 @@ class ErrnoModeling
   void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
 
-  // The declaration of an "errno" variable or "errno location" function.
-  mutable const Decl *ErrnoDecl = nullptr;
-
 private:
-  // FIXME: Names from `ErrnoLocationFuncNames` are used to build this set.
-  CallDescriptionSet ErrnoLocationCalls{{{"__errno_location"}, 0, 0},
-{{"___errno"}, 0, 0},
-{{"__errno"}, 0, 0},
-{{"_errno"}, 0, 0},
-{{"__error"}, 0, 0}};
+  // The declaration of an "errno" variable on systems where errno is
+  // represented by a variable (and not a function that queries its location).
+  mutable const VarDecl *ErrnoDecl = nullptr;
 };
 
 } // namespace
@@ -74,9 +73,13 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const 
MemRegion *)
 
 REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoState, errno_modeling::ErrnoCheckState)
 
-/// Sea

[clang] [clang] Add tests for CWG issues regarding completeness of types (PR #92113)

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

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

>From 1ae4b4e9c6b76269b7e279f798057900b5d39a0c Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 14 May 2024 15:45:30 +0300
Subject: [PATCH 1/6] [clang] Add tests for CWG issues regarding completeness
 of types

---
 clang/test/CXX/drs/cwg11xx.cpp | 15 
 clang/test/CXX/drs/cwg13xx.cpp | 31 +++
 clang/test/CXX/drs/cwg14xx.cpp | 17 +
 clang/test/CXX/drs/cwg18xx.cpp | 28 -
 clang/test/CXX/drs/cwg23xx.cpp | 45 --
 clang/test/CXX/drs/cwg24xx.cpp |  6 +
 clang/test/CXX/drs/cwg25xx.cpp | 15 +---
 clang/test/CXX/drs/cwg26xx.cpp |  2 ++
 clang/test/CXX/drs/cwg27xx.cpp | 14 ---
 clang/test/CXX/drs/cwg28xx.cpp | 25 ---
 clang/test/CXX/drs/cwg9xx.cpp  |  7 ++
 clang/www/cxx_dr_status.html   | 26 ++--
 12 files changed, 205 insertions(+), 26 deletions(-)

diff --git a/clang/test/CXX/drs/cwg11xx.cpp b/clang/test/CXX/drs/cwg11xx.cpp
index 46a0e526be390..8d187041400a6 100644
--- a/clang/test/CXX/drs/cwg11xx.cpp
+++ b/clang/test/CXX/drs/cwg11xx.cpp
@@ -4,6 +4,21 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++2a %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 
+namespace cwg1110 { // cwg1110: 3.1
+#if __cplusplus >= 201103L
+template 
+T return_T();
+
+struct A;
+
+template 
+struct B;
+
+decltype(return_T())* a;
+decltype(return_T>())* b;
+#endif
+} // namespace cwg1110
+
 namespace cwg { // cwg: 3.2
 namespace example1 {
 template  struct set; // #cwg-struct-set
diff --git a/clang/test/CXX/drs/cwg13xx.cpp b/clang/test/CXX/drs/cwg13xx.cpp
index a334b6d01acf5..50f984fa6e7d8 100644
--- a/clang/test/CXX/drs/cwg13xx.cpp
+++ b/clang/test/CXX/drs/cwg13xx.cpp
@@ -306,6 +306,18 @@ namespace cwg1330 { // cwg1330: 4 c++11
 
 // cwg1334: sup 1719
 
+namespace cwg1340 { // cwg1340: 2.9
+struct A;
+struct B;
+
+void f(B* a, A B::* p) {
+  (*a).*p;
+  // expected-warning@-1 {{expression result unused}}
+  a->*p;
+  // expected-warning@-1 {{expression result unused}}
+}
+} // namespace cwg1340
+
 namespace cwg1341 { // cwg1341: sup P0683R1
 #if __cplusplus >= 202002L
 int a;
@@ -451,6 +463,25 @@ static_assert(!__is_nothrow_constructible(D4, int), "");
 #endif
 } // namespace cwg1350
 
+namespace cwg1352 { // 3.0
+struct A {
+#if __cplusplus >= 201103L
+  int a = sizeof(A);
+#endif
+  void f(int b = sizeof(A));
+};
+
+template 
+struct B {
+#if __cplusplus >= 201103L
+  int a = sizeof(B) + sizeof(T);
+#endif
+  void f(int b = sizeof(B) + sizeof(T));
+};
+
+template class B;
+} // namespace cwg1352
+
 namespace cwg1358 { // cwg1358: 3.1
 #if __cplusplus >= 201103L
   struct Lit { constexpr operator int() const { return 0; } };
diff --git a/clang/test/CXX/drs/cwg14xx.cpp b/clang/test/CXX/drs/cwg14xx.cpp
index 9ff9a68dc13c3..f01d96ad47f3e 100644
--- a/clang/test/CXX/drs/cwg14xx.cpp
+++ b/clang/test/CXX/drs/cwg14xx.cpp
@@ -86,6 +86,23 @@ struct A {
 };
 }
 
+namespace cwg1458 { // cwg1458: 3.1
+#if __cplusplus >= 201103L
+struct A;
+
+void f() {
+  constexpr A* a = nullptr;
+  constexpr int p = &*a;
+  // expected-error@-1 {{cannot initialize a variable of type 'const int' with 
an rvalue of type 'A *'}}
+  constexpr A *p2 = &*a;
+}
+
+struct A {
+  int operator&();
+};
+#endif
+} // namespace cwg1458
+
 namespace cwg1460 { // cwg1460: 3.5
 #if __cplusplus >= 201103L
   namespace DRExample {
diff --git a/clang/test/CXX/drs/cwg18xx.cpp b/clang/test/CXX/drs/cwg18xx.cpp
index 9eb749153e57a..89adc28384904 100644
--- a/clang/test/CXX/drs/cwg18xx.cpp
+++ b/clang/test/CXX/drs/cwg18xx.cpp
@@ -206,7 +206,7 @@ namespace cwg1814 { // cwg1814: yes
 #endif
 }
 
-namespace cwg1815 { // cwg1815: yes
+namespace cwg1815 { // cwg1815: 19
 #if __cplusplus >= 201402L
   struct A { int &&r = 0; };
   A a = {};
@@ -303,6 +303,32 @@ namespace cwg1822 { // cwg1822: yes
 #endif
 }
 
+namespace cwg1824 { // cwg1824: 2.7
+template
+struct A {
+  T t;
+};
+
+struct S {
+  A f() { return A(); }
+};
+} // namespace cwg1824
+
+namespace cwg1832 { // cwg1832: 3.0
+enum E { // #cwg1832-E
+  a = static_cast(static_cast(0))
+  // expected-error@-1 {{'E' is an incomplete type}}
+  //   expected-note@#cwg1832-E {{definition of 'cwg1832::E' is not complete 
until the closing '}'}}
+};
+
+#if __cplusplus >= 201103L
+enum E2: decltype(static_cast(0), 0) {};
+// expected-error@-1 {{unknown type name 'E2'}}
+enum class E3: decltype(static_cast(0), 0) {};
+// expected-error@-1 {{unknown type name 'E3'}}
+#endif
+} // namespace cwg1832
+
 namespace cwg1837 { // cwg1837: 3.3
 #if __cplusplus >= 201103L
   template 
diff --git a/clang/test/CXX/drs/cwg23xx.cpp b/clang/test/CXX/drs/cwg23xx.cpp
index db5b7c3cd3c9a..c671a770f3b28 100644
--- a/clang/test/CXX/drs/cwg23xx.cpp
+++ b/clang/test/CXX/drs/cwg23xx.cpp
@@ -1,6 +1,6 @@
 // RUN

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

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

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


[clang] [clang] Store FPOptions earlier when parsing function (PR #92146)

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


@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-pch -DHEADER -x c++-header %s -o %t.pch
+// RUN: %clang_cc1 -emit-llvm -include-pch %t.pch %s -o /dev/null
+
+#ifdef HEADER
+__attribute__((optnone)) void foo() {}
+#endif

SLTozer wrote:

Ah, that makes sense since you're using a single file as the source and header 
- as does the resulting error. New test LGTM.

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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits


@@ -670,9 +670,6 @@ void CodeGenPassBuilder::addIRPasses(
   !Opt.DisablePartialLibcallInlining)
 addPass(PartiallyInlineLibCallsPass());
 
-  // Instrument function entry and exit, e.g. with calls to mcount().
-  addPass(EntryExitInstrumenterPass(/*PostInlining=*/true));

pasko wrote:

Reverted. Thanks for sharing the context about this file!

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


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

2024-05-15 Thread via cfe-commits

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

moved fix for ExtractAPI from https://github.com/llvm/llvm-project/pull/91854, 
https://github.com/llvm/llvm-project/pull/91854#pullrequestreview-2052128349

Also noticed typo here, prefix `E` but check for `C`, fixed too:
https://github.com/llvm/llvm-project/blob/ca4a405232cf170f20a2f111bf72beab82095935/clang/test/ExtractAPI/availability.c#L43-L65

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

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

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

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


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

2024-05-15 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


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

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: klensy (klensy)


Changes

moved fix for ExtractAPI from https://github.com/llvm/llvm-project/pull/91854, 
https://github.com/llvm/llvm-project/pull/91854#pullrequestreview-2052128349

Also noticed typo here, prefix `E` but check for `C`, fixed too:
https://github.com/llvm/llvm-project/blob/ca4a405232cf170f20a2f111bf72beab82095935/clang/test/ExtractAPI/availability.c#L43-L65

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


2 Files Affected:

- (modified) clang/test/ExtractAPI/availability.c (+1-1) 
- (modified) clang/test/ExtractAPI/objc_property.m (+2-2) 


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

``




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


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

2024-05-15 Thread via cfe-commits

klensy wrote:

@daniel-grumberg Moved ExtractAPI changes to 
https://github.com/llvm/llvm-project/pull/92231

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


[clang] [flang] [libc] [libcxx] [llvm] [mlir] Fix typo "indicies" (PR #92232)

2024-05-15 Thread Jay Foad via cfe-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/92232

None

>From a02c63497b0d60f55e1846f5a050820082fb5c86 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Wed, 15 May 2024 10:04:57 +0100
Subject: [PATCH] Fix typo "indicies"

---
 clang/include/clang/AST/VTTBuilder.h  |  6 +-
 clang/lib/AST/VTTBuilder.cpp  |  2 +-
 clang/lib/CodeGen/CGVTT.cpp   | 17 ++---
 clang/lib/CodeGen/CGVTables.h |  6 +-
 .../command/commands/DexExpectStepOrder.py|  2 +-
 flang/docs/HighLevelFIR.md|  2 +-
 flang/test/Lower/HLFIR/forall.f90 |  2 +-
 libc/src/stdio/printf_core/parser.h   |  2 +-
 .../views/mdspan/CustomTestLayouts.h  |  2 +-
 llvm/docs/GlobalISel/GenericOpcode.rst|  4 +-
 llvm/include/llvm/Target/Target.td|  4 +-
 llvm/lib/Analysis/DependenceAnalysis.cpp  | 10 +--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 12 ++--
 llvm/lib/Bitcode/Writer/ValueEnumerator.cpp   |  2 +-
 llvm/lib/Bitcode/Writer/ValueEnumerator.h |  2 +-
 .../LiveDebugValues/VarLocBasedImpl.cpp   |  2 +-
 llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp   |  2 +-
 llvm/lib/CodeGen/PrologEpilogInserter.cpp |  2 +-
 llvm/lib/Support/ELFAttributeParser.cpp   | 10 +--
 .../Target/AArch64/AArch64ISelLowering.cpp|  2 +-
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  2 +-
 .../DirectX/DXILWriter/DXILBitcodeWriter.cpp  | 10 +--
 .../DXILWriter/DXILValueEnumerator.cpp|  2 +-
 .../DirectX/DXILWriter/DXILValueEnumerator.h  |  2 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 .../Transforms/InstCombine/InstCombinePHI.cpp |  4 +-
 .../Scalar/SeparateConstOffsetFromGEP.cpp |  2 +-
 .../Utils/SampleProfileInference.cpp  |  2 +-
 .../Transforms/Vectorize/SLPVectorizer.cpp| 64 +--
 llvm/test/CodeGen/X86/avx-vperm2x128.ll   |  2 +-
 .../test/DebugInfo/PDB/Inputs/every-type.yaml |  4 +-
 ...h-directive-personalityindex-diagnostics.s |  6 +-
 .../InstCombine/phi-extractvalue.ll   |  8 +--
 .../InstCombine/phi-of-insertvalues.ll|  6 +-
 .../VectorCombine/X86/scalarize-vector-gep.ll | 12 ++--
 .../Linalg/Transforms/Vectorization.cpp   |  6 +-
 36 files changed, 114 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/VTTBuilder.h 
b/clang/include/clang/AST/VTTBuilder.h
index 4acbc1f9e96b2..3c19e61a8701c 100644
--- a/clang/include/clang/AST/VTTBuilder.h
+++ b/clang/include/clang/AST/VTTBuilder.h
@@ -92,7 +92,7 @@ class VTTBuilder {
   using AddressPointsMapTy = llvm::DenseMap;
 
   /// The sub-VTT indices for the bases of the most derived class.
-  llvm::DenseMap SubVTTIndicies;
+  llvm::DenseMap SubVTTIndices;
 
   /// The secondary virtual pointer indices of all subobjects of
   /// the most derived class.
@@ -148,8 +148,8 @@ class VTTBuilder {
   }
 
   /// Returns a reference to the sub-VTT indices.
-  const llvm::DenseMap &getSubVTTIndicies() const {
-return SubVTTIndicies;
+  const llvm::DenseMap &getSubVTTIndices() const {
+return SubVTTIndices;
   }
 
   /// Returns a reference to the secondary virtual pointer indices.
diff --git a/clang/lib/AST/VTTBuilder.cpp b/clang/lib/AST/VTTBuilder.cpp
index d58e875177852..464a2014c430a 100644
--- a/clang/lib/AST/VTTBuilder.cpp
+++ b/clang/lib/AST/VTTBuilder.cpp
@@ -189,7 +189,7 @@ void VTTBuilder::LayoutVTT(BaseSubobject Base, bool 
BaseIsVirtual) {
 
   if (!IsPrimaryVTT) {
 // Remember the sub-VTT index.
-SubVTTIndicies[Base] = VTTComponents.size();
+SubVTTIndices[Base] = VTTComponents.size();
   }
 
   uint64_t VTableIndex = VTTVTables.size();
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index d2376b14dd582..4cebb750c89e8 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -138,23 +138,24 @@ uint64_t CodeGenVTables::getSubVTTIndex(const 
CXXRecordDecl *RD,
 BaseSubobject Base) {
   BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
 
-  SubVTTIndiciesMapTy::iterator I = SubVTTIndicies.find(ClassSubobjectPair);
-  if (I != SubVTTIndicies.end())
+  SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);
+  if (I != SubVTTIndices.end())
 return I->second;
 
   VTTBuilder Builder(CGM.getContext(), RD, /*GenerateDefinition=*/false);
 
-  for (llvm::DenseMap::const_iterator I =
-   Builder.getSubVTTIndicies().begin(),
-   E = Builder.getSubVTTIndicies().end(); I != E; ++I) {
+  for (llvm::DenseMap::const_iterator
+   I = Builder.getSubVTTIndices().begin(),
+   E = Builder.getSubVTTIndices().end();
+   I != E; ++I) {
 // Insert all indices.
 BaseSubobjectPairTy ClassSubobjectPair(RD, I->first);
 
-SubVTTIndicies.insert(std::make_pair(ClassSubobjectPair, I->second));
+SubVTTIndices.insert(std::make_pair(ClassSubobjectPair, I->second));
   }
 
-  I = SubVTTIndicies.find(ClassSubobjectPair);

[clang] [flang] [libc] [libcxx] [llvm] [mlir] Fix typo "indicies" (PR #92232)

2024-05-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-backend-aarch64

Author: Jay Foad (jayfoad)


Changes



---

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


36 Files Affected:

- (modified) clang/include/clang/AST/VTTBuilder.h (+3-3) 
- (modified) clang/lib/AST/VTTBuilder.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGVTT.cpp (+9-8) 
- (modified) clang/lib/CodeGen/CGVTables.h (+3-3) 
- (modified) 
cross-project-tests/debuginfo-tests/dexter/dex/command/commands/DexExpectStepOrder.py
 (+1-1) 
- (modified) flang/docs/HighLevelFIR.md (+1-1) 
- (modified) flang/test/Lower/HLFIR/forall.f90 (+1-1) 
- (modified) libc/src/stdio/printf_core/parser.h (+1-1) 
- (modified) libcxx/test/std/containers/views/mdspan/CustomTestLayouts.h (+1-1) 
- (modified) llvm/docs/GlobalISel/GenericOpcode.rst (+2-2) 
- (modified) llvm/include/llvm/Target/Target.td (+2-2) 
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+5-5) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+6-6) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+1-1) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.h (+1-1) 
- (modified) llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/PrologEpilogInserter.cpp (+1-1) 
- (modified) llvm/lib/Support/ELFAttributeParser.cpp (+5-5) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+5-5) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/SampleProfileInference.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+32-32) 
- (modified) llvm/test/CodeGen/X86/avx-vperm2x128.ll (+1-1) 
- (modified) llvm/test/DebugInfo/PDB/Inputs/every-type.yaml (+2-2) 
- (modified) llvm/test/MC/ARM/eh-directive-personalityindex-diagnostics.s 
(+3-3) 
- (modified) llvm/test/Transforms/InstCombine/phi-extractvalue.ll (+4-4) 
- (modified) llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll (+3-3) 
- (modified) llvm/test/Transforms/VectorCombine/X86/scalarize-vector-gep.ll 
(+6-6) 
- (modified) mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/AST/VTTBuilder.h 
b/clang/include/clang/AST/VTTBuilder.h
index 4acbc1f9e96b2..3c19e61a8701c 100644
--- a/clang/include/clang/AST/VTTBuilder.h
+++ b/clang/include/clang/AST/VTTBuilder.h
@@ -92,7 +92,7 @@ class VTTBuilder {
   using AddressPointsMapTy = llvm::DenseMap;
 
   /// The sub-VTT indices for the bases of the most derived class.
-  llvm::DenseMap SubVTTIndicies;
+  llvm::DenseMap SubVTTIndices;
 
   /// The secondary virtual pointer indices of all subobjects of
   /// the most derived class.
@@ -148,8 +148,8 @@ class VTTBuilder {
   }
 
   /// Returns a reference to the sub-VTT indices.
-  const llvm::DenseMap &getSubVTTIndicies() const {
-return SubVTTIndicies;
+  const llvm::DenseMap &getSubVTTIndices() const {
+return SubVTTIndices;
   }
 
   /// Returns a reference to the secondary virtual pointer indices.
diff --git a/clang/lib/AST/VTTBuilder.cpp b/clang/lib/AST/VTTBuilder.cpp
index d58e875177852..464a2014c430a 100644
--- a/clang/lib/AST/VTTBuilder.cpp
+++ b/clang/lib/AST/VTTBuilder.cpp
@@ -189,7 +189,7 @@ void VTTBuilder::LayoutVTT(BaseSubobject Base, bool 
BaseIsVirtual) {
 
   if (!IsPrimaryVTT) {
 // Remember the sub-VTT index.
-SubVTTIndicies[Base] = VTTComponents.size();
+SubVTTIndices[Base] = VTTComponents.size();
   }
 
   uint64_t VTableIndex = VTTVTables.size();
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index d2376b14dd582..4cebb750c89e8 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -138,23 +138,24 @@ uint64_t CodeGenVTables::getSubVTTIndex(const 
CXXRecordDecl *RD,
 BaseSubobject Base) {
   BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
 
-  SubVTTIndiciesMapTy::iterator I = SubVTTIndicies.find(ClassSubobjectPair);
-  if (I != SubVTTIndicies.end())
+  SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);
+  if (I != SubVTTIndices.end())
 return I->second;
 
   VTTBuilder Builder(CGM.getContext(), RD, /*GenerateDefinition=*/false);
 
-  for (llvm::DenseMap::const_iterator I =
-   Builder.getSubVTTIndicies().begin(),
-   E = Builder.getSubVTTIndicies().end(); I != E; ++I) {
+  for (llvm::Dense

[clang] [flang] [libc] [libcxx] [llvm] [mlir] Fix typo "indicies" (PR #92232)

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-powerpc

Author: Jay Foad (jayfoad)


Changes



---

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


36 Files Affected:

- (modified) clang/include/clang/AST/VTTBuilder.h (+3-3) 
- (modified) clang/lib/AST/VTTBuilder.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGVTT.cpp (+9-8) 
- (modified) clang/lib/CodeGen/CGVTables.h (+3-3) 
- (modified) 
cross-project-tests/debuginfo-tests/dexter/dex/command/commands/DexExpectStepOrder.py
 (+1-1) 
- (modified) flang/docs/HighLevelFIR.md (+1-1) 
- (modified) flang/test/Lower/HLFIR/forall.f90 (+1-1) 
- (modified) libc/src/stdio/printf_core/parser.h (+1-1) 
- (modified) libcxx/test/std/containers/views/mdspan/CustomTestLayouts.h (+1-1) 
- (modified) llvm/docs/GlobalISel/GenericOpcode.rst (+2-2) 
- (modified) llvm/include/llvm/Target/Target.td (+2-2) 
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+5-5) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+6-6) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+1-1) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.h (+1-1) 
- (modified) llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/PrologEpilogInserter.cpp (+1-1) 
- (modified) llvm/lib/Support/ELFAttributeParser.cpp (+5-5) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+5-5) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/SampleProfileInference.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+32-32) 
- (modified) llvm/test/CodeGen/X86/avx-vperm2x128.ll (+1-1) 
- (modified) llvm/test/DebugInfo/PDB/Inputs/every-type.yaml (+2-2) 
- (modified) llvm/test/MC/ARM/eh-directive-personalityindex-diagnostics.s 
(+3-3) 
- (modified) llvm/test/Transforms/InstCombine/phi-extractvalue.ll (+4-4) 
- (modified) llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll (+3-3) 
- (modified) llvm/test/Transforms/VectorCombine/X86/scalarize-vector-gep.ll 
(+6-6) 
- (modified) mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/AST/VTTBuilder.h 
b/clang/include/clang/AST/VTTBuilder.h
index 4acbc1f9e96b2..3c19e61a8701c 100644
--- a/clang/include/clang/AST/VTTBuilder.h
+++ b/clang/include/clang/AST/VTTBuilder.h
@@ -92,7 +92,7 @@ class VTTBuilder {
   using AddressPointsMapTy = llvm::DenseMap;
 
   /// The sub-VTT indices for the bases of the most derived class.
-  llvm::DenseMap SubVTTIndicies;
+  llvm::DenseMap SubVTTIndices;
 
   /// The secondary virtual pointer indices of all subobjects of
   /// the most derived class.
@@ -148,8 +148,8 @@ class VTTBuilder {
   }
 
   /// Returns a reference to the sub-VTT indices.
-  const llvm::DenseMap &getSubVTTIndicies() const {
-return SubVTTIndicies;
+  const llvm::DenseMap &getSubVTTIndices() const {
+return SubVTTIndices;
   }
 
   /// Returns a reference to the secondary virtual pointer indices.
diff --git a/clang/lib/AST/VTTBuilder.cpp b/clang/lib/AST/VTTBuilder.cpp
index d58e875177852..464a2014c430a 100644
--- a/clang/lib/AST/VTTBuilder.cpp
+++ b/clang/lib/AST/VTTBuilder.cpp
@@ -189,7 +189,7 @@ void VTTBuilder::LayoutVTT(BaseSubobject Base, bool 
BaseIsVirtual) {
 
   if (!IsPrimaryVTT) {
 // Remember the sub-VTT index.
-SubVTTIndicies[Base] = VTTComponents.size();
+SubVTTIndices[Base] = VTTComponents.size();
   }
 
   uint64_t VTableIndex = VTTVTables.size();
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index d2376b14dd582..4cebb750c89e8 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -138,23 +138,24 @@ uint64_t CodeGenVTables::getSubVTTIndex(const 
CXXRecordDecl *RD,
 BaseSubobject Base) {
   BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
 
-  SubVTTIndiciesMapTy::iterator I = SubVTTIndicies.find(ClassSubobjectPair);
-  if (I != SubVTTIndicies.end())
+  SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);
+  if (I != SubVTTIndices.end())
 return I->second;
 
   VTTBuilder Builder(CGM.getContext(), RD, /*GenerateDefinition=*/false);
 
-  for (llvm::DenseMap::const_iterator I =
-   Builder.getSubVTTIndicies().begin(),
-   E = Builder.getSubVTTIndicies().end(); I != E; ++I) {
+  for (llvm::DenseMap::const_iterator
+   I = Builder.getSubVTTIndices(

[clang] [flang] [libc] [libcxx] [llvm] [mlir] Fix typo "indicies" (PR #92232)

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-arm

Author: Jay Foad (jayfoad)


Changes



---

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


36 Files Affected:

- (modified) clang/include/clang/AST/VTTBuilder.h (+3-3) 
- (modified) clang/lib/AST/VTTBuilder.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGVTT.cpp (+9-8) 
- (modified) clang/lib/CodeGen/CGVTables.h (+3-3) 
- (modified) 
cross-project-tests/debuginfo-tests/dexter/dex/command/commands/DexExpectStepOrder.py
 (+1-1) 
- (modified) flang/docs/HighLevelFIR.md (+1-1) 
- (modified) flang/test/Lower/HLFIR/forall.f90 (+1-1) 
- (modified) libc/src/stdio/printf_core/parser.h (+1-1) 
- (modified) libcxx/test/std/containers/views/mdspan/CustomTestLayouts.h (+1-1) 
- (modified) llvm/docs/GlobalISel/GenericOpcode.rst (+2-2) 
- (modified) llvm/include/llvm/Target/Target.td (+2-2) 
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+5-5) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+6-6) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+1-1) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.h (+1-1) 
- (modified) llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/PrologEpilogInserter.cpp (+1-1) 
- (modified) llvm/lib/Support/ELFAttributeParser.cpp (+5-5) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+5-5) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/SampleProfileInference.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+32-32) 
- (modified) llvm/test/CodeGen/X86/avx-vperm2x128.ll (+1-1) 
- (modified) llvm/test/DebugInfo/PDB/Inputs/every-type.yaml (+2-2) 
- (modified) llvm/test/MC/ARM/eh-directive-personalityindex-diagnostics.s 
(+3-3) 
- (modified) llvm/test/Transforms/InstCombine/phi-extractvalue.ll (+4-4) 
- (modified) llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll (+3-3) 
- (modified) llvm/test/Transforms/VectorCombine/X86/scalarize-vector-gep.ll 
(+6-6) 
- (modified) mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/AST/VTTBuilder.h 
b/clang/include/clang/AST/VTTBuilder.h
index 4acbc1f9e96b2..3c19e61a8701c 100644
--- a/clang/include/clang/AST/VTTBuilder.h
+++ b/clang/include/clang/AST/VTTBuilder.h
@@ -92,7 +92,7 @@ class VTTBuilder {
   using AddressPointsMapTy = llvm::DenseMap;
 
   /// The sub-VTT indices for the bases of the most derived class.
-  llvm::DenseMap SubVTTIndicies;
+  llvm::DenseMap SubVTTIndices;
 
   /// The secondary virtual pointer indices of all subobjects of
   /// the most derived class.
@@ -148,8 +148,8 @@ class VTTBuilder {
   }
 
   /// Returns a reference to the sub-VTT indices.
-  const llvm::DenseMap &getSubVTTIndicies() const {
-return SubVTTIndicies;
+  const llvm::DenseMap &getSubVTTIndices() const {
+return SubVTTIndices;
   }
 
   /// Returns a reference to the secondary virtual pointer indices.
diff --git a/clang/lib/AST/VTTBuilder.cpp b/clang/lib/AST/VTTBuilder.cpp
index d58e875177852..464a2014c430a 100644
--- a/clang/lib/AST/VTTBuilder.cpp
+++ b/clang/lib/AST/VTTBuilder.cpp
@@ -189,7 +189,7 @@ void VTTBuilder::LayoutVTT(BaseSubobject Base, bool 
BaseIsVirtual) {
 
   if (!IsPrimaryVTT) {
 // Remember the sub-VTT index.
-SubVTTIndicies[Base] = VTTComponents.size();
+SubVTTIndices[Base] = VTTComponents.size();
   }
 
   uint64_t VTableIndex = VTTVTables.size();
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index d2376b14dd582..4cebb750c89e8 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -138,23 +138,24 @@ uint64_t CodeGenVTables::getSubVTTIndex(const 
CXXRecordDecl *RD,
 BaseSubobject Base) {
   BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
 
-  SubVTTIndiciesMapTy::iterator I = SubVTTIndicies.find(ClassSubobjectPair);
-  if (I != SubVTTIndicies.end())
+  SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);
+  if (I != SubVTTIndices.end())
 return I->second;
 
   VTTBuilder Builder(CGM.getContext(), RD, /*GenerateDefinition=*/false);
 
-  for (llvm::DenseMap::const_iterator I =
-   Builder.getSubVTTIndicies().begin(),
-   E = Builder.getSubVTTIndicies().end(); I != E; ++I) {
+  for (llvm::DenseMap::const_iterator
+   I = Builder.getSubVTTIndices().be

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-15 Thread via cfe-commits

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

>From 1d6b0bb8479edce69e054ce461482bdbafb4eb4e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 1 May 2024 15:20:05 +
Subject: [PATCH 1/2] [Clang] Fix incorrect passing of _BitInt args

---
 clang/lib/CodeGen/Targets/AArch64.cpp   |  2 +-
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 4c32f510101f0..7daf416b624fa 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -302,7 +302,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)
diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
new file mode 100644
index 0..c7333bac75c1a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-bitint-argpass.c
@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
+
+_BitInt(129) v = -1;
+int h(_BitInt(129));
+
+// CHECK: declare i32 @h(ptr noundef)
+int largerthan128() {
+   return h(v);
+}
+
+

>From f67d0d5a9a99b72a238189e5f6a41586b5b81d6e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Tue, 14 May 2024 14:51:51 +
Subject: [PATCH 2/2] Fixed ext-int-cc.c test and removed the newly added one

---
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 --
 clang/test/CodeGen/ext-int-cc.c |  8 
 2 files changed, 4 insertions(+), 18 deletions(-)
 delete mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
deleted file mode 100644
index c7333bac75c1a..0
--- a/clang/test/CodeGen/aarch64-bitint-argpass.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// REQUIRES: arm-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-elf \
-// RUN:   -O2 \
-// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
-
-_BitInt(129) v = -1;
-int h(_BitInt(129));
-
-// CHECK: declare i32 @h(ptr noundef)
-int largerthan128() {
-   return h(v);
-}
-
-
diff --git a/clang/test/CodeGen/ext-int-cc.c b/clang/test/CodeGen/ext-int-cc.c
index 001e866d34b45..508728172ab4a 100644
--- a/clang/test/CodeGen/ext-int-cc.c
+++ b/clang/test/CodeGen/ext-int-cc.c
@@ -22,9 +22,9 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple systemz -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=SYSTEMZ
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC32
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -target-abi 
darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=AARCH64DARWIN
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios 
-target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck 
%s --check-prefixes=AARCH64DARWIN
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA64
@@ -135,6 +135,7 @@ void ParamPassing4(_BitInt(129) a) {}
 // WIN64: define dso_local void @ParamPassing4(ptr %{{.+}})
 // LIN32: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // WIN32: define dso_local void @ParamPassing4(ptr %{{.+}})
+// AARCH64: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // NACL-N

[clang] 421862f - [Clang] Fix incorrect passing of _BitInt args (#90741)

2024-05-15 Thread via cfe-commits

Author: Lukacma
Date: 2024-05-15T10:51:32+01:00
New Revision: 421862f8e4ffddf57e210a205984a0ee39c57d96

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

LOG: [Clang] Fix incorrect passing of _BitInt args (#90741)

This patch removes incorrect `byval` attribute from pointer argument
passed with >128 bit long _BitInt types.

Added: 


Modified: 
clang/lib/CodeGen/Targets/AArch64.cpp
clang/test/CodeGen/ext-int-cc.c

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index e32b060ebeb93..0a4711fb2170d 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -317,7 +317,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)

diff  --git a/clang/test/CodeGen/ext-int-cc.c b/clang/test/CodeGen/ext-int-cc.c
index 001e866d34b45..508728172ab4a 100644
--- a/clang/test/CodeGen/ext-int-cc.c
+++ b/clang/test/CodeGen/ext-int-cc.c
@@ -22,9 +22,9 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple systemz -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=SYSTEMZ
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC32
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -target-abi 
darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=AARCH64DARWIN
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios 
-target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck 
%s --check-prefixes=AARCH64DARWIN
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA64
@@ -135,6 +135,7 @@ void ParamPassing4(_BitInt(129) a) {}
 // WIN64: define dso_local void @ParamPassing4(ptr %{{.+}})
 // LIN32: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // WIN32: define dso_local void @ParamPassing4(ptr %{{.+}})
+// AARCH64: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // NACL-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
 // NVPTX64-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 
%{{.+}})
 // NVPTX-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
@@ -155,7 +156,6 @@ void ParamPassing4(_BitInt(129) a) {}
 // SYSTEMZ-NOT: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // PPC64-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
 // PPC32-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
-// AARCH64-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 
%{{.+}})
 // AARCH64DARWIN-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 
%{{.+}})
 // ARM-NOT: define{{.*}} arm_aapcscc void @ParamPassing4(ptr byval(i129) align 
8 %{{.+}})
 // LA64-NOT: define{{.*}} void @ParamPassing4(ptr %{{.+}})
@@ -294,6 +294,7 @@ _BitInt(129) ReturnPassing5(void){}
 // WIN64: define dso_local void @ReturnPassing5(ptr dead_on_unwind noalias 
writable sret
 // LIN32: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias 
writable sret
 // WIN32: define dso_local void @ReturnPassing5(ptr dead_on_unwind noalias 
writable sret
+// AARCH64: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias 
writable sret
 // NACL-NOT: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias 
writable sret
 // NVPTX64-NOT: define{{.*}} i129 @ReturnPassing5(
 // NVPTX-NOT: define{

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-15 Thread via cfe-commits

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


[clang] [clang][analyzer] Fix a crash in alpha.unix.BlockInCriticalSection (PR #90030)

2024-05-15 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/90030

From af05be993f4789705cde374dbf7efefd9a18f1c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Tue, 9 Apr 2024 10:44:43 +0200
Subject: [PATCH 1/2] [clang][analyzer] Fix alpha.unix.BlockInCriticalSection

When analyzing C code with function pointers the checker crashes because
of how the implementation extracts IdentifierInfo. Without the fix, this
test crashes.

Add crashing test
---
 .../Checkers/BlockInCriticalSectionChecker.cpp| 8 +---
 clang/test/Analysis/block-in-critical-section.c   | 6 ++
 2 files changed, 11 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/block-in-critical-section.c

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index e138debd1361c..d381a30f7e24c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -14,6 +14,7 @@
 //
 
//===--===//
 
+#include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -103,9 +104,10 @@ class RAIIMutexDescriptor {
   // this function is called instead of early returning it. To avoid this, 
a
   // bool variable (IdentifierInfoInitialized) is used and the function 
will
   // be run only once.
-  Guard = &Call.getCalleeAnalysisDeclContext()->getASTContext().Idents.get(
-  GuardName);
-  IdentifierInfoInitialized = true;
+  if (AnalysisDeclContext *CalleCtx = Call.getCalleeAnalysisDeclContext()) 
{
+Guard = &CalleCtx->getASTContext().Idents.get(GuardName);
+IdentifierInfoInitialized = true;
+  }
 }
   }
 
diff --git a/clang/test/Analysis/block-in-critical-section.c 
b/clang/test/Analysis/block-in-critical-section.c
new file mode 100644
index 0..1e174af541b18
--- /dev/null
+++ b/clang/test/Analysis/block-in-critical-section.c
@@ -0,0 +1,6 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,alpha.unix.BlockInCriticalSection -verify %s
+// expected-no-diagnostics
+
+// This should not crash
+int (*a)(void);
+void b(void) { a(); }

From a18c0900f438730c3bf25ac44ceac156fd416a12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Wed, 15 May 2024 12:08:33 +0200
Subject: [PATCH 2/2] Get ASTContext through StateManager

---
 .../Checkers/BlockInCriticalSectionChecker.cpp  | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index d381a30f7e24c..c57ca262d2484 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -104,10 +104,8 @@ class RAIIMutexDescriptor {
   // this function is called instead of early returning it. To avoid this, 
a
   // bool variable (IdentifierInfoInitialized) is used and the function 
will
   // be run only once.
-  if (AnalysisDeclContext *CalleCtx = Call.getCalleeAnalysisDeclContext()) 
{
-Guard = &CalleCtx->getASTContext().Idents.get(GuardName);
-IdentifierInfoInitialized = true;
-  }
+  const auto &ASTCtx = Call.getState()->getStateManager().getContext();
+  Guard = &ASTCtx.Idents.get(GuardName);
 }
   }
 

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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits


@@ -1016,6 +1000,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 if (!IsThinLTOPostLink) {
   addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB);
   addKCFIPass(TargetTriple, LangOpts, PB);
+  PB.registerPipelineStartEPCallback(

pasko wrote:

Done.

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


[clang] [Clang] Added lifetime markers for indereacly passed Aggregate types (PR #90849)

2024-05-15 Thread via cfe-commits

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

>From 18c489682d38837d7b0abc7b9ecf829a9df4bd0c Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Thu, 2 May 2024 11:33:13 +
Subject: [PATCH] [Clang] Added lifetime markers for temp. allocated Aggregate
 types

---
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/test/CodeGen/aarch64-byval-temp.c   | 46 +--
 ...-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c |  2 +
 ...cle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp |  2 +
 clang/test/CodeGen/nofpclass.c| 22 +
 5 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1b4ca2a8b2fe8..8fdde5326b8ed 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5202,6 +5202,16 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   Val = Builder.CreateFreeze(Val);
 IRCallArgs[FirstIRArg] = Val;
 
+// Emit lifetime markers for the temporary alloca.
+llvm::TypeSize ByvalTempElementSize =
+CGM.getDataLayout().getTypeAllocSize(Addr.getElementType());
+llvm::Value *LifetimeSize =
+EmitLifetimeStart(ByvalTempElementSize, Addr.getPointer());
+
+// Add cleanup code to emit the end lifetime marker after the call.
+if (LifetimeSize) // In case we disabled lifetime markers.
+  CallLifetimeEndAfterCall.emplace_back(Addr, LifetimeSize);
+
 I->copyInto(*this, Addr);
   } else {
 // We want to avoid creating an unnecessary temporary+copy here;
diff --git a/clang/test/CodeGen/aarch64-byval-temp.c 
b/clang/test/CodeGen/aarch64-byval-temp.c
index e9e2586406e5c..765a298f83ed0 100644
--- a/clang/test/CodeGen/aarch64-byval-temp.c
+++ b/clang/test/CodeGen/aarch64-byval-temp.c
@@ -1,13 +1,15 @@
-// RUN: %clang_cc1 -emit-llvm -triple arm64-- -o - %s -O0 | FileCheck %s 
--check-prefix=CHECK-O0
-// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns -triple arm64-- -o - %s -O3 
| FileCheck %s --check-prefix=CHECK-O3
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -emit-llvm -triple arm64-- 
-fexperimental-max-bitint-width=1024  -o - %s -O0 | FileCheck %s 
--check-prefix=CHECK-O0
+// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns 
-fexperimental-max-bitint-width=1024  -triple arm64-- -o - %s -O3 | FileCheck 
%s --check-prefix=CHECK-O3
 
 struct large {
 void* pointers[8];
 };
 
 void pass_large(struct large);
+void pass_large_BitInt(_BitInt(129));
 
-// For arm64, we don't use byval to pass structs but instead we create
+// For arm64, we don't use byval to pass structs and _BitInt(>128) type, but 
instead we create
 // temporary allocas.
 //
 // Make sure we generate the appropriate lifetime markers for the temporary
@@ -71,3 +73,41 @@ void example(void) {
 // Mark the end of the lifetime of `l`.
 // CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr %l)
 // CHECK-O3-NEXT: ret void
+
+void example_BitInt(void) {
+_BitInt(129) l = {0};
+pass_large_BitInt(l);
+pass_large_BitInt(l);
+}
+// CHECK-O0-LABEL: define dso_local void @example_BitInt(
+// CHECK-O0-NEXT:  entry:
+// CHECK-O0-NEXT:[[L:%.*]] = alloca i129, align 16
+// CHECK-O0-NEXT:[[INDIRECT_ARG_TEMP:%.*]] = alloca i129, align 16
+// CHECK-O0-NEXT:[[INDIRECT_ARG_TEMP1:%.*]] = alloca i129, align 16
+// CHECK-O0-NEXT:store i129 0, ptr [[L]], align 16
+// CHECK-O0-NEXT:[[TMP0:%.*]] = load i129, ptr [[L]], align 16
+// CHECK-O0-NEXT:store i129 [[TMP0]], ptr [[INDIRECT_ARG_TEMP]], align 16
+// CHECK-O0-NEXT:call void @pass_large_BitInt(ptr noundef 
[[INDIRECT_ARG_TEMP]])
+// CHECK-O0-NEXT:[[TMP1:%.*]] = load i129, ptr [[L]], align 16
+// CHECK-O0-NEXT:store i129 [[TMP1]], ptr [[INDIRECT_ARG_TEMP1]], align 16
+// CHECK-O0-NEXT:call void @pass_large_BitInt(ptr noundef 
[[INDIRECT_ARG_TEMP1]])
+// CHECK-O0-NEXT:ret void
+//
+// CHECK-O3-LABEL: define dso_local void @example_BitInt(
+// CHECK-O3-NEXT:  entry:
+// CHECK-O3-NEXT:[[L:%.*]] = alloca i129, align 16
+// CHECK-O3-NEXT:[[INDIRECT_ARG_TEMP:%.*]] = alloca i129, align 16
+// CHECK-O3-NEXT:[[INDIRECT_ARG_TEMP1:%.*]] = alloca i129, align 16
+// CHECK-O3-NEXT:call void @llvm.lifetime.start.p0(i64 32, ptr [[L]]) 
+// CHECK-O3-NEXT:store i129 0, ptr [[L]], align 16, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-O3-NEXT:[[TMP0:%.*]] = load i129, ptr [[L]], align 16, !tbaa 
[[TBAA6]]
+// CHECK-O3-NEXT:call void @llvm.lifetime.start.p0(i64 32, ptr 
[[INDIRECT_ARG_TEMP]]) 
+// CHECK-O3-NEXT:store i129 [[TMP0]], ptr [[INDIRECT_ARG_TEMP]], align 16, 
!tbaa [[TBAA6]]
+// CHECK-O3-NEXT:call void @pass_large_BitInt(ptr noundef 
[[INDIRECT_ARG_TEMP]])
+// CHECK-O3-NEXT:call void @llvm.lifetime.end.p0(i64 32, ptr 
[[INDIRECT_ARG_TEMP]]) 
+// CHECK-O3-NEXT:[[TMP1:%.*]] = load i129, ptr

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

2024-05-15 Thread via cfe-commits

klensy wrote:

> Ok, running https://gist.github.com/klensy/2a6cf62f228b676b73cb5b16a599b93b 
> over current PR will give more hits, but with few FP, so be aware.

Funny, there already exist linter 
https://github.com/llvm/llvm-project/blob/d187005cad8c2cb7d44ba3dd6b01c5f0e4c14ae7/llvm/utils/filecheck_lint/filecheck_lint.py

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


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

2024-05-15 Thread via cfe-commits

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


[clang] [lldb] [llvm] [openmp] [polly] fix(python): fix comparison to True/False (PR #91858)

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

NagyDonat wrote:

The main problem with comparison to `True`/`False` is that it's completely 
redundant when the variable is _guaranteed to be boolean_. However, if a 
variable may contain either a boolean or something else, it's reasonable to 
compare it with `True` or `False`.

For the operator `==` there is another pitfall that according to Python `True 
== 1` and `False == 0` holds. (In ancient versions `True` and `False` were 
simply integer constants with these values; now `bool` is a subclass of `int` 
and preserves this old behavior.)

This implies that:
- When `x` is guaranteed to be a boolean, it should be used as `if x:` or `if 
not x:` (instead of `if x == True:` or `if x == False:`.
- Otherwise it may be reasonable to use the `is` operator: e.g. when `x` may be 
`True`, `False` or `None`, it is reasonable to check `if x is False:` or `if x 
is None:`.
- Using `==` has no advantage over `is` and could cause very surprising bugs 
when the variable can hold either a boolean or a number, so I'd say that it 
should be avoided. (However I admit that when `x` is known to be either `True`, 
`False` or `None`, there's a high chance that I'd instinctively write `if x == 
False:`.)

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


[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-15 Thread Björn Svensson via cfe-commits

https://github.com/bjosv created https://github.com/llvm/llvm-project/pull/92241

`readability-implicit-bool-conversion` supports language-versions with 
`LangOpts.Bool` which includes C23.

This PR corrects an issue that the fixer suggests `static_cast<>()` which is 
not available in C23,
and will instead suggest C-style casts on other than C++.

The fixer will also suggest using `nullptr` instead of `0` and avoid a problem 
with recursive fixes on C23.

The recursive issue, a function taking bool and a comparison, is now excluded 
as in C++.
Before change:
```
  functionTakingBool(integer1 == integer2);
 ^
 (   ) != 0

  functionTakingBool((integer1 == integer2) != 0);
 ^
 (  ) != 0
```
```
AST snippet in C23 for functionTakingBool(integer1 == integer2):

  `-CallExpr 0x5bf18d403b58  'void'
`-ImplicitCastExpr 0x5bf18d403b80  'bool' 

  `-BinaryOperator 0x5bf18d403ae8  'int' '=='
|-ImplicitCastExpr 0x5bf18d403ab8  'int' 
...

compared to AST in C++:

  `-CallExpr 0x5815dec42a78  'void'
`-BinaryOperator 0x5815dec429f0  'bool' '=='
  |-ImplicitCastExpr 0x5815dec429c0  'int' 
  ...
```

From 44ae41f00064dc477db0eb00b45fceff811cadec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Mon, 29 Apr 2024 12:49:59 +0200
Subject: [PATCH 1/3] [clang-tidy] Use C-style casts on C23 in
 readability-implicit-bool-conversion

readability-implicit-bool-conversion supports language-versions which has
LangOpts.Bool and that includes C23. The problem is that the fixer suggests
`static_cast<>()` which is not available in C23.

Update checker to provide C-style casts when running on other than C++.
---
 .../ImplicitBoolConversionCheck.cpp   |   6 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../readability/implicit-bool-conversion.rst  |   4 +-
 .../readability/implicit-bool-conversion.c| 333 ++
 4 files changed, 343 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 74152c6034510..c2d1bc691d58a 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -165,6 +165,12 @@ bool needsSpacePrefix(SourceLocation Loc, ASTContext 
&Context) {
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
+  if (!Context.getLangOpts().CPlusPlus) {
+Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(),
+   (Twine("(") + OtherType + ")").str());
+return;
+  }
+
   const Expr *SubExpr = Cast->getSubExpr();
   const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
   const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19f8307412956..d19f83793a6c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
-  fixed problem with duplicate parentheses in double implicit casts.
+  fixed problem with duplicate parentheses in double implicit casts. Corrected
+  the fix suggestions for C23 by using C-style casts instead of 
``static_cast``.
 
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
index 1ea67a0b55e96..643af488ae3df 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
@@ -96,8 +96,8 @@ The rules for generating fix-it hints are:
   - ``if (!pointer)`` is changed to ``if (pointer == nullptr)``,
 
 - in case of conversions from bool to other built-in types, an explicit
-  ``static_cast`` is proposed to make it clear that a conversion is taking
-  place:
+  ``static_cast`` (or a C-style cast for C23) is proposed to make it clear that
+  a conversion is taking place:
 
   - ``int integer = boolean;`` is changed to
 ``int integer = static_cast(boolean);``,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readabili

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

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

https://github.com/daniel-grumberg approved this pull request.

LGTM! Thanks for doing this!

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


[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-15 Thread via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Björn Svensson (bjosv)


Changes

`readability-implicit-bool-conversion` supports language-versions with 
`LangOpts.Bool` which includes C23.

This PR corrects an issue that the fixer suggests `static_cast<>()` which 
is not available in C23,
and will instead suggest C-style casts on other than C++.

The fixer will also suggest using `nullptr` instead of `0` and avoid a problem 
with recursive fixes on C23.

The recursive issue, a function taking bool and a comparison, is now excluded 
as in C++.
Before change:
```
  functionTakingBool(integer1 == integer2);
 ^
 (   ) != 0

  functionTakingBool((integer1 == integer2) != 0);
 ^
 (  ) != 0
```
```
AST snippet in C23 for functionTakingBool(integer1 == integer2):

  `-CallExpr 0x5bf18d403b58  'void'
`-ImplicitCastExpr 0x5bf18d403b80  'bool' 

  `-BinaryOperator 0x5bf18d403ae8  'int' '=='
|-ImplicitCastExpr 0x5bf18d403ab8  'int' 

...

compared to AST in C++:

  `-CallExpr 0x5815dec42a78  'void'
`-BinaryOperator 0x5815dec429f0  'bool' '=='
  |-ImplicitCastExpr 0x5815dec429c0  'int' 

  ...
```

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


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
(+15-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
 (+2-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 (+354) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 74152c6034510..704972b604380 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -50,7 +50,9 @@ StringRef getZeroLiteralToCompareWithForType(CastKind 
CastExprKind,
 
   case CK_PointerToBoolean:
   case CK_MemberPointerToBoolean: // Fall-through on purpose.
-return Context.getLangOpts().CPlusPlus11 ? "nullptr" : "0";
+return (Context.getLangOpts().CPlusPlus11 || Context.getLangOpts().C23)
+   ? "nullptr"
+   : "0";
 
   default:
 llvm_unreachable("Unexpected cast kind");
@@ -165,6 +167,12 @@ bool needsSpacePrefix(SourceLocation Loc, ASTContext 
&Context) {
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
+  if (!Context.getLangOpts().CPlusPlus) {
+Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(),
+   (Twine("(") + OtherType + ")").str());
+return;
+  }
+
   const Expr *SubExpr = Cast->getSubExpr();
   const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
   const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
@@ -267,6 +275,10 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   auto BoolXor =
   binaryOperator(hasOperatorName("^"), hasLHS(ImplicitCastFromBool),
  hasRHS(ImplicitCastFromBool));
+  auto ComparisonInCall =
+  allOf(hasParent(callExpr()),
+has(binaryOperator(hasAnyOperatorName("==", "!=";
+
   Finder->addMatcher(
   traverse(TK_AsIs,
implicitCastExpr(
@@ -281,6 +293,8 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
stmt(anyOf(ifStmt(), whileStmt()), has(declStmt(),
// Exclude cases common to implicit cast to and from bool.
unless(ExceptionCases), unless(has(BoolXor)),
+   // Exclude C23 cases common to implicit cast to bool.
+   unless(ComparisonInCall),
// Retrieve also parent statement, to check if we need
// additional parens in replacement.
optionally(hasParent(stmt().bind("parentStmt"))),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19f8307412956..d19f83793a6c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix sug

[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-15 Thread via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Björn Svensson (bjosv)


Changes

`readability-implicit-bool-conversion` supports language-versions with 
`LangOpts.Bool` which includes C23.

This PR corrects an issue that the fixer suggests `static_cast<>()` which 
is not available in C23,
and will instead suggest C-style casts on other than C++.

The fixer will also suggest using `nullptr` instead of `0` and avoid a problem 
with recursive fixes on C23.

The recursive issue, a function taking bool and a comparison, is now excluded 
as in C++.
Before change:
```
  functionTakingBool(integer1 == integer2);
 ^
 (   ) != 0

  functionTakingBool((integer1 == integer2) != 0);
 ^
 (  ) != 0
```
```
AST snippet in C23 for functionTakingBool(integer1 == integer2):

  `-CallExpr 0x5bf18d403b58  'void'
`-ImplicitCastExpr 0x5bf18d403b80  'bool' 

  `-BinaryOperator 0x5bf18d403ae8  'int' '=='
|-ImplicitCastExpr 0x5bf18d403ab8  'int' 

...

compared to AST in C++:

  `-CallExpr 0x5815dec42a78  'void'
`-BinaryOperator 0x5815dec429f0  'bool' '=='
  |-ImplicitCastExpr 0x5815dec429c0  'int' 

  ...
```

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


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
(+15-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
 (+2-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 (+354) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 74152c6034510..704972b604380 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -50,7 +50,9 @@ StringRef getZeroLiteralToCompareWithForType(CastKind 
CastExprKind,
 
   case CK_PointerToBoolean:
   case CK_MemberPointerToBoolean: // Fall-through on purpose.
-return Context.getLangOpts().CPlusPlus11 ? "nullptr" : "0";
+return (Context.getLangOpts().CPlusPlus11 || Context.getLangOpts().C23)
+   ? "nullptr"
+   : "0";
 
   default:
 llvm_unreachable("Unexpected cast kind");
@@ -165,6 +167,12 @@ bool needsSpacePrefix(SourceLocation Loc, ASTContext 
&Context) {
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
+  if (!Context.getLangOpts().CPlusPlus) {
+Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(),
+   (Twine("(") + OtherType + ")").str());
+return;
+  }
+
   const Expr *SubExpr = Cast->getSubExpr();
   const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
   const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
@@ -267,6 +275,10 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   auto BoolXor =
   binaryOperator(hasOperatorName("^"), hasLHS(ImplicitCastFromBool),
  hasRHS(ImplicitCastFromBool));
+  auto ComparisonInCall =
+  allOf(hasParent(callExpr()),
+has(binaryOperator(hasAnyOperatorName("==", "!=";
+
   Finder->addMatcher(
   traverse(TK_AsIs,
implicitCastExpr(
@@ -281,6 +293,8 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
stmt(anyOf(ifStmt(), whileStmt()), has(declStmt(),
// Exclude cases common to implicit cast to and from bool.
unless(ExceptionCases), unless(has(BoolXor)),
+   // Exclude C23 cases common to implicit cast to bool.
+   unless(ComparisonInCall),
// Retrieve also parent statement, to check if we need
// additional parens in replacement.
optionally(hasParent(stmt().bind("parentStmt"))),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19f8307412956..d19f83793a6c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestion

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

2024-05-15 Thread via cfe-commits

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


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

2024-05-15 Thread via cfe-commits

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


[clang] [flang] [libc] [libcxx] [llvm] [mlir] Fix typo "indicies" (PR #92232)

2024-05-15 Thread Matt Arsenault via cfe-commits

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


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


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

2024-05-15 Thread via cfe-commits

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

>From 18c489682d38837d7b0abc7b9ecf829a9df4bd0c Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Thu, 2 May 2024 11:33:13 +
Subject: [PATCH 1/2] [Clang] Added lifetime markers for temp. allocated
 Aggregate types

---
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/test/CodeGen/aarch64-byval-temp.c   | 46 +--
 ...-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c |  2 +
 ...cle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp |  2 +
 clang/test/CodeGen/nofpclass.c| 22 +
 5 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1b4ca2a8b2fe8..8fdde5326b8ed 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5202,6 +5202,16 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   Val = Builder.CreateFreeze(Val);
 IRCallArgs[FirstIRArg] = Val;
 
+// Emit lifetime markers for the temporary alloca.
+llvm::TypeSize ByvalTempElementSize =
+CGM.getDataLayout().getTypeAllocSize(Addr.getElementType());
+llvm::Value *LifetimeSize =
+EmitLifetimeStart(ByvalTempElementSize, Addr.getPointer());
+
+// Add cleanup code to emit the end lifetime marker after the call.
+if (LifetimeSize) // In case we disabled lifetime markers.
+  CallLifetimeEndAfterCall.emplace_back(Addr, LifetimeSize);
+
 I->copyInto(*this, Addr);
   } else {
 // We want to avoid creating an unnecessary temporary+copy here;
diff --git a/clang/test/CodeGen/aarch64-byval-temp.c 
b/clang/test/CodeGen/aarch64-byval-temp.c
index e9e2586406e5c..765a298f83ed0 100644
--- a/clang/test/CodeGen/aarch64-byval-temp.c
+++ b/clang/test/CodeGen/aarch64-byval-temp.c
@@ -1,13 +1,15 @@
-// RUN: %clang_cc1 -emit-llvm -triple arm64-- -o - %s -O0 | FileCheck %s 
--check-prefix=CHECK-O0
-// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns -triple arm64-- -o - %s -O3 
| FileCheck %s --check-prefix=CHECK-O3
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -emit-llvm -triple arm64-- 
-fexperimental-max-bitint-width=1024  -o - %s -O0 | FileCheck %s 
--check-prefix=CHECK-O0
+// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns 
-fexperimental-max-bitint-width=1024  -triple arm64-- -o - %s -O3 | FileCheck 
%s --check-prefix=CHECK-O3
 
 struct large {
 void* pointers[8];
 };
 
 void pass_large(struct large);
+void pass_large_BitInt(_BitInt(129));
 
-// For arm64, we don't use byval to pass structs but instead we create
+// For arm64, we don't use byval to pass structs and _BitInt(>128) type, but 
instead we create
 // temporary allocas.
 //
 // Make sure we generate the appropriate lifetime markers for the temporary
@@ -71,3 +73,41 @@ void example(void) {
 // Mark the end of the lifetime of `l`.
 // CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr %l)
 // CHECK-O3-NEXT: ret void
+
+void example_BitInt(void) {
+_BitInt(129) l = {0};
+pass_large_BitInt(l);
+pass_large_BitInt(l);
+}
+// CHECK-O0-LABEL: define dso_local void @example_BitInt(
+// CHECK-O0-NEXT:  entry:
+// CHECK-O0-NEXT:[[L:%.*]] = alloca i129, align 16
+// CHECK-O0-NEXT:[[INDIRECT_ARG_TEMP:%.*]] = alloca i129, align 16
+// CHECK-O0-NEXT:[[INDIRECT_ARG_TEMP1:%.*]] = alloca i129, align 16
+// CHECK-O0-NEXT:store i129 0, ptr [[L]], align 16
+// CHECK-O0-NEXT:[[TMP0:%.*]] = load i129, ptr [[L]], align 16
+// CHECK-O0-NEXT:store i129 [[TMP0]], ptr [[INDIRECT_ARG_TEMP]], align 16
+// CHECK-O0-NEXT:call void @pass_large_BitInt(ptr noundef 
[[INDIRECT_ARG_TEMP]])
+// CHECK-O0-NEXT:[[TMP1:%.*]] = load i129, ptr [[L]], align 16
+// CHECK-O0-NEXT:store i129 [[TMP1]], ptr [[INDIRECT_ARG_TEMP1]], align 16
+// CHECK-O0-NEXT:call void @pass_large_BitInt(ptr noundef 
[[INDIRECT_ARG_TEMP1]])
+// CHECK-O0-NEXT:ret void
+//
+// CHECK-O3-LABEL: define dso_local void @example_BitInt(
+// CHECK-O3-NEXT:  entry:
+// CHECK-O3-NEXT:[[L:%.*]] = alloca i129, align 16
+// CHECK-O3-NEXT:[[INDIRECT_ARG_TEMP:%.*]] = alloca i129, align 16
+// CHECK-O3-NEXT:[[INDIRECT_ARG_TEMP1:%.*]] = alloca i129, align 16
+// CHECK-O3-NEXT:call void @llvm.lifetime.start.p0(i64 32, ptr [[L]]) 
+// CHECK-O3-NEXT:store i129 0, ptr [[L]], align 16, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-O3-NEXT:[[TMP0:%.*]] = load i129, ptr [[L]], align 16, !tbaa 
[[TBAA6]]
+// CHECK-O3-NEXT:call void @llvm.lifetime.start.p0(i64 32, ptr 
[[INDIRECT_ARG_TEMP]]) 
+// CHECK-O3-NEXT:store i129 [[TMP0]], ptr [[INDIRECT_ARG_TEMP]], align 16, 
!tbaa [[TBAA6]]
+// CHECK-O3-NEXT:call void @pass_large_BitInt(ptr noundef 
[[INDIRECT_ARG_TEMP]])
+// CHECK-O3-NEXT:call void @llvm.lifetime.end.p0(i64 32, ptr 
[[INDIRECT_ARG_TEMP]]) 
+// CHECK-O3-NEXT:[[TMP1:%.*]] = load i129,

[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits


@@ -135,6 +138,65 @@ static bool runOnFunction(Function &F, bool PostInlining) {
   return Changed;
 }
 
+namespace {
+struct EntryExitInstrumenter : public FunctionPass {
+  static char ID;
+  EntryExitInstrumenter() : FunctionPass(ID) {
+initializeEntryExitInstrumenterPass(*PassRegistry::getPassRegistry());
+  }
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addPreserved();
+AU.addPreserved();
+  }
+  bool runOnFunction(Function &F) override { return ::runOnFunction(F, false); 
}
+};
+char EntryExitInstrumenter::ID = 0;
+
+struct PostInlineEntryExitInstrumenter : public FunctionPass {
+  static char ID;
+  PostInlineEntryExitInstrumenter() : FunctionPass(ID) {
+initializePostInlineEntryExitInstrumenterPass(
+*PassRegistry::getPassRegistry());
+  }
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addPreserved();
+AU.addPreserved();
+  }
+  bool runOnFunction(Function &F) override { return ::runOnFunction(F, true); }
+};
+char PostInlineEntryExitInstrumenter::ID = 0;
+}
+
+INITIALIZE_PASS_BEGIN(
+EntryExitInstrumenter, "ee-instrument",
+"Instrument function entry/exit with calls to e.g. mcount() (pre 
inlining)",
+false, false)
+INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+INITIALIZE_PASS_END(
+EntryExitInstrumenter, "ee-instrument",
+"Instrument function entry/exit with calls to e.g. mcount() (pre 
inlining)",
+false, false)
+
+INITIALIZE_PASS_BEGIN(
+PostInlineEntryExitInstrumenter, "post-inline-ee-instrument",
+"Instrument function entry/exit with calls to e.g. mcount() "
+"(post inlining)",
+false, false)
+INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+INITIALIZE_PASS_END(
+PostInlineEntryExitInstrumenter, "post-inline-ee-instrument",
+"Instrument function entry/exit with calls to e.g. mcount() "
+"(post inlining)",
+false, false)
+
+FunctionPass *llvm::createEntryExitInstrumenterPass() {

pasko wrote:

Removed.

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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits

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


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

2024-05-15 Thread via cfe-commits

yronglin wrote:

I've a more short reproducer:
```C++
namespace std {
template  class initializer_list {};
}

template  class C {
public:
  C(std::initializer_list);
};

template  using Ptr =__remove_pointer(T) *;
template   C(T) ->  C, sizeof(T)>;

class A {
public:
  template 
  T1 *some_func(T2 &&);
};

struct B : A {
  int *ar = some_func(C{some_func(0)});
  B() {}
};

```

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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits

https://github.com/pasko updated https://github.com/llvm/llvm-project/pull/92171

>From df3f8dfc47cd8d7b220ed712dc7c2cab1c563f50 Mon Sep 17 00:00:00 2001
From: Egor Pasko 
Date: Mon, 6 May 2024 19:48:59 +0200
Subject: [PATCH 1/2] wip: Move instrumentation passes

This change is not ready for landing yet.

Move EntryExitInstrumenter(PostInlining=true) to as late as possible and
EntryExitInstrumenter(PostInlining=false) to an early pre-inlining stage
(but skip for ThinLTO post-link).
---
 clang/lib/CodeGen/BackendUtil.cpp | 21 ++-
 llvm/include/llvm/InitializePasses.h  |  2 +
 llvm/include/llvm/LinkAllPasses.h |  2 +
 llvm/include/llvm/Passes/CodeGenPassBuilder.h |  3 -
 llvm/include/llvm/Transforms/Utils.h  |  9 +++
 llvm/lib/CodeGen/TargetPassConfig.cpp |  3 +
 llvm/lib/Transforms/Scalar/Scalar.cpp |  2 +
 .../Utils/EntryExitInstrumenter.cpp   | 62 +++
 llvm/tools/llc/llc.cpp|  2 +
 llvm/tools/opt/optdriver.cpp  |  2 +
 10 files changed, 89 insertions(+), 19 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 22c3f8642ad8e..f6ff605bcef87 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -987,22 +987,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
/*DropTypeTests=*/true));
   });
 
-if (CodeGenOpts.InstrumentFunctions ||
-CodeGenOpts.InstrumentFunctionEntryBare ||
-CodeGenOpts.InstrumentFunctionsAfterInlining ||
-CodeGenOpts.InstrumentForProfiling) {
-  PB.registerPipelineStartEPCallback(
-  [](ModulePassManager &MPM, OptimizationLevel Level) {
-MPM.addPass(createModuleToFunctionPassAdaptor(
-EntryExitInstrumenterPass(/*PostInlining=*/false)));
-  });
-  PB.registerOptimizerLastEPCallback(
-  [](ModulePassManager &MPM, OptimizationLevel Level) {
-MPM.addPass(createModuleToFunctionPassAdaptor(
-EntryExitInstrumenterPass(/*PostInlining=*/true)));
-  });
-}
-
 // Register callbacks to schedule sanitizer passes at the appropriate part
 // of the pipeline.
 if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
@@ -1016,6 +1000,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 if (!IsThinLTOPostLink) {
   addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB);
   addKCFIPass(TargetTriple, LangOpts, PB);
+  PB.registerPipelineStartEPCallback(
+  [](ModulePassManager &MPM, OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(
+EntryExitInstrumenterPass(/*PostInlining=*/false)));
+  });
 }
 
 if (std::optional Options =
diff --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index 9ba75d491c1c9..e970706e8202d 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -101,6 +101,7 @@ void initializeEarlyMachineLICMPass(PassRegistry&);
 void initializeEarlyTailDuplicatePass(PassRegistry&);
 void initializeEdgeBundlesPass(PassRegistry&);
 void initializeEHContGuardCatchretPass(PassRegistry &);
+void initializeEntryExitInstrumenterPass(PassRegistry&);
 void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry&);
 void initializeExpandLargeDivRemLegacyPassPass(PassRegistry&);
 void initializeExpandMemCmpLegacyPassPass(PassRegistry &);
@@ -230,6 +231,7 @@ void 
initializePostDomOnlyViewerWrapperPassPass(PassRegistry &);
 void initializePostDomPrinterWrapperPassPass(PassRegistry &);
 void initializePostDomViewerWrapperPassPass(PassRegistry &);
 void initializePostDominatorTreeWrapperPassPass(PassRegistry&);
+void initializePostInlineEntryExitInstrumenterPass(PassRegistry&);
 void initializePostMachineSchedulerPass(PassRegistry&);
 void initializePostRAHazardRecognizerPass(PassRegistry&);
 void initializePostRAMachineSinkingPass(PassRegistry&);
diff --git a/llvm/include/llvm/LinkAllPasses.h 
b/llvm/include/llvm/LinkAllPasses.h
index 30e7c22f31460..b432040b052a9 100644
--- a/llvm/include/llvm/LinkAllPasses.h
+++ b/llvm/include/llvm/LinkAllPasses.h
@@ -113,6 +113,8 @@ namespace {
   (void)llvm::createTLSVariableHoistPass();
   (void) llvm::createConstantHoistingPass();
   (void)llvm::createCodeGenPrepareLegacyPass();
+  (void) llvm::createEntryExitInstrumenterPass();
+  (void) llvm::createPostInlineEntryExitInstrumenterPass();
   (void) llvm::createEarlyCSEPass();
   (void) llvm::createGVNPass();
   (void) llvm::createPostDomTree();
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 2e94a19502131..b34f6e82fb7be 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -670,9 +670,6 @@ void CodeGenPa

[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits

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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits

pasko wrote:

> can you add links to https://reviews.llvm.org/D97608, 
> [rust-lang/rust#92109](https://github.com/rust-lang/rust/issues/92109), #52853

Done (Updated the toplevel comment on the PR) 

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

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

>From 659cf5b5c1216ab9f6a8dbb63b4f93de41cd173d Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 10:54:12 +0200
Subject: [PATCH 1/2] [clang] CTAD: implement the missing IsDeducible
 constraint for alias templates.

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

- rebase to main
- add release note for __is_deducible
- implement diagnostics for bad argument types for __is_deducible

Don't expose __is_deducible trait.

Refine the implementation of hiding __is_deducible type trait.

Apply approach 3.
---
 clang/include/clang/Basic/TokenKinds.def |  3 +
 clang/include/clang/Sema/Sema.h  |  9 ++
 clang/lib/Basic/TypeTraits.cpp   | 10 +++
 clang/lib/Sema/SemaExprCXX.cpp   | 10 ++-
 clang/lib/Sema/SemaTemplate.cpp  | 82 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 86 
 clang/test/AST/ast-dump-ctad-alias.cpp   | 20 +++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 27 --
 clang/test/SemaTemplate/deduction-guide.cpp  | 16 ++--
 clang/www/cxx_status.html|  4 +-
 10 files changed, 238 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..b5a0e9df9f7ae 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -538,6 +538,9 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary, KEYCXX)
+// IsDeducible is only used internally by clang for CTAD implementation and
+// is not exposed to users.
+TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..66d5e2d4a4ade 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9492,6 +9492,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Basic/TypeTraits.cpp b/clang/lib/Basic/TypeTraits.cpp
index 4dbf678dc395b..8d6794223ccaf 100644
--- a/clang/lib/Basic/TypeTraits.cpp
+++ b/clang/lib/Basic/TypeTraits.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 using namespace clang;
 
 static constexpr const char *TypeTraitNames[] = {
@@ -81,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
 
 const char *clang::getTraitSpelling(TypeTrait T) {
   assert(T <= TT_Last && "invalid enum value!");
+  if (T == BTT_IsDeducible) {
+// The __is_deducible is an internal-only type trait. To hide it from
+// external users, we define it with an empty spelling name, preventing the
+// clang parser from recognizing its token kind.
+// However, other components such as the AST dump still require the real
+// type trait name. Therefore, we return the real name when needed.
+assert(std::strlen(TypeTraitSpellings[T]) == 0);
+return "__is_deducible";
+  }
   return TypeTraitSpellings[T];
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 34e12078a8c92..e4601f7d6c47d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6143,7 +6143,15 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }
-default: llvm_unreachable("not a BTT");
+  case BTT_IsDeducible: {
+const auto *TSTToBeDeduced = cast(LhsT);
+sema::TemplateDeductionInfo Info(KeyLoc);
+return Self.DeduceTemplateArgumentsFromType(
+   TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT,
+   Info) == TemplateDeductionResult::Success;
+  }
+  default:
+llvm_unreachable("not a BTT");
   }
   llvm_unreachable("Unknow

[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

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


[clang] [flang] [flang] Add nsw flag to do-variable increment with a new option (PR #91579)

2024-05-15 Thread Yusuke MINATO via cfe-commits

https://github.com/yus3710-fj updated 
https://github.com/llvm/llvm-project/pull/91579

>From 262824a13615b700bbfc672c3a2d06e63892c6e3 Mon Sep 17 00:00:00 2001
From: Yusuke MINATO 
Date: Wed, 24 Apr 2024 14:42:21 +0900
Subject: [PATCH] [flang] Add nsw flag to do-variable increment with a new
 option

This patch adds nsw flag to the increment of do-variables when
a new option is enabled.
NOTE 11.10 in the Fortran 2018 standard says they never overflow.

See also the discussion in 74709 and
discourse post.

empty commit to re-run CI

modify the name of the lowering option and its comment
---
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/Driver/ToolChains/Flang.cpp |   1 +
 flang/include/flang/Lower/LoweringOptions.def |   4 +
 .../flang/Optimizer/Transforms/Passes.h   |   4 +-
 .../flang/Optimizer/Transforms/Passes.td  |   5 +-
 flang/include/flang/Tools/CLOptions.inc   |  13 +-
 flang/include/flang/Tools/CrossToolHelpers.h  |   1 +
 flang/lib/Frontend/CompilerInvocation.cpp |   6 +
 flang/lib/Frontend/FrontendActions.cpp|   3 +
 flang/lib/Lower/Bridge.cpp|  12 +-
 flang/lib/Lower/IO.cpp|   9 +-
 .../Transforms/ControlFlowConverter.cpp   |  44 +++-
 flang/test/Driver/frontend-forwarding.f90 |   2 +
 flang/test/Fir/loop01.fir | 211 ++
 flang/test/Lower/array-substring.f90  |  40 
 flang/test/Lower/do_loop.f90  |  42 
 flang/test/Lower/do_loop_unstructured.f90 | 189 +++-
 flang/test/Lower/infinite_loop.f90|  34 +++
 flang/test/Lower/io-implied-do-fixes.f90  |  51 -
 flang/tools/bbc/bbc.cpp   |   7 +
 20 files changed, 659 insertions(+), 23 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c54eb543d6580..03d2ff193d697 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6550,6 +6550,10 @@ def flang_deprecated_no_hlfir : Flag<["-"], 
"flang-deprecated-no-hlfir">,
   Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
   HelpText<"Do not use HLFIR lowering (deprecated)">;
 
+def flang_experimental_integer_overflow : Flag<["-"], 
"flang-experimental-integer-overflow">,
+  Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Add nsw flag to internal operations such as do-variable increment 
(experimental)">;
+
 
//===--===//
 // FLangOption + CoreOption + NoXarchOption
 
//===--===//
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d275528b69051..42ca060186fd8 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -139,6 +139,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
 
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
+options::OPT_flang_experimental_integer_overflow,
 options::OPT_fno_ppc_native_vec_elem_order,
 options::OPT_fppc_native_vec_elem_order});
 }
diff --git a/flang/include/flang/Lower/LoweringOptions.def 
b/flang/include/flang/Lower/LoweringOptions.def
index be080a4d29d73..7594a57a26291 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -34,5 +34,9 @@ ENUM_LOWERINGOPT(NoPPCNativeVecElemOrder, unsigned, 1, 0)
 /// On by default.
 ENUM_LOWERINGOPT(Underscoring, unsigned, 1, 1)
 
+/// If true, add nsw flags to loop variable increments.
+/// Off by default.
+ENUM_LOWERINGOPT(NSWOnLoopVarInc, unsigned, 1, 0)
+
 #undef LOWERINGOPT
 #undef ENUM_LOWERINGOPT
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h 
b/flang/include/flang/Optimizer/Transforms/Passes.h
index ae1d72a3526bf..25fe61488f4f6 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -54,6 +54,7 @@ namespace fir {
 std::unique_ptr createAffineDemotionPass();
 std::unique_ptr
 createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});
+std::unique_ptr createCFGConversionPassWithNSW();
 std::unique_ptr createExternalNameConversionPass();
 std::unique_ptr
 createExternalNameConversionPass(bool appendUnderscore);
@@ -89,7 +90,8 @@ createFunctionAttrPass(FunctionAttrTypes &functionAttr, bool 
noInfsFPMath,
bool noSignedZerosFPMath, bool unsafeFPMath);
 
 void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
-   bool forceLoopToExecuteOnce = false);
+   bool forceLoopToExecuteOnce = false,
+   bool setNSW = fals

[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

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

>From 659cf5b5c1216ab9f6a8dbb63b4f93de41cd173d Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 10:54:12 +0200
Subject: [PATCH 1/2] [clang] CTAD: implement the missing IsDeducible
 constraint for alias templates.

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

- rebase to main
- add release note for __is_deducible
- implement diagnostics for bad argument types for __is_deducible

Don't expose __is_deducible trait.

Refine the implementation of hiding __is_deducible type trait.

Apply approach 3.
---
 clang/include/clang/Basic/TokenKinds.def |  3 +
 clang/include/clang/Sema/Sema.h  |  9 ++
 clang/lib/Basic/TypeTraits.cpp   | 10 +++
 clang/lib/Sema/SemaExprCXX.cpp   | 10 ++-
 clang/lib/Sema/SemaTemplate.cpp  | 82 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 86 
 clang/test/AST/ast-dump-ctad-alias.cpp   | 20 +++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 27 --
 clang/test/SemaTemplate/deduction-guide.cpp  | 16 ++--
 clang/www/cxx_status.html|  4 +-
 10 files changed, 238 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..b5a0e9df9f7ae 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -538,6 +538,9 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary, KEYCXX)
+// IsDeducible is only used internally by clang for CTAD implementation and
+// is not exposed to users.
+TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..66d5e2d4a4ade 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9492,6 +9492,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Basic/TypeTraits.cpp b/clang/lib/Basic/TypeTraits.cpp
index 4dbf678dc395b..8d6794223ccaf 100644
--- a/clang/lib/Basic/TypeTraits.cpp
+++ b/clang/lib/Basic/TypeTraits.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 using namespace clang;
 
 static constexpr const char *TypeTraitNames[] = {
@@ -81,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
 
 const char *clang::getTraitSpelling(TypeTrait T) {
   assert(T <= TT_Last && "invalid enum value!");
+  if (T == BTT_IsDeducible) {
+// The __is_deducible is an internal-only type trait. To hide it from
+// external users, we define it with an empty spelling name, preventing the
+// clang parser from recognizing its token kind.
+// However, other components such as the AST dump still require the real
+// type trait name. Therefore, we return the real name when needed.
+assert(std::strlen(TypeTraitSpellings[T]) == 0);
+return "__is_deducible";
+  }
   return TypeTraitSpellings[T];
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 34e12078a8c92..e4601f7d6c47d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6143,7 +6143,15 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }
-default: llvm_unreachable("not a BTT");
+  case BTT_IsDeducible: {
+const auto *TSTToBeDeduced = cast(LhsT);
+sema::TemplateDeductionInfo Info(KeyLoc);
+return Self.DeduceTemplateArgumentsFromType(
+   TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT,
+   Info) == TemplateDeductionResult::Success;
+  }
+  default:
+llvm_unreachable("not a BTT");
   }
   llvm_unreachable("Unknow

[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

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

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

>From 659cf5b5c1216ab9f6a8dbb63b4f93de41cd173d Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 10:54:12 +0200
Subject: [PATCH 1/2] [clang] CTAD: implement the missing IsDeducible
 constraint for alias templates.

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

- rebase to main
- add release note for __is_deducible
- implement diagnostics for bad argument types for __is_deducible

Don't expose __is_deducible trait.

Refine the implementation of hiding __is_deducible type trait.

Apply approach 3.
---
 clang/include/clang/Basic/TokenKinds.def |  3 +
 clang/include/clang/Sema/Sema.h  |  9 ++
 clang/lib/Basic/TypeTraits.cpp   | 10 +++
 clang/lib/Sema/SemaExprCXX.cpp   | 10 ++-
 clang/lib/Sema/SemaTemplate.cpp  | 82 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 86 
 clang/test/AST/ast-dump-ctad-alias.cpp   | 20 +++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 27 --
 clang/test/SemaTemplate/deduction-guide.cpp  | 16 ++--
 clang/www/cxx_status.html|  4 +-
 10 files changed, 238 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..b5a0e9df9f7ae 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -538,6 +538,9 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary, KEYCXX)
+// IsDeducible is only used internally by clang for CTAD implementation and
+// is not exposed to users.
+TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..66d5e2d4a4ade 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9492,6 +9492,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Basic/TypeTraits.cpp b/clang/lib/Basic/TypeTraits.cpp
index 4dbf678dc395b..8d6794223ccaf 100644
--- a/clang/lib/Basic/TypeTraits.cpp
+++ b/clang/lib/Basic/TypeTraits.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 using namespace clang;
 
 static constexpr const char *TypeTraitNames[] = {
@@ -81,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
 
 const char *clang::getTraitSpelling(TypeTrait T) {
   assert(T <= TT_Last && "invalid enum value!");
+  if (T == BTT_IsDeducible) {
+// The __is_deducible is an internal-only type trait. To hide it from
+// external users, we define it with an empty spelling name, preventing the
+// clang parser from recognizing its token kind.
+// However, other components such as the AST dump still require the real
+// type trait name. Therefore, we return the real name when needed.
+assert(std::strlen(TypeTraitSpellings[T]) == 0);
+return "__is_deducible";
+  }
   return TypeTraitSpellings[T];
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 34e12078a8c92..e4601f7d6c47d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6143,7 +6143,15 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }
-default: llvm_unreachable("not a BTT");
+  case BTT_IsDeducible: {
+const auto *TSTToBeDeduced = cast(LhsT);
+sema::TemplateDeductionInfo Info(KeyLoc);
+return Self.DeduceTemplateArgumentsFromType(
+   TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT,
+   Info) == TemplateDeductionResult::Success;
+  }
+  default:
+llvm_unreachable("not a BTT");
   }
   llvm_unreachable("Unknow

[clang] 1650f1b - Fix typo "indicies" (#92232)

2024-05-15 Thread via cfe-commits

Author: Jay Foad
Date: 2024-05-15T13:10:16+01:00
New Revision: 1650f1b3d7f97ca95eb930984e74bdfd91b02b4e

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

LOG: Fix typo "indicies" (#92232)

Added: 


Modified: 
clang/include/clang/AST/VTTBuilder.h
clang/lib/AST/VTTBuilder.cpp
clang/lib/CodeGen/CGVTT.cpp
clang/lib/CodeGen/CGVTables.h

cross-project-tests/debuginfo-tests/dexter/dex/command/commands/DexExpectStepOrder.py
flang/docs/HighLevelFIR.md
flang/test/Lower/HLFIR/forall.f90
libc/src/stdio/printf_core/parser.h
libcxx/test/std/containers/views/mdspan/CustomTestLayouts.h
llvm/docs/GlobalISel/GenericOpcode.rst
llvm/include/llvm/Target/Target.td
llvm/lib/Analysis/DependenceAnalysis.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/lib/Bitcode/Writer/ValueEnumerator.h
llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
llvm/lib/CodeGen/PrologEpilogInserter.cpp
llvm/lib/Support/ELFAttributeParser.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp
llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.h
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
llvm/lib/Transforms/Utils/SampleProfileInference.cpp
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/CodeGen/X86/avx-vperm2x128.ll
llvm/test/DebugInfo/PDB/Inputs/every-type.yaml
llvm/test/MC/ARM/eh-directive-personalityindex-diagnostics.s
llvm/test/Transforms/InstCombine/phi-extractvalue.ll
llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll
llvm/test/Transforms/VectorCombine/X86/scalarize-vector-gep.ll
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp

Removed: 




diff  --git a/clang/include/clang/AST/VTTBuilder.h 
b/clang/include/clang/AST/VTTBuilder.h
index 4acbc1f9e96b2..3c19e61a8701c 100644
--- a/clang/include/clang/AST/VTTBuilder.h
+++ b/clang/include/clang/AST/VTTBuilder.h
@@ -92,7 +92,7 @@ class VTTBuilder {
   using AddressPointsMapTy = llvm::DenseMap;
 
   /// The sub-VTT indices for the bases of the most derived class.
-  llvm::DenseMap SubVTTIndicies;
+  llvm::DenseMap SubVTTIndices;
 
   /// The secondary virtual pointer indices of all subobjects of
   /// the most derived class.
@@ -148,8 +148,8 @@ class VTTBuilder {
   }
 
   /// Returns a reference to the sub-VTT indices.
-  const llvm::DenseMap &getSubVTTIndicies() const {
-return SubVTTIndicies;
+  const llvm::DenseMap &getSubVTTIndices() const {
+return SubVTTIndices;
   }
 
   /// Returns a reference to the secondary virtual pointer indices.

diff  --git a/clang/lib/AST/VTTBuilder.cpp b/clang/lib/AST/VTTBuilder.cpp
index d58e875177852..464a2014c430a 100644
--- a/clang/lib/AST/VTTBuilder.cpp
+++ b/clang/lib/AST/VTTBuilder.cpp
@@ -189,7 +189,7 @@ void VTTBuilder::LayoutVTT(BaseSubobject Base, bool 
BaseIsVirtual) {
 
   if (!IsPrimaryVTT) {
 // Remember the sub-VTT index.
-SubVTTIndicies[Base] = VTTComponents.size();
+SubVTTIndices[Base] = VTTComponents.size();
   }
 
   uint64_t VTableIndex = VTTVTables.size();

diff  --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index d2376b14dd582..4cebb750c89e8 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -138,23 +138,24 @@ uint64_t CodeGenVTables::getSubVTTIndex(const 
CXXRecordDecl *RD,
 BaseSubobject Base) {
   BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
 
-  SubVTTIndiciesMapTy::iterator I = SubVTTIndicies.find(ClassSubobjectPair);
-  if (I != SubVTTIndicies.end())
+  SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);
+  if (I != SubVTTIndices.end())
 return I->second;
 
   VTTBuilder Builder(CGM.getContext(), RD, /*GenerateDefinition=*/false);
 
-  for (llvm::DenseMap::const_iterator I =
-   Builder.getSubVTTIndicies().begin(),
-   E = Builder.getSubVTTIndicies().end(); I != E; ++I) {
+  for (llvm::DenseMap::const_iterator
+   I = Builder.getSubVTTIndices().begin(),
+   E = Builder.getSubVTTIndices().end();
+   I != E; ++I) {
 // Insert all indices.
 BaseSubobjectPairTy ClassSubobjectPair(RD, I->first);
 
-SubVTTIndicies.insert(std::make_pair(ClassSubobjectPair, I->second));
+SubVTTIndices.insert(std::make_pair(ClassSubobjectPair, I->second));
   }
 
-  I = SubVTTIndicies.find(ClassSubobjectPair);
-  assert(I != SubVTTIndicies.end() && "D

[clang] [flang] [libc] [libcxx] [llvm] [mlir] Fix typo "indicies" (PR #92232)

2024-05-15 Thread Jay Foad via cfe-commits

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

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

AaronBallman wrote:

> > I don't think we should allow it for C++11 and later modes
> 
> To clarify, should we allow enabling them in e.g. `c++03` mode if 
> `-fraw-string-literals` is passed? I don’t see why not, but I’m not entirely 
> sure whether you’re saying we should not support that flag in C++ (neither 
> the positive nor the negative variant) at all or just not in C++11 and later.

I think we should allow users to enable them in C++03 modes if 
`-fraw-string-literals` is passed. I think it's fine to have 
`-fno-raw-string-literals` that allows users to disable them in C++03 mode (in 
case an earlier command line option opted into them and the user wants to 
disable the feature for some reason), but I don't know if that's worth the 
effort to support because I don't think we should allow 
`-fno-raw-string-literals` in C++11 mode.

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

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

AaronBallman wrote:

Btw, it seems that precommit CI found some valid issues to be addressed

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-05-15 Thread via cfe-commits

Sirraide wrote:

> I think we should allow users to enable them in C++03 modes if 
> -fraw-string-literals is passed. I think it's fine to have 
> -fno-raw-string-literals that allows users to disable them in C++03 mode (in 
> case an earlier command line option opted into them and the user wants to 
> disable the feature for some reason), but I don't know if that's worth the 
> effort to support because I don't think we should allow 
> -fno-raw-string-literals in C++11 mode.

In that case I think it might just make sense to ignore the flag in C++11 and 
later then and allow it before C++11.

> Btw, it seems that precommit CI found some valid issues to be addressed

Ah, I didn’t know that all new warnings should have a `-W` flag associated with 
them; it seems I’ve somehow only ever added errors so far. I’ll take a look at 
what happened there.

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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-15 Thread Egor Pasko via cfe-commits

pasko wrote:

@aeubanks Thanks for the first set of comments. I think I addressed them all 
and checked that instrumentation is still WAI in my ThinkLTO example. I did not 
run/update tests yet, this is TBD. Another round of review pre-tests would be 
appreciated.

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


[clang-tools-extra] 3b5a121 - [clang-tidy][NFC] replace comparison of begin and end iterators with range empty (#91994)

2024-05-15 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-05-15T14:35:07+02:00
New Revision: 3b5a121a2478e586f59e3277d04d17fb63be5d76

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

LOG: [clang-tidy][NFC] replace comparison of begin and end iterators with range 
empty (#91994)

Improves readability by changing comparisons of `*_begin` and `*_end`
iterators into `.empty()` on their range.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index ca1ae551cc632..2fca7ae2e7eee 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -171,8 +171,7 @@ void SuspiciousEnumUsageCheck::check(const 
MatchFinder::MatchResult &Result) {
 // Skip when one of the parameters is an empty enum. The
 // hasDisjointValueRange function could not decide the values properly in
 // case of an empty enum.
-if (EnumDec->enumerator_begin() == EnumDec->enumerator_end() ||
-OtherEnumDec->enumerator_begin() == OtherEnumDec->enumerator_end())
+if (EnumDec->enumerators().empty() || OtherEnumDec->enumerators().empty())
   return;
 
 if (!hasDisjointValueRange(EnumDec, OtherEnumDec))

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
index 00dfa17a1ccf6..5dee7f91a9341 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
@@ -67,8 +67,7 @@ static std::string createReplacementText(const LambdaExpr 
*Lambda) {
   AppendName("this");
 }
   }
-  if (!Replacement.empty() &&
-  Lambda->explicit_capture_begin() != Lambda->explicit_capture_end()) {
+  if (!Replacement.empty() && !Lambda->explicit_captures().empty()) {
 // Add back separator if we are adding explicit capture variables.
 Stream << ", ";
   }

diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
index 3f1d2f9f58099..c2d9286312dc4 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -192,9 +192,7 @@ void UnusedParametersCheck::check(const 
MatchFinder::MatchResult &Result) {
 
 // In non-strict mode ignore function definitions with empty bodies
 // (constructor initializer counts for non-empty body).
-if (StrictMode ||
-(Function->getBody()->child_begin() !=
- Function->getBody()->child_end()) ||
+if (StrictMode || !Function->getBody()->children().empty() ||
 (isa(Function) &&
  cast(Function)->getNumCtorInitializers() > 0))
   warnOnUnusedParameter(Result, Function, I);

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
index 6d7d1d6b87c60..1585925ee9967 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
@@ -254,7 +254,7 @@ findInsertionForConstraint(const FunctionDecl *Function, 
ASTContext &Context) {
 return utils::lexer::findPreviousTokenKind(Init->getSourceLocation(),
SM, LangOpts, tok::colon);
 }
-if (Constructor->init_begin() != Constructor->init_end())
+if (!Constructor->inits().empty())
   return std::nullopt;
   }
   if (Function->isDeleted()) {



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


[clang-tools-extra] [clang-tidy][NFC] replace comparison of begin and end iterators with range empty (PR #91994)

2024-05-15 Thread Julian Schmidt via cfe-commits

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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +529,324 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  static const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType GetSingleElementType(QualType Ty) const;
+  bool IsLikeComplexType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::GetSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = GetSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // For compatibility with GCC, ignore empty bitfields in C++ mode.
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = GetSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+// An 8-byte aligned struct s { float f; } is passed as a double.

uweigand wrote:

Well, is it *true* in your ABI that trailing padding is allowed here?  If not, 
then the code to reject it needs to be added back as isSingleElementStruct does 
...

https://github.com/llvm/llvm-project/pull/91384
___
cfe-commits mailing list
cfe-co

[clang] [llvm] [DebugInfo] Use DW_op_bit_piece for structured bindings of bitfields (PR #85665)

2024-05-15 Thread John Brawn via cfe-commits


@@ -6178,10 +6178,16 @@ The current supported opcode vocabulary is limited:
   the last entry from the second last entry and appends the result to the
   expression stack.
 - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
-- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and 
``8``
-  here, respectively) of the variable fragment from the working expression. 
Note
-  that contrary to DW_OP_bit_piece, the offset is describing the location
-  within the described source variable.
+- ``DW_OP_LLVM_fragment, 16, 8`` specifies that the top of the expression stack
+  is a fragment of the source language variable with the given offset and size
+  (``16`` and ``8`` here, respectively). Note that the offset and size are the
+  opposite way around to ``DW_OP_bit_piece``, and the offset is within the
+  source language variable.
+- ``DW_OP_bit_piece, 8, 16`` specifies that the source language variable can be
+  found in the sequence of bits at the given size and offset (``8`` and ``16``
+  here, respectively) within the top of the expression stack. Note that the
+  offset and size are the opposite way around to ``DW_OP_LLVM_fragment``, and 
the
+  offset is within the LLVM variable (if that's at the top of the stack).

john-brawn-arm wrote:

DW_OP_bit_piece is like every other standard dwarf expression: if we see a new 
location for a variable then the variable is now at that location. The current 
behaviour for DIExpression::fragmentsOverlap() is that it returns true when the 
expression isn't a fragment, and that's what we want for DW_OP_bit_piece.

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-15 Thread via cfe-commits


@@ -206,14 +210,37 @@ static void lowerAwaitSuspend(IRBuilder<> &Builder, 
CoroAwaitSuspendInst *CB) {
 llvm_unreachable("Unexpected coro_await_suspend invocation method");
   }
 
+  if (CB->getCalledFunction()->getIntrinsicID() ==
+  Intrinsic::coro_await_suspend_handle) {
+// Follow the await_suspend by a lowered resume call to the returned
+// coroutine.
+if (auto *Invoke = dyn_cast(CB))
+  Builder.SetInsertPoint(Invoke->getNormalDest()->getFirstInsertionPt());

zmodem wrote:

Yes, I will update the comment.

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


[clang] [llvm] [Clang][OpenMP] Fix runtime problem when explicit map both pointer and pointee (PR #92210)

2024-05-15 Thread Shilei Tian via cfe-commits

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


[clang-tools-extra] [clang-tidy] fix crash due to assumed callee in min-max-use-initializer-list (PR #91992)

2024-05-15 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] 932f0de - [clang-tidy] fix crash due to assumed callee in min-max-use-initializer-list (#91992)

2024-05-15 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-05-15T14:52:32+02:00
New Revision: 932f0de43a9e334e161a69a50bd6b01cd51e238e

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

LOG: [clang-tidy] fix crash due to assumed callee in 
min-max-use-initializer-list (#91992)

Previously, the call to `findArgs` for a `CallExpr` inside of a `min` or
`max` call would call `findArgs` before checking if the argument is a
call to `min` or `max`, which is what `findArgs` is expecting.
The fix moves the name checking before the call to `findArgs`, such that
only a `min` or `max` function call is used as an argument.

Fixes #91982 
Fixes #92249

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
index 45f7700463d57..418699ffbc4d1 100644
--- a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
@@ -129,17 +129,17 @@ generateReplacements(const MatchFinder::MatchResult 
&Match,
   continue;
 }
 
+// if the nested call is not the same as the top call
+if (InnerCall->getDirectCallee()->getQualifiedNameAsString() !=
+TopCall->getDirectCallee()->getQualifiedNameAsString())
+  continue;
+
 const FindArgsResult InnerResult = findArgs(InnerCall);
 
 // if the nested call doesn't have arguments skip it
 if (!InnerResult.First || !InnerResult.Last)
   continue;
 
-// if the nested call is not the same as the top call
-if (InnerCall->getDirectCallee()->getQualifiedNameAsString() !=
-TopCall->getDirectCallee()->getQualifiedNameAsString())
-  continue;
-
 // if the nested call doesn't have the same compare function
 if ((Result.Compare || InnerResult.Compare) &&
 !utils::areStatementsIdentical(Result.Compare, InnerResult.Compare,

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp
index 51ab9bda975f1..1f2dad2b933ca 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp
@@ -300,6 +300,27 @@ B maxTT2 = std::max(B(), std::max(B(), B()));
 B maxTT3 = std::max(B(), std::max(B(), B()), [](const B &lhs, const B &rhs) { 
return lhs.a[0] < rhs.a[0]; });
 // CHECK-FIXES: B maxTT3 = std::max(B(), std::max(B(), B()), [](const B &lhs, 
const B &rhs) { return lhs.a[0] < rhs.a[0]; });
 
+struct GH91982 {
+  int fun0Args();
+  int fun1Arg(int a);
+  int fun2Args(int a, int b);
+  int fun3Args(int a, int b, int c);
+  int fun4Args(int a, int b, int c, int d);
+
+  int foo() {
+return std::max(
+fun0Args(),
+std::max(fun1Arg(0),
+ std::max(fun2Args(0, 1),
+  std::max(fun3Args(0, 1, 2), fun4Args(0, 1, 2, 3);
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: do not use nested 'std::max' 
calls, use an initializer list instead [modernize-min-max-use-initializer-list]
+// CHECK-FIXES: return std::max(
+// CHECK-FIXES-NEXT: {fun0Args(),
+// CHECK-FIXES-NEXT: fun1Arg(0),
+// CHECK-FIXES-NEXT: fun2Args(0, 1),
+// CHECK-FIXES-NEXT: fun3Args(0, 1, 2), fun4Args(0, 1, 2, 3)});
+  }
+};
 
 } // namespace
 



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


[clang-tools-extra] [clang-tidy] fix crash due to assumed callee in min-max-use-initializer-list (PR #91992)

2024-05-15 Thread Julian Schmidt via cfe-commits

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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -0,0 +1,137 @@
+// RUN: %clang_cc1 -triple s390x-ibm-zos \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-feature +vector \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-cpu z13 \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-cpu arch11 \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-cpu z14 \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-cpu arch12 \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-cpu z15 \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -target-cpu arch13 \
+// RUN:   -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck %s
+
+// Scalar types
+
+char pass_char(char arg) { return arg; }
+// CHECK-LABEL: define signext i8 @pass_char(i8 signext %{{.*}})
+
+short pass_short(short arg) { return arg; }
+// CHECK-LABEL: define signext i16 @pass_short(i16 signext %{{.*}})
+
+int pass_int(int arg) { return arg; }
+// CHECK-LABEL: define signext i32 @pass_int(i32 signext %{{.*}})
+
+long pass_long(long arg) { return arg; }
+// CHECK-LABEL: define i64 @pass_long(i64 %{{.*}})
+
+long long pass_longlong(long long arg) { return arg; }
+// CHECK-LABEL: define i64 @pass_longlong(i64 %{{.*}})
+
+float pass_float(float arg) { return arg; }
+// CHECK-LABEL: define float @pass_float(float %{{.*}})
+
+double pass_double(double arg) { return arg; }
+// CHECK-LABEL: define double @pass_double(double %{{.*}})
+
+long double pass_longdouble(long double arg) { return arg; }
+// CHECK-LABEL: define fp128 @pass_longdouble(fp128 %{{.*}})
+
+enum Color { Red, Blue };
+enum Color pass_enum(enum Color arg) { return arg; }
+// CHECK-LABEL: define zeroext i32 @pass_enum(i32 zeroext %{{.*}})
+
+// Complex types
+
+// TODO: Add tests for complex integer types
+
+_Complex float pass_complex_float(_Complex float arg) { return arg; }
+// CHECK-LABEL: define { float, float } @pass_complex_float(float %{{.*}}, 
float %{{.*}})
+
+_Complex double pass_complex_double(_Complex double arg) { return arg; }
+// CHECK-LABEL: define { double, double } @pass_complex_double(double %{{.*}}, 
double %{{.*}})
+
+_Complex long double pass_complex_longdouble(_Complex long double arg) { 
return arg; }
+// CHECK-LABEL: define { fp128, fp128 } @pass_complex_longdouble(fp128 
%{{.*}}, fp128 %{{.*}})
+
+// Verify that the following are complex-like types
+struct complexlike_float { float re, im; };
+struct complexlike_float pass_complexlike_float(struct complexlike_float arg) 
{ return arg; }
+// CHECK-LABEL: define %struct.complexlike_float @pass_complexlike_float(float 
%{{.*}}, float %{{.*}})
+
+struct complexlike_double { double re, im; };
+struct complexlike_double pass_complexlike_double(struct complexlike_double 
arg) { return arg; }
+// CHECK-LABEL: define %struct.complexlike_double 
@pass_complexlike_double(double %{{.*}}, double %{{.*}})
+
+struct complexlike_longdouble { long double re, im; };
+struct complexlike_longdouble pass_complexlike_longdouble(struct 
complexlike_longdouble arg) { return arg; }
+// CHECK-LABEL: define %struct.complexlike_longdouble 
@pass_complexlike_longdouble(fp128 %{{.*}}, fp128 %{{.*}})
+
+// Aggregate types
+

uweigand wrote:

As to single-element struct, I'm refering to all the various special cases the 
code checks for.  They should have tests that verify the intended behaviour.  
(And those tests should also be verified against the actual behavior of the 
legacy compilers.)  In particular, does it count as single-element struct if:
- we have any padding
- we have a single element that is itself a single-element struct
- we have a single element that is a single-element array
- we have an element that is a bitfield of size zero (named or unnamed)
- we have an element that is a bitfield of nonzero size
- we have an element that is an empty struct
- we have an element that is an empty array
- it's a C++ class that has a C++20 empty data member (NoUniqueAddressAttr)
- it's a C++ class that has an empty base class
- it's a C++ class that has a non-empty base class


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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-05-15 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,401 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isCompoundType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  unsigned getMaxAlignFromTypeDefs(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy,
+unsigned functionCallConv) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg,
+  unsigned functionCallConv) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() =
+  classifyReturnType(FI.getReturnType(), FI.getCallingConvention());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info =
+  classifyArgumentType(I.type, IsNamedArg, FI.getCallingConvention());
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isCompoundType(QualType Ty) const {
+  return (Ty->isAnyComplexType() || Ty->isVectorType() ||
+  isAggregateTypeForABI(Ty));
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  for (const auto &I : CXXRD->bases()) {
+QualType Base = I.getType();
+
+// Empty bases don't affect things either way.
+if (isEmptyRecord(getContext(), Base, true))
+  continue;
+
+if (!Found.isNull())
+  return Ty;
+Found = getSingleElementType(Base);
+  }
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  // Unlike isSingleElementStruct(), empty structure and array fields
+  // do count.  So do anonymous bitfields that aren't zero-sized.
+  if (getContext().getLangOpts().CPlusPlus &&
+  FD->isZeroLengthBitField(getContext()))
+continue;
+
+  // Unlike isSingleElementStruct(), arrays do not count.
+  // Nested structures still do though.
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(FD->getType());
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+unsigned ZOSXPLinkABIInfo::getMaxAlignFr

  1   2   3   4   5   >