[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits

yamt wrote:

> Given that we don't need `setjmpTableSize` anymore and `setjmpTable` doesn't 
> change, we don't need the whole block here from line 1463 ~ line 1503 doing 
> SSA updates anymore:

i get errors like the following if i simply put the SSA update things in 
`!EnableWasmAltSjLj` block.
i need to investigate.
```
spacetanuki% /Volumes/PortableSSD/llvm/build/bin/clang --sysroot 
/opt/wasi-sdk-21.0/share/wasi-sysroot -resource-dir 
/Volumes/PortableSSD/llvm/llvm/lib/clang/17 --target=wasm32-wasi -Os -c -mllvm 
-wasm-enable-sjlj -mllvm -experimental-wasm-enable-alt-sjlj a.c  
Instruction does not dominate all uses!
  %val = load i32, ptr %val_gep, align 4
  %setjmp.ret = phi i32 [ 0, %entry.split ], [ %val, %setjmp.dispatch ]
in function f
fatal error: error in backend: Broken function found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /Volumes/PortableSSD/llvm/build/bin/clang --sysroot 
/opt/wasi-sdk-21.0/share/wasi-sysroot -resource-dir 
/Volumes/PortableSSD/llvm/llvm/lib/clang/17 --target=wasm32-wasi -Os -c -mllvm 
-wasm-enable-sjlj -mllvm -experimental-wasm-enable-alt-sjlj a.c
1.   parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module 'a.c'.
4.  Running pass 'Module Verifier' on function '@f'
```

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-10 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/83149

>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH 1/3] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
+   TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
+   TypenameMacros == R.TypenameMacros && 

[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-10 Thread Wang Pengcheng via cfe-commits

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

>From 8dc42f5c90ba369a145868f8c1a9a8cb3e988cb0 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/docs/ReleaseNotes.rst|   1 +
 clang/test/Driver/riscv-profiles.c | 312 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  65 ++
 3 files changed, 378 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bce27dc8c4a996..a072bf4a5ff4b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option is now supported.
 
 CUDA/HIP Language Changes
 ^
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..904f0c371f4442
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,312 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S64: "-target-feature" "+ziccrse"
+// RVA22S64: "-target-feature" "+zicntr"

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-10 Thread Hirofumi Nakamura via cfe-commits

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-10 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/83149

>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH 1/2] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
+   TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
+   TypenameMacros == R.TypenameMacros && 

[clang] 3f6bc1a - [C++20] [Moduls] Avoid computing odr hash for functions from comparing constraint expression

2024-03-10 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-03-11T11:39:21+08:00
New Revision: 3f6bc1adf805681293c2ef0b93b708ff52244c00

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

LOG: [C++20] [Moduls] Avoid computing odr hash for functions from comparing 
constraint expression

Previously we disabled to compute ODR hash for declarations from the
global module fragment. However, we missed the case that the functions
lives in the concept requiments (see the attached the test files for
example). And the mismatch causes the potential crashment.

Due to we will set the function body as lazy after we deserialize it and
we will only take its body when needed. However, we don't allow to take
the body during deserializing. So it is actually potentially problematic
if we set the body as lazy first and computing the hash value of the
function, which requires to deserialize its body. So we will meet a
crash here.

This patch tries to solve the issue by not taking the body of the
function from GMF. Note that we can't skip comparing the constraint
expression from the GMF directly since it is an key part of the
function selecting and it may be the reason why we can't return 0
directly for `FunctionDecl::getODRHash()` from the GMF.

Added: 
clang/test/Modules/hashing-decls-in-exprs-from-gmf.cppm

Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 76810a86a78a46..47ed6d0d1db0df 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -673,6 +673,16 @@ class alignas(8) Decl {
   /// fragment. See [module.global.frag]p3,4 for details.
   bool isDiscardedInGlobalModuleFragment() const { return false; }
 
+  /// Check if we should skip checking ODRHash for declaration \param D.
+  ///
+  /// The existing ODRHash mechanism seems to be not stable enough and
+  /// the false positive ODR violation reports are annoying and we rarely see
+  /// true ODR violation reports. Also we learned that MSVC disabled ODR checks
+  /// for declarations in GMF. So we try to disable ODR checks in the GMF to
+  /// get better user experiences before we make the ODR violation checks 
stable
+  /// enough.
+  bool shouldSkipCheckingODR() const;
+
   /// Return true if this declaration has an attribute which acts as
   /// definition of the entity, such as 'alias' or 'ifunc'.
   bool hasDefiningAttr() const;

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 2002bf23c9595f..370d8037a4da17 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2456,13 +2456,6 @@ class BitsUnpacker {
   uint32_t Value;
   uint32_t CurrentBitsIndex = ~0;
 };
-
-inline bool shouldSkipCheckingODR(const Decl *D) {
-  return D->getOwningModule() &&
- D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
- D->getOwningModule()->isExplicitGlobalModule();
-}
-
 } // namespace clang
 
 #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d681791d3920c3..8626f04012f7d4 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4496,7 +4496,7 @@ unsigned FunctionDecl::getODRHash() {
   }
 
   class ODRHash Hash;
-  Hash.AddFunctionDecl(this);
+  Hash.AddFunctionDecl(this, /*SkipBody=*/shouldSkipCheckingODR());
   setHasODRHash(true);
   ODRHash = Hash.CalculateHash();
   return ODRHash;

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index fcedb3cfd176a0..04bbc49ab2f319 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1102,6 +1102,11 @@ bool Decl::isInAnotherModuleUnit() const {
   return M != getASTContext().getCurrentNamedModule();
 }
 
+bool Decl::shouldSkipCheckingODR() const {
+  return getASTContext().getLangOpts().SkipODRCheckInGMF && getOwningModule() 
&&
+ getOwningModule()->isExplicitGlobalModule();
+}
+
 static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
 static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 683a076e6bc399..ede9f6e93469b7 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9762,7 +9762,7 @@ void ASTReader::finishPendingActions() {
 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread via cfe-commits

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


[clang] 7dfa839 - [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (#77092)

2024-03-10 Thread via cfe-commits

Author: Amirreza Ashouri
Date: 2024-03-11T04:23:23+01:00
New Revision: 7dfa8398354e435cdee5a8ea6d6b17d1e4557733

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

LOG: [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (#77092)

Consistent with `__is_trivially_copyable(volatile int) == true` and
`__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified
type)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/Type.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..bce27dc8c4a996 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -251,6 +251,9 @@ Bug Fixes in This Version
   for logical operators in C23.
   Fixes (#GH64356).
 
+- ``__is_trivially_relocatable`` no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (#GH77091).
+
 - Clang no longer produces a false-positive `-Wunused-variable` warning
   for variables created through copy initialization having side-effects in 
C++17 and later.
   Fixes (#GH64356) (#GH79518).

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index f50f51cc70982e..14ec17989ec7c7 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1722,91 +1722,91 @@ struct StructWithAnonUnion3 {
 
 void is_layout_compatible(int n)
 {
-  static_assert(__is_layout_compatible(void, void), "");
-  static_assert(!__is_layout_compatible(void, int), "");
-  static_assert(__is_layout_compatible(void, const void), "");
-  static_assert(__is_layout_compatible(void, volatile void), "");
-  static_assert(__is_layout_compatible(const int, volatile int), "");
-  static_assert(__is_layout_compatible(int, int), "");
-  static_assert(__is_layout_compatible(int, const int), "");
-  static_assert(__is_layout_compatible(int, volatile int), "");
-  static_assert(__is_layout_compatible(const int, volatile int), "");
-  static_assert(__is_layout_compatible(int *, int * __restrict), "");
+  static_assert(__is_layout_compatible(void, void));
+  static_assert(!__is_layout_compatible(void, int));
+  static_assert(__is_layout_compatible(void, const void));
+  static_assert(__is_layout_compatible(void, volatile void));
+  static_assert(__is_layout_compatible(const int, volatile int));
+  static_assert(__is_layout_compatible(int, int));
+  static_assert(__is_layout_compatible(int, const int));
+  static_assert(__is_layout_compatible(int, volatile int));
+  static_assert(__is_layout_compatible(const int, volatile int));
+  static_assert(__is_layout_compatible(int *, int * __restrict));
   // Note: atomic qualification matters for layout compatibility.
-  static_assert(!__is_layout_compatible(int, _Atomic int), "");
-  static_assert(__is_layout_compatible(_Atomic(int), _Atomic int), "");
-  static_assert(!__is_layout_compatible(int, unsigned int), "");
-  static_assert(!__is_layout_compatible(char, unsigned char), "");
-  static_assert(!__is_layout_compatible(char, signed char), "");
-  static_assert(!__is_layout_compatible(unsigned char, signed char), "");
-  static_assert(__is_layout_compatible(int[], int[]), "");
-  static_assert(__is_layout_compatible(int[2], int[2]), "");
-  static_assert(!__is_layout_compatible(int[n], int[2]), ""); // FIXME: VLAs 
should be rejected
-  static_assert(!__is_layout_compatible(int[n], int[n]), ""); // FIXME: VLAs 
should be rejected
-  static_assert(__is_layout_compatible(int&, int&), "");
-  static_assert(!__is_layout_compatible(int&, char&), "");
-  static_assert(__is_layout_compatible(void(int), void(int)), "");
-  static_assert(!__is_layout_compatible(void(int), void(char)), "");
-  static_assert(__is_layout_compatible(void(&)(int), void(&)(int)), "");
-  static_assert(!__is_layout_compatible(void(&)(int), void(&)(char)), "");
-  static_assert(__is_layout_compatible(void(*)(int), void(*)(int)), "");
-  static_assert(!__is_layout_compatible(void(*)(int), void(*)(char)), "");

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread via cfe-commits

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


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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits

yamt wrote:

> @yamt, do you want to submit a PR to emscripten adding new library functions? 
> I can do that too, but given that this is your code, if you want to do it 
> it'd be good. About where to add them... to make the transition smooth, 
> https://github.com/emscripten-core/emscripten/blob/main/system/lib/compiler-rt/emscripten_setjmp.c
>  looks like a good place to start given that our current functions are here, 
> but we can move them later to elsewhere. WDYT? @sbc100

https://github.com/emscripten-core/emscripten/pull/21502

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


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-03-10 Thread Chuanqi Xu via cfe-commits

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


[clang] f786881 - [coroutine] Implement llvm.coro.await.suspend intrinsic (#79712)

2024-03-10 Thread via cfe-commits

Author: fpasserby
Date: 2024-03-11T10:00:00+08:00
New Revision: f78688134026686288a8d310b493d9327753a022

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

LOG: [coroutine] Implement llvm.coro.await.suspend intrinsic (#79712)

Implement `llvm.coro.await.suspend` intrinsics, to deal with performance
regression after prohibiting `.await_suspend` inlining, as suggested in
#64945.
Actually, there are three new intrinsics, which directly correspond to
each of three forms of `await_suspend`:
```
void llvm.coro.await.suspend.void(ptr %awaiter, ptr %frame, ptr 
@wrapperFunction)
i1 llvm.coro.await.suspend.bool(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
ptr llvm.coro.await.suspend.handle(ptr %awaiter, ptr %frame, ptr 
@wrapperFunction)
```
There are three different versions instead of one, because in `bool`
case it's result is used for resuming via a branch, and in
`coroutine_handle` case exceptions from `await_suspend` are handled in
the coroutine, and exceptions from the subsequent `.resume()` are
propagated to the caller.

Await-suspend block is simplified down to intrinsic calls only, for
example for symmetric transfer:
```
%id = call token @llvm.coro.save(ptr null)
%handle = call ptr @llvm.coro.await.suspend.handle(ptr %awaiter, ptr %frame, 
ptr @wrapperFunction)
call void @llvm.coro.resume(%handle)
%result = call i8 @llvm.coro.suspend(token %id, i1 false)
switch i8 %result, ...
```
All await-suspend logic is moved out into a wrapper function, generated
for each suspension point.
The signature of the function is ` wrapperFunction(ptr %awaiter,
ptr %frame)` where `` is one of `void` `i1` or `ptr`, depending on
the return type of `await_suspend`.
Intrinsic calls are lowered during `CoroSplit` pass, right after the
split.

Because I'm new to LLVM, I'm not sure if the helper function generation,
calls to them and lowering are implemented in the right way, especially
with regard to various metadata and attributes, i. e. for TBAA. All
things that seemed questionable are marked with `FIXME` comments.

There is another detail: in case of symmetric transfer raw pointer to
the frame of coroutine, that should be resumed, is returned from the
helper function and a direct call to `@llvm.coro.resume` is generated.
C++ standard demands, that `.resume()` method is evaluated. Not sure how
important is this, because code has been generated in the same way
before, sans helper function.

Added: 
llvm/test/Transforms/Coroutines/coro-await-suspend-lower-invoke.ll
llvm/test/Transforms/Coroutines/coro-await-suspend-lower.ll

Modified: 
clang/include/clang/AST/ExprCXX.h
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaCoroutine.cpp
clang/test/AST/coroutine-locals-cleanup.cpp
clang/test/CodeGenCoroutines/coro-always-inline.cpp
clang/test/CodeGenCoroutines/coro-await.cpp
clang/test/CodeGenCoroutines/coro-dwarf.cpp
clang/test/CodeGenCoroutines/coro-function-try-block.cpp
clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
clang/test/CodeGenCoroutines/coro-symmetric-transfer-02.cpp
clang/test/CodeGenCoroutines/pr56329.cpp
clang/test/CodeGenCoroutines/pr59181.cpp
clang/test/CodeGenCoroutines/pr65054.cpp
llvm/docs/Coroutines.rst
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Coroutines/CoroInstr.h
llvm/lib/Transforms/Coroutines/CoroInternal.h
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/lib/Transforms/Coroutines/Coroutines.cpp

Removed: 
clang/test/CodeGenCoroutines/coro-awaiter-noinline-suspend.cpp



diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index a0e467b35778c5..6003b866c9f564 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5038,6 +5038,9 @@ class CoroutineSuspendExpr : public Expr {
   OpaqueValueExpr *OpaqueValue = nullptr;
 
 public:
+  // These types correspond to the three C++ 'await_suspend' return variants
+  enum class SuspendReturnType { SuspendVoid, SuspendBool, SuspendHandle };
+
   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand,
Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume,
OpaqueValueExpr *OpaqueValue)
@@ -5097,6 +5100,24 @@ class CoroutineSuspendExpr : public Expr {
 return static_cast(SubExprs[SubExpr::Operand]);
   }
 
+  SuspendReturnType getSuspendReturnType() const {
+auto *SuspendExpr = getSuspendExpr();
+assert(SuspendExpr);
+
+auto SuspendType = SuspendExpr->getType();
+
+if (SuspendType->isVoidType())
+  return SuspendReturnType::SuspendVoid;
+if (SuspendType->isBooleanType())
+  return 

[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-03-10 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I'll merge this since I find you may not have commit access.

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


[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-10 Thread Diego A. Estrada Rivera via cfe-commits

diego-est wrote:

I added the appropriate functions and moved the class members into private. 
Additionally I ran `make check-all` to make sure the now-private members 
wouldn't cause any issues with the rest of the codebase, all the checks passed.

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


[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-10 Thread Diego A. Estrada Rivera via cfe-commits

https://github.com/diego-est updated 
https://github.com/llvm/llvm-project/pull/84638

>From 114e22388508cd1ef5174bdda041564691b58032 Mon Sep 17 00:00:00 2001
From: Sunglas 
Date: Sat, 9 Mar 2024 12:23:43 -0400
Subject: [PATCH 1/2] [analyzer] Turn NodeBuilderContext into a class

---
 .../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 8e392421fef9bb..24d4afc551355e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -59,7 +59,7 @@ class CoreEngine {
   friend class ExprEngine;
   friend class IndirectGotoNodeBuilder;
   friend class NodeBuilder;
-  friend struct NodeBuilderContext;
+  friend class NodeBuilderContext;
   friend class SwitchNodeBuilder;
 
 public:
@@ -194,7 +194,8 @@ class CoreEngine {
 };
 
 // TODO: Turn into a class.
-struct NodeBuilderContext {
+class NodeBuilderContext {
+public:
   const CoreEngine 
   const CFGBlock *Block;
   const LocationContext *LC;

>From a87c924670e00e293ea31d5230c6131509ce26b1 Mon Sep 17 00:00:00 2001
From: Sunglas 
Date: Sun, 10 Mar 2024 21:24:23 -0400
Subject: [PATCH 2/2] fix(NodeBuilderContext implementation): changed class
 members to private and added the appropriate getters.

Moved every member in NodeBuilderContext to private and added the following 
getters:
- getEngine
- getLocationContext

Setters are not necessary since the class members are const already.
---
 .../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h  | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 24d4afc551355e..0705affa4117d9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -195,11 +195,11 @@ class CoreEngine {
 
 // TODO: Turn into a class.
 class NodeBuilderContext {
-public:
   const CoreEngine 
   const CFGBlock *Block;
   const LocationContext *LC;
 
+public:
   NodeBuilderContext(const CoreEngine , const CFGBlock *B,
  const LocationContext *L)
   : Eng(E), Block(B), LC(L) {
@@ -209,9 +209,15 @@ class NodeBuilderContext {
   NodeBuilderContext(const CoreEngine , const CFGBlock *B, ExplodedNode *N)
   : NodeBuilderContext(E, B, N->getLocationContext()) {}
 
+  /// Return the CoreEngine associated with this builder.
+  const CoreEngine () const { return Eng; }
+
   /// Return the CFGBlock associated with this builder.
   const CFGBlock *getBlock() const { return Block; }
 
+  /// Return the location context associated with this builder.
+  const LocationContext *getLocationContext() const { return LC; }
+
   /// Returns the number of times the current basic block has been
   /// visited on the exploded graph path.
   unsigned blockCount() const {

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


[clang] [C++20][Coroutines] lambda-coroutine with promise_type ctor. (PR #84519)

2024-03-10 Thread Chuanqi Xu via cfe-commits

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

LGTM.

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-10 Thread Takuto Ikuta via cfe-commits

atetubou wrote:

@ZequanWu could you take a look this?

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


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-03-10 Thread Chuanqi Xu via cfe-commits

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

LGTM then. Thanks.

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits

yamt wrote:

> > In terms of getting this landed and tested, I wonder which path we should 
> > take:
> > 
> > 1. Land this now, without tests, then update emscripten then come back and 
> > flip the default, at which point the existing tests will get updated.
> > 2. Duplicate/update the the existing tests to tests both modes, then delete 
> > those changes once we flip the default.
> > 
> > Personally I think I'd be happy with (1) since this is a behind and 
> > experimental flag.
> > What do others think? @aheejin ?
> 
> Come to think of it, should we even introduce this experimental option? 
> Adding `if (NewOption) ... else ...` everywhere makes the code complicated. 
> Can we just do
> 
> 1. Add library functions in emscripten
> 
> 2. Replace the current logic in LLVM with new code. (Without 
> `if`~`else`). Tests can be updated with this.
> 
> 3. Remove old library functions in emscripten.
>?

i implemented this way (`if-else`) becasue @sbc100 told me it's necessary for 
emscripten to support both methods for a short period.


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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits


@@ -1738,10 +1792,16 @@ void 
WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
   BasicBlock *ThenBB = BasicBlock::Create(C, "if.then", );
   BasicBlock *EndBB = BasicBlock::Create(C, "if.end", );
   Value *EnvP = IRB.CreateBitCast(Env, getAddrPtrType(), "env.p");
-  Value *SetjmpID = IRB.CreateLoad(getAddrIntType(), EnvP, "setjmp.id");
-  Value *Label =
-  IRB.CreateCall(TestSetjmpF, {SetjmpID, SetjmpTable, SetjmpTableSize},
- OperandBundleDef("funclet", CatchPad), "label");
+  Value *Label;
+  if (EnableWasmAltSjLj) {
+Label = IRB.CreateCall(TestSetjmpF, {EnvP, SetjmpTable},
+   OperandBundleDef("funclet", CatchPad), "label");
+  } else {

yamt wrote:

`SetjmpTableInsts` still has a single item, which is used to pass 
function_invocation_id.

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits


@@ -999,25 +1017,43 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module ) {
   // Register __wasm_longjmp function, which calls __builtin_wasm_longjmp.
   FunctionType *FTy = FunctionType::get(
   IRB.getVoidTy(), {Int8PtrTy, IRB.getInt32Ty()}, false);
-  WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_longjmp", );
+  if (EnableWasmAltSjLj) {
+WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_sjlj_longjmp", );

yamt wrote:

i wanted to have a common prefix for this set of api. (`__wasm_sjlj_`)

what's your suggestion for `testSetjmp`?
```
saveSetjmp -> __wasm_setjmp?
testSetjmp -> ???
getTempRet0-> (removed)
__wasm_longjmp -> keep it
```


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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits


@@ -1291,19 +1327,29 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function ) {
   Type *IntPtrTy = getAddrIntType();
   Constant *size = ConstantInt::get(IntPtrTy, 40);
   IRB.SetInsertPoint(SetjmpTableSize);
-  auto *SetjmpTable = IRB.CreateMalloc(IntPtrTy, IRB.getInt32Ty(), size,
-   nullptr, nullptr, "setjmpTable");
-  SetjmpTable->setDebugLoc(FirstDL);
-  // CallInst::CreateMalloc may return a bitcast instruction if the result 
types
-  // mismatch. We need to set the debug loc for the original call too.
-  auto *MallocCall = SetjmpTable->stripPointerCasts();
-  if (auto *MallocCallI = dyn_cast(MallocCall)) {
-MallocCallI->setDebugLoc(FirstDL);
+  Instruction *SetjmpTable;

yamt wrote:

at least in some places (eg `handleLongjmpableCallsForWasmSjLj`) it was easier 
to share a variable.

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-03-10 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Gentle ping~

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits


@@ -1291,19 +1327,29 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function ) {
   Type *IntPtrTy = getAddrIntType();
   Constant *size = ConstantInt::get(IntPtrTy, 40);
   IRB.SetInsertPoint(SetjmpTableSize);
-  auto *SetjmpTable = IRB.CreateMalloc(IntPtrTy, IRB.getInt32Ty(), size,
-   nullptr, nullptr, "setjmpTable");
-  SetjmpTable->setDebugLoc(FirstDL);
-  // CallInst::CreateMalloc may return a bitcast instruction if the result 
types
-  // mismatch. We need to set the debug loc for the original call too.
-  auto *MallocCall = SetjmpTable->stripPointerCasts();
-  if (auto *MallocCallI = dyn_cast(MallocCall)) {
-MallocCallI->setDebugLoc(FirstDL);
+  Instruction *SetjmpTable;
+  if (EnableWasmAltSjLj) {
+// This alloca'ed pointer is used by the runtime to identify function
+// inovactions. It's just for pointer comparisons. It will never
+// be dereferenced.
+SetjmpTable = IRB.CreateAlloca(IRB.getInt32Ty());
+SetjmpTable->setDebugLoc(FirstDL);
+SetjmpTableInsts.push_back(SetjmpTable);
+  } else {

yamt wrote:

ok

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-10 Thread YAMAMOTO Takashi via cfe-commits


@@ -1291,19 +1327,29 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function ) {
   Type *IntPtrTy = getAddrIntType();
   Constant *size = ConstantInt::get(IntPtrTy, 40);
   IRB.SetInsertPoint(SetjmpTableSize);
-  auto *SetjmpTable = IRB.CreateMalloc(IntPtrTy, IRB.getInt32Ty(), size,
-   nullptr, nullptr, "setjmpTable");
-  SetjmpTable->setDebugLoc(FirstDL);
-  // CallInst::CreateMalloc may return a bitcast instruction if the result 
types
-  // mismatch. We need to set the debug loc for the original call too.
-  auto *MallocCall = SetjmpTable->stripPointerCasts();
-  if (auto *MallocCallI = dyn_cast(MallocCall)) {
-MallocCallI->setDebugLoc(FirstDL);
+  Instruction *SetjmpTable;
+  if (EnableWasmAltSjLj) {
+// This alloca'ed pointer is used by the runtime to identify function
+// inovactions. It's just for pointer comparisons. It will never
+// be dereferenced.
+SetjmpTable = IRB.CreateAlloca(IRB.getInt32Ty());
+SetjmpTable->setDebugLoc(FirstDL);
+SetjmpTableInsts.push_back(SetjmpTable);

yamt wrote:

we need to insert this to make handleLongjmpableCallsForWasmSjLj happy.
we can simplify it if/when we can retire the current logic.


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


[clang] [llvm] [CodeGen][AArch64][FMV] PAC the stub_helper's frame on arm64e (PR #84704)

2024-03-10 Thread Jon Roelofs via cfe-commits


@@ -0,0 +1,58 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals 
--include-generated-funcs
+// RUN: %clang_cc1 -triple arm64e-apple-ios -target-feature +ls64 
-target-feature +fullfp16 -S -emit-llvm -o - %s | FileCheck %s
+
+int __attribute__((target_version("sha1"))) fmv(void) { return 1; }
+int __attribute__((target_version("default"))) fmv(void) { return 0; }
+int foo() {
+  return fmv();
+}
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv._Msha1
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@foo
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@fmv.resolver
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 2048
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 2048
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv._Msha1
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv.default

jroelofs wrote:

The machinery to sign these hasn't been upstreamed yet, but they'll be e.g. 
`@fmv.default.pauth` when that happens.

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


[clang] [llvm] [CodeGen][AArch64][FMV] PAC the stub_helper's frame on arm64e (PR #84704)

2024-03-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jon Roelofs (jroelofs)


Changes

... and apply default function attributes so that the resolver will also be 
PAC'd (once more `arm64e` patches land upstream).

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+12-6) 
- (added) clang/test/CodeGen/attr-target-version-arm64e.c (+58) 
- (modified) llvm/include/llvm/CodeGen/AsmPrinter.h (+9-4) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+2-1) 
- (modified) llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp (+45) 
- (modified) llvm/test/CodeGen/AArch64/ifunc-asm.ll (+16-5) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 967319bdfc4571..dadc76d04c5f6b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4365,13 +4365,16 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // For cpu_specific, don't create an ifunc yet because we don't know if the
   // cpu_dispatch will be emitted in this translation unit.
   if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
-llvm::Type *ResolverType = llvm::FunctionType::get(
+llvm::FunctionType *ResolverType = llvm::FunctionType::get(
 llvm::PointerType::get(DeclTy,

getTypes().getTargetAddressSpace(FD->getType())),
 false);
-llvm::Constant *Resolver = GetOrCreateLLVMFunction(
-MangledName + ".resolver", ResolverType, GlobalDecl{},
-/*ForVTable=*/false);
+llvm::Function *Resolver = cast(
+CreateRuntimeFunction(ResolverType, MangledName + ".resolver")
+.getCallee());
+llvm::AttrBuilder Attrs(getLLVMContext());
+addDefaultFunctionDefinitionAttributes(Attrs);
+Resolver->addFnAttrs(Attrs);
 llvm::GlobalIFunc *GIF =
 llvm::GlobalIFunc::create(DeclTy, 0, getMultiversionLinkage(*this, GD),
   "", Resolver, ());
@@ -4381,8 +4384,11 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
 return GIF;
   }
 
-  llvm::Constant *Resolver = GetOrCreateLLVMFunction(
-  ResolverName, DeclTy, GlobalDecl{}, /*ForVTable=*/false);
+  llvm::Function *Resolver = cast(
+  CreateRuntimeFunction(DeclTy, ResolverName).getCallee());
+  llvm::AttrBuilder Attrs(getLLVMContext());
+  addDefaultFunctionDefinitionAttributes(Attrs);
+  Resolver->addFnAttrs(Attrs);
   assert(isa(Resolver) &&
  "Resolver should be created for the first time");
   SetCommonAttributes(FD, cast(Resolver));
diff --git a/clang/test/CodeGen/attr-target-version-arm64e.c 
b/clang/test/CodeGen/attr-target-version-arm64e.c
new file mode 100644
index 00..2deff9a688daaa
--- /dev/null
+++ b/clang/test/CodeGen/attr-target-version-arm64e.c
@@ -0,0 +1,58 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals 
--include-generated-funcs
+// RUN: %clang_cc1 -triple arm64e-apple-ios -target-feature +ls64 
-target-feature +fullfp16 -S -emit-llvm -o - %s | FileCheck %s
+
+int __attribute__((target_version("sha1"))) fmv(void) { return 1; }
+int __attribute__((target_version("default"))) fmv(void) { return 0; }
+int foo() {
+  return fmv();
+}
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv._Msha1
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@foo
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@fmv.resolver
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 2048
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 2048
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv._Msha1
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv.default
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv.default
+// CHECK-SAME: () #[[ATTR1]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 0
+//
+//.
+// CHECK: attributes #[[ATTR0]] = { noinline 

[clang] [llvm] [CodeGen][AArch64][FMV] PAC the stub_helper's frame on arm64e (PR #84704)

2024-03-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Jon Roelofs (jroelofs)


Changes

... and apply default function attributes so that the resolver will also be 
PAC'd (once more `arm64e` patches land upstream).

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+12-6) 
- (added) clang/test/CodeGen/attr-target-version-arm64e.c (+58) 
- (modified) llvm/include/llvm/CodeGen/AsmPrinter.h (+9-4) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+2-1) 
- (modified) llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp (+45) 
- (modified) llvm/test/CodeGen/AArch64/ifunc-asm.ll (+16-5) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 967319bdfc4571..dadc76d04c5f6b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4365,13 +4365,16 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // For cpu_specific, don't create an ifunc yet because we don't know if the
   // cpu_dispatch will be emitted in this translation unit.
   if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
-llvm::Type *ResolverType = llvm::FunctionType::get(
+llvm::FunctionType *ResolverType = llvm::FunctionType::get(
 llvm::PointerType::get(DeclTy,

getTypes().getTargetAddressSpace(FD->getType())),
 false);
-llvm::Constant *Resolver = GetOrCreateLLVMFunction(
-MangledName + ".resolver", ResolverType, GlobalDecl{},
-/*ForVTable=*/false);
+llvm::Function *Resolver = cast(
+CreateRuntimeFunction(ResolverType, MangledName + ".resolver")
+.getCallee());
+llvm::AttrBuilder Attrs(getLLVMContext());
+addDefaultFunctionDefinitionAttributes(Attrs);
+Resolver->addFnAttrs(Attrs);
 llvm::GlobalIFunc *GIF =
 llvm::GlobalIFunc::create(DeclTy, 0, getMultiversionLinkage(*this, GD),
   "", Resolver, ());
@@ -4381,8 +4384,11 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
 return GIF;
   }
 
-  llvm::Constant *Resolver = GetOrCreateLLVMFunction(
-  ResolverName, DeclTy, GlobalDecl{}, /*ForVTable=*/false);
+  llvm::Function *Resolver = cast(
+  CreateRuntimeFunction(DeclTy, ResolverName).getCallee());
+  llvm::AttrBuilder Attrs(getLLVMContext());
+  addDefaultFunctionDefinitionAttributes(Attrs);
+  Resolver->addFnAttrs(Attrs);
   assert(isa(Resolver) &&
  "Resolver should be created for the first time");
   SetCommonAttributes(FD, cast(Resolver));
diff --git a/clang/test/CodeGen/attr-target-version-arm64e.c 
b/clang/test/CodeGen/attr-target-version-arm64e.c
new file mode 100644
index 00..2deff9a688daaa
--- /dev/null
+++ b/clang/test/CodeGen/attr-target-version-arm64e.c
@@ -0,0 +1,58 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals 
--include-generated-funcs
+// RUN: %clang_cc1 -triple arm64e-apple-ios -target-feature +ls64 
-target-feature +fullfp16 -S -emit-llvm -o - %s | FileCheck %s
+
+int __attribute__((target_version("sha1"))) fmv(void) { return 1; }
+int __attribute__((target_version("default"))) fmv(void) { return 0; }
+int foo() {
+  return fmv();
+}
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv._Msha1
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@foo
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@fmv.resolver
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 2048
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 2048
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv._Msha1
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv.default
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv.default
+// CHECK-SAME: () #[[ATTR1]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 0
+//
+//.
+// CHECK: attributes #[[ATTR0]] = { 

[clang] [llvm] [CodeGen][AArch64][FMV] PAC the stub_helper's frame on arm64e (PR #84704)

2024-03-10 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs created 
https://github.com/llvm/llvm-project/pull/84704

... and apply default function attributes so that the resolver will also be 
PAC'd (once more `arm64e` patches land upstream).

>From b352a41e1788819afbb15a5b6d79cbf2968dc5dc Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Sun, 10 Mar 2024 16:46:50 -0700
Subject: [PATCH] [CodeGen][AArch64][FMV] PAC the stub_helper's frame on arm64e

---
 clang/lib/CodeGen/CodeGenModule.cpp   | 18 --
 .../test/CodeGen/attr-target-version-arm64e.c | 58 +++
 llvm/include/llvm/CodeGen/AsmPrinter.h| 13 +++--
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  3 +-
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 45 ++
 llvm/test/CodeGen/AArch64/ifunc-asm.ll| 21 +--
 6 files changed, 142 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-version-arm64e.c

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 967319bdfc4571..dadc76d04c5f6b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4365,13 +4365,16 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // For cpu_specific, don't create an ifunc yet because we don't know if the
   // cpu_dispatch will be emitted in this translation unit.
   if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
-llvm::Type *ResolverType = llvm::FunctionType::get(
+llvm::FunctionType *ResolverType = llvm::FunctionType::get(
 llvm::PointerType::get(DeclTy,

getTypes().getTargetAddressSpace(FD->getType())),
 false);
-llvm::Constant *Resolver = GetOrCreateLLVMFunction(
-MangledName + ".resolver", ResolverType, GlobalDecl{},
-/*ForVTable=*/false);
+llvm::Function *Resolver = cast(
+CreateRuntimeFunction(ResolverType, MangledName + ".resolver")
+.getCallee());
+llvm::AttrBuilder Attrs(getLLVMContext());
+addDefaultFunctionDefinitionAttributes(Attrs);
+Resolver->addFnAttrs(Attrs);
 llvm::GlobalIFunc *GIF =
 llvm::GlobalIFunc::create(DeclTy, 0, getMultiversionLinkage(*this, GD),
   "", Resolver, ());
@@ -4381,8 +4384,11 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
 return GIF;
   }
 
-  llvm::Constant *Resolver = GetOrCreateLLVMFunction(
-  ResolverName, DeclTy, GlobalDecl{}, /*ForVTable=*/false);
+  llvm::Function *Resolver = cast(
+  CreateRuntimeFunction(DeclTy, ResolverName).getCallee());
+  llvm::AttrBuilder Attrs(getLLVMContext());
+  addDefaultFunctionDefinitionAttributes(Attrs);
+  Resolver->addFnAttrs(Attrs);
   assert(isa(Resolver) &&
  "Resolver should be created for the first time");
   SetCommonAttributes(FD, cast(Resolver));
diff --git a/clang/test/CodeGen/attr-target-version-arm64e.c 
b/clang/test/CodeGen/attr-target-version-arm64e.c
new file mode 100644
index 00..2deff9a688daaa
--- /dev/null
+++ b/clang/test/CodeGen/attr-target-version-arm64e.c
@@ -0,0 +1,58 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals 
--include-generated-funcs
+// RUN: %clang_cc1 -triple arm64e-apple-ios -target-feature +ls64 
-target-feature +fullfp16 -S -emit-llvm -o - %s | FileCheck %s
+
+int __attribute__((target_version("sha1"))) fmv(void) { return 1; }
+int __attribute__((target_version("default"))) fmv(void) { return 0; }
+int foo() {
+  return fmv();
+}
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv._Msha1
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@foo
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@fmv.resolver
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 2048
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 2048
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv._Msha1
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv.default
+//
+//
+// CHECK: Function 

[clang] [llvm] BPF address space insn (PR #84410)

2024-03-10 Thread via cfe-commits


@@ -0,0 +1,52 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt --bpf-check-and-opt-ir -S -mtriple=bpf-pc-linux < %s | FileCheck %s
+
+; Generated from the following C code:
+;
+;   extern int __uptr *magic1();
+;   extern int __uptr *magic2();
+;
+;   void test(long i) {
+; int __uptr *a;
+;
+; if (i > 42)
+;   a = magic1();
+; else
+;   a = magic2();
+; a[5] = 7;
+;   }
+;
+; Using the following command:
+;
+;   clang --target=bpf -O2 -S -emit-llvm -o t.ll t.c
+
+; Function Attrs: nounwind

eddyz87 wrote:

Oh, I see what you mean. I cleaned up the attributes by hand because those were 
not necessary for the test and have not adjusted the comment. Will change, 
thank you.

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


[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-10 Thread Owen Pan via cfe-commits

owenca wrote:

> Then I'd go back to `Style.isCpp()`.

That would still require passing `Style.isCpp()` as the parameter to the 
`FormatToken` (and other) functions.

> What happens if you use libFormat concurrently?

Can you elaborate? Doesn't each process get its own copy of the globals of a 
shared library?

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-10 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

This change started to cause
```
$ cat test.cc
template struct P {
~P() { p->f(); }
T * p;
};
struct X;
struct B { virtual ~B(); };
struct S: B { P x; };
```
```
$ clang++ -std=c++23 -fsyntax-only test.cc
test.cc:2:13: error: member access into incomplete type 'X'
2 | ~P() { p->f(); }
  | ^
test.cc:7:8: note: in instantiation of member function 'P::~P' requested here
7 | struct S: B { P x; };
  |^
test.cc:5:8: note: forward declaration of 'X'
5 | struct X;
  |^
1 error generated.
```
to fail, which I think is not intentional?

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-03-10 Thread Axel Lundberg via cfe-commits

https://github.com/Zonotora updated 
https://github.com/llvm/llvm-project/pull/75481

>From cd64144a4cf18adba1494871bfd9da1b0bf0a489 Mon Sep 17 00:00:00 2001
From: Zonotora 
Date: Sat, 16 Dec 2023 19:33:21 +0100
Subject: [PATCH 1/3] [clang] Extract negativity check lambda to function

---
 clang/lib/CodeGen/CGExprScalar.cpp | 41 ++
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 8536570087ad0f..74d94259572dc2 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1103,6 +1103,21 @@ void ScalarExprEmitter::EmitIntegerTruncationCheck(Value 
*Src, QualType SrcType,
 {Src, Dst});
 }
 
+static llvm::Value *EmitIsNegativeTestHelper(Value *V, QualType VType,
+ const char *Name,
+ CGBuilderTy ) {
+  bool VSigned = VType->isSignedIntegerOrEnumerationType();
+  llvm::Type *VTy = V->getType();
+  if (!VSigned) {
+// If the value is unsigned, then it is never negative.
+return llvm::ConstantInt::getFalse(VTy->getContext());
+  }
+  llvm::Constant *Zero = llvm::ConstantInt::get(VTy, 0);
+  return Builder.CreateICmp(llvm::ICmpInst::ICMP_SLT, V, Zero,
+llvm::Twine(Name) + "." + V->getName() +
+".negativitycheck");
+};
+
 // Should be called within CodeGenFunction::SanitizerScope RAII scope.
 // Returns 'i1 false' when the conversion Src -> Dst changed the sign.
 static std::pair Value * {
-// Is this value a signed type?
-bool VSigned = VType->isSignedIntegerOrEnumerationType();
-llvm::Type *VTy = V->getType();
-if (!VSigned) {
-  // If the value is unsigned, then it is never negative.
-  // FIXME: can we encounter non-scalar VTy here?
-  return llvm::ConstantInt::getFalse(VTy->getContext());
-}
-// Get the zero of the same type with which we will be comparing.
-llvm::Constant *Zero = llvm::ConstantInt::get(VTy, 0);
-// %V.isnegative = icmp slt %V, 0
-// I.e is %V *strictly* less than zero, does it have negative value?
-return Builder.CreateICmp(llvm::ICmpInst::ICMP_SLT, V, Zero,
-  llvm::Twine(Name) + "." + V->getName() +
-  ".negativitycheck");
-  };
-
   // 1. Was the old Value negative?
-  llvm::Value *SrcIsNegative = EmitIsNegativeTest(Src, SrcType, "src");
+  llvm::Value *SrcIsNegative =
+  EmitIsNegativeTestHelper(Src, SrcType, "src", Builder);
   // 2. Is the new Value negative?
-  llvm::Value *DstIsNegative = EmitIsNegativeTest(Dst, DstType, "dst");
+  llvm::Value *DstIsNegative =
+  EmitIsNegativeTestHelper(Dst, DstType, "dst", Builder);
   // 3. Now, was the 'negativity status' preserved during the conversion?
   //NOTE: conversion from negative to zero is considered to change the 
sign.
   //(We want to get 'false' when the conversion changed the sign)

>From e5914b0519efa0d70c429f2b08b326f863df4fbe Mon Sep 17 00:00:00 2001
From: Zonotora 
Date: Sat, 16 Dec 2023 19:36:04 +0100
Subject: [PATCH 2/3] [clang][UBSan] Add implicit conversion check for
 bitfields

This patch implements the implicit truncation and implicit
sign change checks for bitfields.
---
 clang/docs/ReleaseNotes.rst   |   7 +
 clang/docs/UndefinedBehaviorSanitizer.rst |  19 +-
 clang/include/clang/Basic/Sanitizers.def  |  20 +-
 clang/lib/CodeGen/CGExpr.cpp  |  45 +++-
 clang/lib/CodeGen/CGExprScalar.cpp| 224 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  12 +
 .../test/CodeGen/ubsan-bitfield-conversion.c  |  61 +
 compiler-rt/lib/ubsan/ubsan_handlers.cpp  |  27 ++-
 compiler-rt/lib/ubsan/ubsan_handlers.h|   1 +
 9 files changed, 378 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/CodeGen/ubsan-bitfield-conversion.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..7a8135077a2bc2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -173,6 +173,10 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
+  sign change.
+- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
+  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -183,6 +187,9 @@ Deprecated Compiler Flags
 
 Modified Compiler Flags
 ---
+- ``-fsanitize=implicit-conversion`` is now a group for both
+  ``-fsanitize=implicit-integer-conversion`` and
+  ``-fsanitize=implicit-bitfield-conversion``.
 
 Removed Compiler Flags
 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/4] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [clang][analyzer] Improve BlockInCriticalSectionsChecker (PR #80029)

2024-03-10 Thread Endre Fülöp via cfe-commits

gamesh411 wrote:

As keeping the trivial change that this PR was before, and thanks to the fact 
that the checker needed a major overhaul, I have increased the scope of this 
change to support the use cases mentioned by @balazske.
That is why I am re-requesting a review.

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


[clang] [clang][analyzer] Improve BlockInCriticalSectionsChecker (PR #80029)

2024-03-10 Thread Endre Fülöp via cfe-commits

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread Amirreza Ashouri via cfe-commits


@@ -249,6 +249,12 @@ Bug Fixes in This Version
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
+  Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+

AMP999 wrote:

That's right! I've fixed it.

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/3] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

Fixes https://github.com/llvm/llvm-project/issues/77091

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [clang][analyzer] Add note tags to alpha.unix.BlockInCriticalSection (PR #80029)

2024-03-10 Thread Endre Fülöp via cfe-commits

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

From 346e2296869e750c7ec5bd75cf05f80a23b70569 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Tue, 30 Jan 2024 11:33:30 +0100
Subject: [PATCH] [clang][analyzer] Improve BlockInCriticalSectionsChecker with
 multi-section and recursive mutex support

* Add support for multiple, potentially overlapping critical sections:
  The checker can now simultaneously handle several mutex's critical
  sections without confusing them.
* Implement the handling of recursive mutexes:
  By identifying the lock events, recursive mutexes are now supported.
  A lock event is a pair of a lock expression and the SVal of the mutex
  that it locks, so even multiple locks of the same mutex (and even by
  the same expression) is now supported.
* Refine the note tags generated by the checker:
  The note tags now correctly show just for mutexes those are
  active at point of error, and multiple acqisitions of the same mutex
  are also noted.
---
 .../BlockInCriticalSectionChecker.cpp | 391 ++
 .../Analysis/block-in-critical-section.cpp| 270 +---
 2 files changed, 515 insertions(+), 146 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index 66e080adb1382b..74ec4b73bd8b5f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -20,48 +20,180 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
+
+#include 
+#include 
+#include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+struct CritSectionMarker {
+  const Expr *LockExpr{};
+  const MemRegion *LockReg{};
+
+  void Profile(llvm::FoldingSetNodeID ) const {
+ID.Add(LockExpr);
+ID.Add(LockReg);
+  }
+
+  [[nodiscard]] constexpr bool
+  operator==(const CritSectionMarker ) const noexcept {
+return LockExpr == Other.LockExpr && LockReg == Other.LockReg;
+  }
+  [[nodiscard]] constexpr bool
+  operator!=(const CritSectionMarker ) const noexcept {
+return !(*this == Other);
+  }
+};
+
+class FirstArgMutexDescriptor {
+  CallDescription LockFn;
+  CallDescription UnlockFn;
+
+public:
+  FirstArgMutexDescriptor(CallDescription &, CallDescription &)
+  : LockFn(std::move(LockFn)), UnlockFn(std::move(UnlockFn)) {}
+  [[nodiscard]] bool matchesLock(const CallEvent ) const {
+return LockFn.matches(Call) && Call.getNumArgs() > 0;
+  }
+  [[nodiscard]] bool matchesUnlock(const CallEvent ) const {
+return UnlockFn.matches(Call) && Call.getNumArgs() > 0;
+  }
+  [[nodiscard]] const MemRegion *getLockRegion(const CallEvent ) const {
+return Call.getArgSVal(0).getAsRegion();
+  }
+  [[nodiscard]] const MemRegion *getUnlockRegion(const CallEvent ) const {
+return Call.getArgSVal(0).getAsRegion();
+  }
+};
+
+class MemberMutexDescriptor {
+  CallDescription LockFn;
+  CallDescription UnlockFn;
+
+public:
+  MemberMutexDescriptor(CallDescription &, CallDescription &)
+  : LockFn(std::move(LockFn)), UnlockFn(std::move(UnlockFn)) {}
+  [[nodiscard]] bool matchesLock(const CallEvent ) const {
+return LockFn.matches(Call);
+  }
+  bool matchesUnlock(const CallEvent ) const {
+return UnlockFn.matches(Call);
+  }
+  [[nodiscard]] const MemRegion *getLockRegion(const CallEvent ) const {
+return cast(Call).getCXXThisVal().getAsRegion();
+  }
+  [[nodiscard]] const MemRegion *getUnlockRegion(const CallEvent ) const {
+return cast(Call).getCXXThisVal().getAsRegion();
+  }
+};
+
+class RAIIMutexDescriptor {
+  mutable const IdentifierInfo *Guard{};
+  mutable bool IdentifierInfoInitialized{};
+  mutable llvm::SmallString<32> GuardName{};
+
+  void initIdentifierInfo(const CallEvent ) const {
+if (!IdentifierInfoInitialized) {
+  // In case of checking C code, or when the corresponding headers are not
+  // included, we might end up query the identifier table every time when
+  // 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 = ()->getASTContext().Idents.get(
+  GuardName);
+  IdentifierInfoInitialized = true;
+}
+  }
+
+public:
+  RAIIMutexDescriptor(StringRef GuardName) : GuardName(GuardName) {}
+  [[nodiscard]] bool matchesLock(const CallEvent ) 

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-10 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

Then I'd go back to `Style.isCpp()`.

What happens if you use libFormat concurrently?

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


[clang] [llvm] New calling convention preserve_none (PR #76868)

2024-03-10 Thread Caleb Helbling via cfe-commits

calebh wrote:

We have another use case for this calling convention - micropatching. See my 
coworker's blog post on how this would work: 
https://www.philipzucker.com/permutation_compile/

Is there a reason why r10 isn't included in the list of registers for x64?

Having support for additional architectures (ARM, PPC) would be great for our 
use case.

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/82947

From f1d957413bcc81e9ced06ad40570859769f4c1c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 20:20:59 -0500
Subject: [PATCH 1/6] [clang-tidy] Improved modernize-use-using by fixing a
 false-negative

The check needs a parent decl to match but if the typedef is in a function,
the parent is a declStmt which is not a decl by itself.
Improved the matcher to match on either a decl or a declstmt and extract
the decl from the stmt in the latter case.

fixes #72179
---
 .../clang-tidy/modernize/UseUsingCheck.cpp | 16 +---
 clang-tools-extra/docs/ReleaseNotes.rst|  3 +++
 .../checkers/modernize/use-using.cpp   | 18 ++
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index bb05f206c717ce..50a07fc02e31b4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -24,6 +24,7 @@ static constexpr llvm::StringLiteral ExternCDeclName = 
"extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
+static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -41,7 +42,8 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   unless(isInstantiated()),
   optionally(hasAncestor(
   linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
-  hasParent(decl().bind(ParentDeclName)))
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName
   .bind(TypedefName),
   this);
 
@@ -51,17 +53,25 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   tagDecl(
   anyOf(allOf(unless(anyOf(isImplicit(),
classTemplateSpecializationDecl())),
-  hasParent(decl().bind(ParentDeclName))),
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName,
 // We want the parent of the ClassTemplateDecl, not the parent
 // of the specialization.
 classTemplateSpecializationDecl(hasAncestor(classTemplateDecl(
-hasParent(decl().bind(ParentDeclName)))
+anyOf(hasParent(decl().bind(ParentDeclName)),
+  hasParent(declStmt().bind(DeclStmtName
   .bind(TagDeclName),
   this);
 }
 
 void UseUsingCheck::check(const MatchFinder::MatchResult ) {
   const auto *ParentDecl = Result.Nodes.getNodeAs(ParentDeclName);
+
+  if (!ParentDecl) {
+const auto *ParentDeclStmt = 
Result.Nodes.getNodeAs(DeclStmtName);
+ParentDecl = ParentDeclStmt->getSingleDecl();
+  }
+
   if (!ParentDecl)
 return;
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f54..479b9b86444184 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,6 +224,9 @@ Changes in existing checks
   analyzed, se the check now handles the common patterns
   `const auto e = (*vector_ptr)[i]` and `const auto e = vector_ptr->at(i);`.
 
+- Improved :doc:`modernize-use-using `
+  check by fixing false-negative in functions.
+
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 462bc984fd3ad5..230c7c94cda1cf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -342,3 +342,21 @@ typedef int InExternCPP;
 // CHECK-FIXES: using InExternCPP = int;
 
 }
+
+namespace ISSUE_72179
+{  
+  void foo()
+  {
+typedef int a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using a = int;
+
+  }
+
+  void foo2()
+  {
+typedef struct { int a; union { int b; }; } c;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using c = struct { int a; union { int b; }; };
+  }
+}

From e7dcbbcf92e896354e9a52da259251a7d3a74369 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 22:14:22 -0500

[clang] [clang-repl] Expose CreateExecutor() and ResetExecutor() in extended Interpreter interface (PR #84460)

2024-03-10 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/84460

From 10f8d3eb040a5838d84d8a84fe636c7c2a7d196b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Fri, 8 Mar 2024 00:08:56 +0100
Subject: [PATCH 1/3] [clang-repl] Expose RuntimeInterfaceBuilder for
 customizations

---
 clang/include/clang/Interpreter/Interpreter.h |  35 ++-
 clang/lib/Interpreter/Interpreter.cpp | 247 ++
 clang/unittests/Interpreter/CMakeLists.txt|   1 +
 .../Interpreter/InterpreterExtensionsTest.cpp |  79 ++
 4 files changed, 253 insertions(+), 109 deletions(-)
 create mode 100644 clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index c8f932e95c4798..d972d960dcb7cd 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -18,6 +18,7 @@
 #include "clang/AST/GlobalDecl.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Interpreter/Value.h"
+#include "clang/Sema/Ownership.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
@@ -75,17 +76,26 @@ class IncrementalCompilerBuilder {
   llvm::StringRef CudaSDKPath;
 };
 
+/// Generate glue code between the Interpreter's built-in runtime and user 
code.
+class RuntimeInterfaceBuilder {
+public:
+  virtual ~RuntimeInterfaceBuilder() = default;
+
+  using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder,
+   Expr *, ArrayRef);
+  virtual TransformExprFunction *getPrintValueTransformer() = 0;
+};
+
 /// Provides top-level interfaces for incremental compilation and execution.
 class Interpreter {
   std::unique_ptr TSCtx;
   std::unique_ptr IncrParser;
   std::unique_ptr IncrExecutor;
+  std::unique_ptr RuntimeIB;
 
   // An optional parser for CUDA offloading
   std::unique_ptr DeviceParser;
 
-  Interpreter(std::unique_ptr CI, llvm::Error );
-
   llvm::Error CreateExecutor();
   unsigned InitPTUSize = 0;
 
@@ -94,8 +104,25 @@ class Interpreter {
   // printing happens, it's in an invalid state.
   Value LastValue;
 
+  // Add a call to an Expr to report its result. We query the function from
+  // RuntimeInterfaceBuilder once and store it as a function pointer to avoid
+  // frequent virtual function calls.
+  RuntimeInterfaceBuilder::TransformExprFunction *AddPrintValueCall = nullptr;
+
+protected:
+  // Derived classes can make use an extended interface of the Interpreter.
+  // That's useful for testing and out-of-tree clients.
+  Interpreter(std::unique_ptr CI, llvm::Error );
+
+  // Lazily construct the RuntimeInterfaceBuilder. The provided instance will 
be
+  // used for the entire lifetime of the interpreter. The default 
implementation
+  // targets the in-process __clang_Interpreter runtime. Override this to use a
+  // custom runtime.
+  virtual std::unique_ptr FindRuntimeInterface();
+
 public:
-  ~Interpreter();
+  virtual ~Interpreter();
+
   static llvm::Expected>
   create(std::unique_ptr CI);
   static llvm::Expected>
@@ -143,8 +170,6 @@ class Interpreter {
 private:
   size_t getEffectivePTUSize() const;
 
-  bool FindRuntimeInterface();
-
   llvm::DenseMap Dtors;
 
   llvm::SmallVector ValuePrintingInfo;
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 37696b28976428..3485da8196683a 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -507,9 +507,13 @@ static constexpr llvm::StringRef MagicRuntimeInterface[] = 
{
 "__clang_Interpreter_SetValueWithAlloc",
 "__clang_Interpreter_SetValueCopyArr", "__ci_newtag"};
 
-bool Interpreter::FindRuntimeInterface() {
+static std::unique_ptr
+createInProcessRuntimeInterfaceBuilder(Interpreter , ASTContext ,
+   Sema );
+
+std::unique_ptr Interpreter::FindRuntimeInterface() {
   if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; }))
-return true;
+return nullptr;
 
   Sema  = getCompilerInstance()->getSema();
   ASTContext  = S.getASTContext();
@@ -528,120 +532,34 @@ bool Interpreter::FindRuntimeInterface() {
 
   if (!LookupInterface(ValuePrintingInfo[NoAlloc],
MagicRuntimeInterface[NoAlloc]))
-return false;
+return nullptr;
   if (!LookupInterface(ValuePrintingInfo[WithAlloc],
MagicRuntimeInterface[WithAlloc]))
-return false;
+return nullptr;
   if (!LookupInterface(ValuePrintingInfo[CopyArray],
MagicRuntimeInterface[CopyArray]))
-return false;
+return nullptr;
   if (!LookupInterface(ValuePrintingInfo[NewTag],
MagicRuntimeInterface[NewTag]))
-return false;
-  return true;
+return nullptr;
+
+  return createInProcessRuntimeInterfaceBuilder(*this, Ctx, S);
 }
 
 namespace {
 

[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

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


[clang] [llvm] [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x >= 0` (PR #82404)

2024-03-10 Thread via cfe-commits

goldsteinn wrote:

> It looks like you need to update `Headers/__clang_hip_math.hip` in clang.

Fixed. Thats what I get for not running clang tests :/

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


[clang] [llvm] [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x >= 0` (PR #82404)

2024-03-10 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/82404

>From 08fddf10b8d78f5cf866dcb687009f20cfb85bd3 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Tue, 20 Feb 2024 12:51:02 -0600
Subject: [PATCH] [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x
 >= 0`

Just a standard canonicalization.

Proofs: https://alive2.llvm.org/ce/z/9W4VFm
---
 clang/test/Headers/__clang_hip_math.hip   | 24 
 .../InstCombine/InstCombineCasts.cpp  |  6 +-
 .../test/Transforms/InstCombine/add-sitofp.ll | 10 ++--
 .../Transforms/InstCombine/binop-itofp.ll | 28 +-
 .../Transforms/InstCombine/clamp-to-minmax.ll |  6 +-
 llvm/test/Transforms/InstCombine/fpcast.ll| 12 ++--
 .../Transforms/InstCombine/minmax-fold.ll | 10 ++--
 llvm/test/Transforms/InstCombine/minmax-fp.ll |  2 +-
 llvm/test/Transforms/InstCombine/pr27236.ll   |  2 +-
 .../LoopVectorize/X86/float-induction-x86.ll  |  6 +-
 .../LoopVectorize/float-induction.ll  | 56 +--
 11 files changed, 83 insertions(+), 79 deletions(-)

diff --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index 37099de74fb8ec..701f93853ab93c 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -1685,7 +1685,7 @@ extern "C" __device__ double test_j1(double x) {
 // DEFAULT-NEXT:[[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// DEFAULT-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
+// DEFAULT-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
 // DEFAULT-NEXT:[[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
 // DEFAULT-NEXT:[[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], 
[[DIV_I]]
 // DEFAULT-NEXT:[[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1718,7 +1718,7 @@ extern "C" __device__ double test_j1(double x) {
 // FINITEONLY-NEXT:[[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// FINITEONLY-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
+// FINITEONLY-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
 // FINITEONLY-NEXT:[[DIV_I:%.*]] = fdiv nnan ninf contract float 
[[CONV_I]], [[Y]]
 // FINITEONLY-NEXT:[[MUL8_I:%.*]] = fmul nnan ninf contract float 
[[__X1_0_I3]], [[DIV_I]]
 // FINITEONLY-NEXT:[[SUB_I]] = fsub nnan ninf contract float [[MUL8_I]], 
[[__X0_0_I2]]
@@ -1751,7 +1751,7 @@ extern "C" __device__ double test_j1(double x) {
 // APPROX-NEXT:[[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // APPROX-NEXT:[[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // APPROX-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// APPROX-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
+// APPROX-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
 // APPROX-NEXT:[[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
 // APPROX-NEXT:[[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], 
[[DIV_I]]
 // APPROX-NEXT:[[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1788,7 +1788,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
 // DEFAULT-NEXT:[[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// DEFAULT-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
+// DEFAULT-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
 // DEFAULT-NEXT:[[DIV_I:%.*]] = fdiv contract double [[CONV_I]], [[Y]]
 // DEFAULT-NEXT:[[MUL8_I:%.*]] = fmul contract double [[__X1_0_I3]], 
[[DIV_I]]
 // DEFAULT-NEXT:[[SUB_I]] = fsub contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -1821,7 +1821,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
 // FINITEONLY-NEXT:[[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// FINITEONLY-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
+// FINITEONLY-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
 // FINITEONLY-NEXT:[[DIV_I:%.*]] = fdiv nnan ninf 

[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2024-03-10 Thread Matt Mundell via cfe-commits

mattmundell wrote:

Thanks @owenca, I added an argument name instead 
([cb983df](https://github.com/greenbone/gvmd/pull/2112/commits/cb983dfada959f0f73bfed7a438e5c79898408d6)).

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

felix642 wrote:

Thank you for the quick review @PiotrZSL. I've implemented the proposed changes 
and rebased on top of main. We can wait a few days to see if someone else has 
some comments to add and then we should be ready to merge 

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/82947

From f1d957413bcc81e9ced06ad40570859769f4c1c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 20:20:59 -0500
Subject: [PATCH 1/5] [clang-tidy] Improved modernize-use-using by fixing a
 false-negative

The check needs a parent decl to match but if the typedef is in a function,
the parent is a declStmt which is not a decl by itself.
Improved the matcher to match on either a decl or a declstmt and extract
the decl from the stmt in the latter case.

fixes #72179
---
 .../clang-tidy/modernize/UseUsingCheck.cpp | 16 +---
 clang-tools-extra/docs/ReleaseNotes.rst|  3 +++
 .../checkers/modernize/use-using.cpp   | 18 ++
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index bb05f206c717ce..50a07fc02e31b4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -24,6 +24,7 @@ static constexpr llvm::StringLiteral ExternCDeclName = 
"extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
+static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -41,7 +42,8 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   unless(isInstantiated()),
   optionally(hasAncestor(
   linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
-  hasParent(decl().bind(ParentDeclName)))
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName
   .bind(TypedefName),
   this);
 
@@ -51,17 +53,25 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   tagDecl(
   anyOf(allOf(unless(anyOf(isImplicit(),
classTemplateSpecializationDecl())),
-  hasParent(decl().bind(ParentDeclName))),
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName,
 // We want the parent of the ClassTemplateDecl, not the parent
 // of the specialization.
 classTemplateSpecializationDecl(hasAncestor(classTemplateDecl(
-hasParent(decl().bind(ParentDeclName)))
+anyOf(hasParent(decl().bind(ParentDeclName)),
+  hasParent(declStmt().bind(DeclStmtName
   .bind(TagDeclName),
   this);
 }
 
 void UseUsingCheck::check(const MatchFinder::MatchResult ) {
   const auto *ParentDecl = Result.Nodes.getNodeAs(ParentDeclName);
+
+  if (!ParentDecl) {
+const auto *ParentDeclStmt = 
Result.Nodes.getNodeAs(DeclStmtName);
+ParentDecl = ParentDeclStmt->getSingleDecl();
+  }
+
   if (!ParentDecl)
 return;
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f54..479b9b86444184 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,6 +224,9 @@ Changes in existing checks
   analyzed, se the check now handles the common patterns
   `const auto e = (*vector_ptr)[i]` and `const auto e = vector_ptr->at(i);`.
 
+- Improved :doc:`modernize-use-using `
+  check by fixing false-negative in functions.
+
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 462bc984fd3ad5..230c7c94cda1cf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -342,3 +342,21 @@ typedef int InExternCPP;
 // CHECK-FIXES: using InExternCPP = int;
 
 }
+
+namespace ISSUE_72179
+{  
+  void foo()
+  {
+typedef int a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using a = int;
+
+  }
+
+  void foo2()
+  {
+typedef struct { int a; union { int b; }; } c;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using c = struct { int a; union { int b; }; };
+  }
+}

From e7dcbbcf92e896354e9a52da259251a7d3a74369 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 22:14:22 -0500

[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-10 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/82947

From d1cbed0e2e83bd3544067fd25d7e811f1ab3f095 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 20:20:59 -0500
Subject: [PATCH 1/4] [clang-tidy] Improved modernize-use-using by fixing a
 false-negative

The check needs a parent decl to match but if the typedef is in a function,
the parent is a declStmt which is not a decl by itself.
Improved the matcher to match on either a decl or a declstmt and extract
the decl from the stmt in the latter case.

fixes #72179
---
 .../clang-tidy/modernize/UseUsingCheck.cpp | 16 +---
 clang-tools-extra/docs/ReleaseNotes.rst|  3 +++
 .../checkers/modernize/use-using.cpp   | 18 ++
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index bb05f206c717ce..50a07fc02e31b4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -24,6 +24,7 @@ static constexpr llvm::StringLiteral ExternCDeclName = 
"extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
+static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -41,7 +42,8 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   unless(isInstantiated()),
   optionally(hasAncestor(
   linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
-  hasParent(decl().bind(ParentDeclName)))
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName
   .bind(TypedefName),
   this);
 
@@ -51,17 +53,25 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   tagDecl(
   anyOf(allOf(unless(anyOf(isImplicit(),
classTemplateSpecializationDecl())),
-  hasParent(decl().bind(ParentDeclName))),
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName,
 // We want the parent of the ClassTemplateDecl, not the parent
 // of the specialization.
 classTemplateSpecializationDecl(hasAncestor(classTemplateDecl(
-hasParent(decl().bind(ParentDeclName)))
+anyOf(hasParent(decl().bind(ParentDeclName)),
+  hasParent(declStmt().bind(DeclStmtName
   .bind(TagDeclName),
   this);
 }
 
 void UseUsingCheck::check(const MatchFinder::MatchResult ) {
   const auto *ParentDecl = Result.Nodes.getNodeAs(ParentDeclName);
+
+  if (!ParentDecl) {
+const auto *ParentDeclStmt = 
Result.Nodes.getNodeAs(DeclStmtName);
+ParentDecl = ParentDeclStmt->getSingleDecl();
+  }
+
   if (!ParentDecl)
 return;
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6fd01ed9d471c5..2b36ae4acb9f1d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`modernize-use-using `
+  check by fixing false-negative in functions.
+
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 462bc984fd3ad5..230c7c94cda1cf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -342,3 +342,21 @@ typedef int InExternCPP;
 // CHECK-FIXES: using InExternCPP = int;
 
 }
+
+namespace ISSUE_72179
+{  
+  void foo()
+  {
+typedef int a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using a = int;
+
+  }
+
+  void foo2()
+  {
+typedef struct { int a; union { int b; }; } c;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using c = struct { int a; union { int b; }; };
+  }
+}

From 0b5c78508fbf49229d576171d7af6c6bb16b4367 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 22:14:22 -0500
Subject: [PATCH 2/4] fixup! [clang-tidy] 

[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-10 Thread via cfe-commits

https://github.com/guillem-bartina-sonarsource updated 
https://github.com/llvm/llvm-project/pull/84515

>From 473e8bbeaa8bcb4fb313a5cc75cc7a5de5367879 Mon Sep 17 00:00:00 2001
From: guillem-bartina-sonarsource 
Date: Fri, 8 Mar 2024 17:16:56 +0100
Subject: [PATCH] [clang][Sema] Refine unused-member-function diagnostic
 message for constructors

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Sema/Sema.cpp   | 15 
 clang/test/SemaCXX/warn-unused-filescoped.cpp | 23 +++
 3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9b5245695153ec..703803ad2c1212 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -400,7 +400,7 @@ def warn_unused_function : Warning<"unused function %0">,
   InGroup, DefaultIgnore;
 def warn_unused_template : Warning<"unused %select{function|variable}0 
template %1">,
   InGroup, DefaultIgnore;
-def warn_unused_member_function : Warning<"unused member function %0">,
+def warn_unused_member_function : Warning<"unused %select{member 
function|constructor}0 %1">,
   InGroup, DefaultIgnore;
 def warn_used_but_marked_unused: Warning<"%0 was marked unused but was used">,
   InGroup, DefaultIgnore;
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 720d5fd5f0428d..163ab48998d5e0 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1398,11 +1398,16 @@ void Sema::ActOnEndOfTranslationUnit() {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
 << /*function=*/0 << DiagD << DiagRange;
-  else
-Diag(DiagD->getLocation(), isa(DiagD)
-   ? diag::warn_unused_member_function
-   : diag::warn_unused_function)
-<< DiagD << DiagRange;
+  else {
+if (isa(DiagD))
+  Diag(DiagD->getLocation(), diag::warn_unused_member_function)
+  << (!isa(DiagD) ? /*member function=*/0
+  : /*constructor=*/1)
+  << DiagD << DiagRange;
+else
+  Diag(DiagD->getLocation(), diag::warn_unused_function)
+  << DiagD << DiagRange;
+  }
 }
   } else {
 const VarDecl *DiagD = cast(*I)->getDefinition();
diff --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp 
b/clang/test/SemaCXX/warn-unused-filescoped.cpp
index be8d350855c078..b3d1bb4661a5f4 100644
--- a/clang/test/SemaCXX/warn-unused-filescoped.cpp
+++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp
@@ -76,10 +76,33 @@ struct S {
   struct SVS : public VS {
 void vm() { }
   };
+
+  struct CS {
+CS() {}
+CS(bool a) {}
+CS(int b) {} // expected-warning{{unused constructor 'CS'}}
+CS(float c);
+  };
+
+  struct DCS : public CS {
+DCS() = default; // expected-warning{{unused constructor 'DCS'}}
+DCS(bool a) : CS(a) {} // expected-warning{{unused constructor 'DCS'}}
+DCS(const DCS&) {}
+DCS(DCS&&) {} // expected-warning{{unused constructor 'DCS'}}
+  };
+
+  template
+  struct TCS {
+TCS();
+  };
+  template  TCS::TCS() {}
+  template <> TCS::TCS() {} // expected-warning{{unused constructor 
'TCS'}}
 }
 
 void S::m3() {} // expected-warning{{unused member function 'm3'}}
 
+CS::CS(float c) {} // expected-warning{{unused constructor 'CS'}}
+
 static inline void f4() {} // expected-warning{{unused function 'f4'}}
 const unsigned int cx = 0; // expected-warning{{unused variable 'cx'}}
 const unsigned int cy = 0;

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-10 Thread via cfe-commits

https://github.com/guillem-bartina-sonarsource edited 
https://github.com/llvm/llvm-project/pull/84515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-10 Thread via cfe-commits


@@ -1398,11 +1398,16 @@ void Sema::ActOnEndOfTranslationUnit() {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
 << /*function=*/0 << DiagD << DiagRange;
-  else
-Diag(DiagD->getLocation(), isa(DiagD)
-   ? diag::warn_unused_member_function
-   : diag::warn_unused_function)
-<< DiagD << DiagRange;
+  else {
+if (isa(DiagD))
+  Diag(DiagD->getLocation(), diag::warn_unused_member_function)
+  << (!isa(DiagD) ? /*member function=*/0
+  : /*constructor=*/1)
+  << DiagD << DiagRange;
+else
+  Diag(DiagD->getLocation(), diag::warn_unused_function)
+  << DiagD << DiagRange;
+  }

guillem-bartina-sonarsource wrote:

Note that `warn_unused_function` and `warn_unused_member_function` are two 
different diagnostics, with different messages. The former has only one 
argument, whereas the latter now has two (one of them selects between `member 
function` and `constructor`).
Unless I'm missing some hidden logic regarding diagnostic constructors and the 
'<<' operator, we can't merge the two because the two diagnostics have 
different number of arguments.

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


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-03-10 Thread via cfe-commits

fpasserby wrote:

> Thanks. This looks good to me except few nit comments.
> 
> Have you tested on a real world workloads?

I've tested it on seastar and libcppcoro tests and on the example from #72006.

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


[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-10 Thread Balazs Benics via cfe-commits

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

See my previous reply.

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


[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-10 Thread Balazs Benics via cfe-commits

steakhal wrote:

Thanks for the PR.
I think it would make sense to not expose data members in a class' public api.
We might need some member functions along the way to make this possible.

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


[clang] [Clang] [Parser] Support [[omp::assume]] (PR #84582)

2024-03-10 Thread via cfe-commits

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


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

2024-03-10 Thread via cfe-commits


@@ -1227,12 +1227,11 @@ C++14 implementation status
 
 
 
-(7): In Clang 3.7 and later, sized deallocation is only 
enabled
-if the user passes the -fsized-deallocation flag. The user must
-supply definitions of the sized deallocation functions, either by providing 
them
-explicitly or by using a C++ standard library that does. libstdc++
-added these functions in version 5.0, and libc++ added them in
-version 3.7.
+(7): The user must supply definitions of the sized 
deallocation
+  functions, either by providing them explicitly or by using a C++ standard 
library
+  that does. libstdc++ added these functions in version 5.0, and
+  libc++ added them in version 3.7. The user can also use the
+  -fno-sized-deallocation option to disable sized deallocation.

cor3ntin wrote:

@mordante @AaronBallman do we still support either of these? I'm inclined to 
removing the comment entirely. 

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


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

2024-03-10 Thread via cfe-commits

https://github.com/cor3ntin commented:

The `__cpp_sized_deallocation`  feature test macro should be set to 201309L

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


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

2024-03-10 Thread via cfe-commits

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread via cfe-commits

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-10 Thread via cfe-commits


@@ -249,6 +249,12 @@ Bug Fixes in This Version
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
+  Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+

cor3ntin wrote:

That's should be moved _after_ the next line (and you can use the same 
`#GH` syntax )

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


[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)

2024-03-10 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/84671

>From fba48b8ca75113fc8226e065c85ce276a4e9ed6b Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 10 Mar 2024 16:11:18 +0800
Subject: [PATCH] [Clang][Sema] Fix a bug on type constraint checking

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  1 +
 clang/test/Sema/PR84368.cpp| 16 
 3 files changed, 19 insertions(+)
 create mode 100644 clang/test/Sema/PR84368.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..c1e77e34bb77e2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,8 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Fix a bug on type constraint checking (#GH84368).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 20c2c93ac9c7b4..765c5bc689ae1e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1698,6 +1698,7 @@ Decl 
*TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 assert(!Owner->isDependentContext());
 Inst->setLexicalDeclContext(Owner);
 RecordInst->setLexicalDeclContext(Owner);
+Inst->setObjectOfFriendDecl();
 
 if (PrevClassTemplate) {
   Inst->setCommonPtr(PrevClassTemplate->getCommonPtr());
diff --git a/clang/test/Sema/PR84368.cpp b/clang/test/Sema/PR84368.cpp
new file mode 100644
index 00..073530ffd8abea
--- /dev/null
+++ b/clang/test/Sema/PR84368.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
+// expected-no-diagnostics
+
+template concept IsOk = requires() { typename T::Float; };
+
+template struct Thing;
+
+template struct Foobar {
+   template struct Inner {
+   template friend struct Thing;
+   };
+};
+
+struct MyType { using Float=float; };
+Foobar::Inner<0> foobar;

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


[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)

2024-03-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

Try to fix https://github.com/llvm/llvm-project/issues/84368
[temp.friend]p1:
Similarly, each specialization of the `task` class template has the class 
template
specialization `taskint` as a friend, and has all specializations of 
the class template `frd` as friends.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1) 
- (added) clang/test/Sema/PR84368.cpp (+16) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..b32e739288dbc5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,8 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Fix a bug on type constraint checking (#GH84368). 
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 20c2c93ac9c7b4..765c5bc689ae1e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1698,6 +1698,7 @@ Decl 
*TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 assert(!Owner->isDependentContext());
 Inst->setLexicalDeclContext(Owner);
 RecordInst->setLexicalDeclContext(Owner);
+Inst->setObjectOfFriendDecl();
 
 if (PrevClassTemplate) {
   Inst->setCommonPtr(PrevClassTemplate->getCommonPtr());
diff --git a/clang/test/Sema/PR84368.cpp b/clang/test/Sema/PR84368.cpp
new file mode 100644
index 00..073530ffd8abea
--- /dev/null
+++ b/clang/test/Sema/PR84368.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
+// expected-no-diagnostics
+
+template concept IsOk = requires() { typename T::Float; };
+
+template struct Thing;
+
+template struct Foobar {
+   template struct Inner {
+   template friend struct Thing;
+   };
+};
+
+struct MyType { using Float=float; };
+Foobar::Inner<0> foobar;

``




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


[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)

2024-03-10 Thread Qizhi Hu via cfe-commits

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

Try to fix https://github.com/llvm/llvm-project/issues/84368
[temp.friend]p1:
Similarly, each specialization of the `task` class template has the class 
template
specialization `task` as a friend, and has all specializations of the 
class template `frd` as friends.

>From 9abe798955b0db77e12f0aec43cd23926a2b4744 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 10 Mar 2024 16:11:18 +0800
Subject: [PATCH] [Clang][Sema] Fix a bug on type constraint checking

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  1 +
 clang/test/Sema/PR84368.cpp| 16 
 3 files changed, 19 insertions(+)
 create mode 100644 clang/test/Sema/PR84368.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..b32e739288dbc5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,8 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Fix a bug on type constraint checking (#GH84368). 
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 20c2c93ac9c7b4..765c5bc689ae1e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1698,6 +1698,7 @@ Decl 
*TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 assert(!Owner->isDependentContext());
 Inst->setLexicalDeclContext(Owner);
 RecordInst->setLexicalDeclContext(Owner);
+Inst->setObjectOfFriendDecl();
 
 if (PrevClassTemplate) {
   Inst->setCommonPtr(PrevClassTemplate->getCommonPtr());
diff --git a/clang/test/Sema/PR84368.cpp b/clang/test/Sema/PR84368.cpp
new file mode 100644
index 00..073530ffd8abea
--- /dev/null
+++ b/clang/test/Sema/PR84368.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
+// expected-no-diagnostics
+
+template concept IsOk = requires() { typename T::Float; };
+
+template struct Thing;
+
+template struct Foobar {
+   template struct Inner {
+   template friend struct Thing;
+   };
+};
+
+struct MyType { using Float=float; };
+Foobar::Inner<0> foobar;

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