[libcxx] [flang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [clang] [libcxxabi] [lld] [lldb] [mlir] [Mips] Fix unable to handle inline assembly ends with compat-branch o… (PR #77291)

2024-02-04 Thread via cfe-commits

yingopq wrote:

> What assembly does GCC emit, and how does GNU as deal with that assembly? 
> That is, how do those two tools interact in the GNU world when dealing with 
> forbidden slots?

All results were same: add nop after beqzc.
```
$ cat a.s
.set reorder
bbb:
beqzc $t1, bbb
b bbb
$ sudo mipsel-linux-gnu-as -mips32r6 a.s
$ mipsel-linux-gnu-objdump -d a.out

a.out: file format elf32-tradlittlemips


Disassembly of section .text:

 :
   0:   d93fbeqzc   t1,0 
   4:   nop
   8:   1000b   8 
   c:   nop
```

and
```
$ sudo mipsel-linux-gnu-gcc -mips32r6 -c a.s -o hello.o
$ mipsel-linux-gnu-objdump -d hello.o 

hello.o: file format elf32-tradlittlemips


Disassembly of section .text:

 :
   0:   d93fbeqzc   t1,0 
   4:   nop
   8:   1000b   8 
   c:   nop
```

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


[libcxx] [flang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [clang] [libcxxabi] [lld] [lldb] [mlir] [Mips] Fix unable to handle inline assembly ends with compat-branch o… (PR #77291)

2024-02-04 Thread via cfe-commits

yingopq wrote:

> What assembly does GCC emit, and how does GNU as deal with that assembly? 
> That is, how do those two tools interact in the GNU world when dealing with 
> forbidden slots?

All results were same: add nop after beqzc.
```
$ cat a.s
.set reorder
bbb:
beqzc $t1, bbb
b bbb
$ sudo mipsel-linux-gnu-as -mips32r6 a.s
$ mipsel-linux-gnu-objdump -d a.out

a.out: file format elf32-tradlittlemips


Disassembly of section .text:

 :
   0:   d93fbeqzc   t1,0 
   4:   nop
   8:   1000b   8 
   c:   nop
```

and
```
$ sudo mipsel-linux-gnu-gcc -mips32r6 -c a.s -o hello.o
$ mipsel-linux-gnu-objdump -d hello.o 

hello.o: file format elf32-tradlittlemips


Disassembly of section .text:

 :
   0:   d93fbeqzc   t1,0 
   4:   nop
   8:   1000b   8 
   c:   nop
```

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


[llvm] [clang-tools-extra] [compiler-rt] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Phoebe Wang via cfe-commits


@@ -139,20 +139,79 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+  // Below Features has many missings comparing to gcc, it's because gcc has
+  // some LLVM doesn't include, e.g. FEATURE_ABM, FEATURE_HLE, ...
+  FEATURE_3DNOW,
+  FEATURE_ADX = 40,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+
+  FEATURE_ENQCMD = 48,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,

phoebewang wrote:

Oh, you are right. The 2 features map to two CPUID bits in SDM

> Bit 07: CET_SS. Supports CET shadow stack features if 1. Processors that set 
> this bit define bits 1:0
> of the IA32_U_CET and IA32_S_CET MSRs. Enumerates support for the following 
> MSRs: IA32_INTERRUPT_SPP_TABLE_ADDR, IA32_PL3_SSP, IA32_PL2_SSP, 
> IA32_PL1_SSP, and IA32_PL0_SSP.

> Bit 20: CET_IBT. Supports CET indirect branch tracking features if 1. 
> Processors that set this bit
> define bits 5:2 and bits 63:10 of the IA32_U_CET and IA32_S_CET MSRs.











































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


[clang] [clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (PR #79549)

2024-02-04 Thread Owen Pan via cfe-commits

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


[llvm] [clang-tools-extra] [compiler-rt] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Phoebe Wang via cfe-commits


@@ -139,20 +139,88 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
-
-  FEATURE_CMPXCHG16B = 46,
-  FEATURE_F16C = 49,
+  // FIXME: Below Features has some missings comparing to gcc, it's because gcc
+  // has some not one-to-one mapped in llvm.
+  FEATURE_3DNOW,
+  // FEATURE_3DNOWP,
+  FEATURE_ADX = 40,
+  // FEATURE_ABM,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+  // FIXME: Not adding FEATURE_CMPXCHG8B is a workaround to make 'generic' as
+  // a cpu string with no X86_FEATURE_COMPAT features, which is required in
+  // current implementantion of cpu_specific/cpu_dispatch FMV feature.
+  // FEATURE_CMPXCHG8B,
+  FEATURE_ENQCMD = 48,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,
+  // FEATURE_FXSAVE,
+  // FEATURE_HLE,
+  // FEATURE_IBT,
   FEATURE_LAHF_LM = 54,
   FEATURE_LM,
-  FEATURE_WP,
+  FEATURE_LWP,
   FEATURE_LZCNT,
   FEATURE_MOVBE,
-
-  FEATURE_AVX512FP16 = 94,
+  FEATURE_MOVDIR64B,
+  FEATURE_MOVDIRI,
+  FEATURE_MWAITX,
+  // FEATURE_OSXSAVE,
+  FEATURE_PCONFIG = 63,
+  FEATURE_PKU,
+  FEATURE_PREFETCHWT1,
+  FEATURE_PRFCHW,
+  FEATURE_PTWRITE,
+  FEATURE_RDPID,
+  FEATURE_RDRND,
+  FEATURE_RDSEED,
+  FEATURE_RTM,
+  FEATURE_SERIALIZE,
+  FEATURE_SGX,
+  FEATURE_SHA,
+  FEATURE_SHSTK,
+  FEATURE_TBM,
+  FEATURE_TSXLDTRK,
+  FEATURE_VAES,
+  FEATURE_WAITPKG,
+  FEATURE_WBNOINVD,
+  FEATURE_XSAVE,
+  FEATURE_XSAVEC,
+  FEATURE_XSAVEOPT,
+  FEATURE_XSAVES,
+  FEATURE_AMX_TILE,
+  FEATURE_AMX_INT8,
+  FEATURE_AMX_BF16,
+  FEATURE_UINTR,
+  FEATURE_HRESET,
+  FEATURE_KL,
+  // FEATURE_AESKLE,
+  FEATURE_WIDEKL = 92,
+  FEATURE_AVXVNNI,
+  FEATURE_AVX512FP16,
   FEATURE_X86_64_BASELINE,
   FEATURE_X86_64_V2,
   FEATURE_X86_64_V3,
   FEATURE_X86_64_V4,
+  FEATURE_AVXIFMA,
+  FEATURE_AVXVNNIINT8,
+  FEATURE_AVXNECONVERT,
+  FEATURE_CMPCCXADD,
+  FEATURE_AMX_FP16,
+  FEATURE_PREFETCHI,
+  FEATURE_RAOINT,
+  FEATURE_AMX_COMPLEX,
+  FEATURE_AVXVNNIINT16,
+  FEATURE_SM3,
+  FEATURE_SHA512,
+  FEATURE_SM4,
+  // FEATURE_APX_F,
+  FEATURE_USERMSR = 112,
+  // FEATURE_AVX10_1_256,
+  // FEATURE_AVX10_1_512,

phoebewang wrote:

Why comments them? We have APX and AVX10 support.

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


[clang] [clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (PR #79549)

2024-02-04 Thread Owen Pan via cfe-commits

owenca wrote:

/cherry-pick f826f55b2ab6

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


[clang] [clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (PR #79549)

2024-02-04 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#80591

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


[clang] [clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (PR #79549)

2024-02-04 Thread Owen Pan via cfe-commits

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


[clang-tools-extra] [compiler-rt] [clang] [llvm] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/79086

>From b5c8579c5c8e7ea1e8436348bbf60ecee9c3c799 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 19 Jan 2024 09:22:27 +0800
Subject: [PATCH 1/7] [X86] Support more ISAs to enable __builtin_cpu_supports

This patch will also expand supports for attribute/target, while
the priority of newly supported ISAs will be set to zero.
---
 clang/test/CodeGen/target-builtin-noerror.c   |  59 +
 compiler-rt/lib/builtins/cpu_model/x86.c  | 209 +-
 .../llvm/TargetParser/X86TargetParser.def | 135 ++-
 3 files changed, 324 insertions(+), 79 deletions(-)

diff --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 06bb40a2b71ea..16097fa08cb9c 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -84,6 +84,65 @@ void verifyfeaturestrings(void) {
   (void)__builtin_cpu_supports("avx512vp2intersect");
   (void)__builtin_cpu_supports("f16c");
   (void)__builtin_cpu_supports("avx512fp16");
+  (void)__builtin_cpu_supports("3dnow");
+  (void)__builtin_cpu_supports("adx");
+  (void)__builtin_cpu_supports("cldemote");
+  (void)__builtin_cpu_supports("clflushopt");
+  (void)__builtin_cpu_supports("clwb");
+  (void)__builtin_cpu_supports("clzero");
+  (void)__builtin_cpu_supports("cx16");
+  (void)__builtin_cpu_supports("cx8");
+  (void)__builtin_cpu_supports("enqcmd");
+  (void)__builtin_cpu_supports("fsgsbase");
+  (void)__builtin_cpu_supports("lwp");
+  (void)__builtin_cpu_supports("lzcnt");
+  (void)__builtin_cpu_supports("movbe");
+  (void)__builtin_cpu_supports("movdir64b");
+  (void)__builtin_cpu_supports("movdiri");
+  (void)__builtin_cpu_supports("mwaitx");
+  (void)__builtin_cpu_supports("pconfig");
+  (void)__builtin_cpu_supports("pku");
+  (void)__builtin_cpu_supports("prefetchwt1");
+  (void)__builtin_cpu_supports("prfchw");
+  (void)__builtin_cpu_supports("ptwrite");
+  (void)__builtin_cpu_supports("rdpid");
+  (void)__builtin_cpu_supports("rdrnd");
+  (void)__builtin_cpu_supports("rdseed");
+  (void)__builtin_cpu_supports("rtm");
+  (void)__builtin_cpu_supports("serialize");
+  (void)__builtin_cpu_supports("sgx");
+  (void)__builtin_cpu_supports("sha");
+  (void)__builtin_cpu_supports("shstk");
+  (void)__builtin_cpu_supports("tbm");
+  (void)__builtin_cpu_supports("tsxldtrk");
+  (void)__builtin_cpu_supports("vaes");
+  (void)__builtin_cpu_supports("waitpkg");
+  (void)__builtin_cpu_supports("wbnoinvd");
+  (void)__builtin_cpu_supports("xsave");
+  (void)__builtin_cpu_supports("xsavec");
+  (void)__builtin_cpu_supports("xsaveopt");
+  (void)__builtin_cpu_supports("xsaves");
+  (void)__builtin_cpu_supports("amx-tile");
+  (void)__builtin_cpu_supports("amx-int8");
+  (void)__builtin_cpu_supports("amx-bf16");
+  (void)__builtin_cpu_supports("uintr");
+  (void)__builtin_cpu_supports("hreset");
+  (void)__builtin_cpu_supports("kl");
+  (void)__builtin_cpu_supports("widekl");
+  (void)__builtin_cpu_supports("avxvnni");
+  (void)__builtin_cpu_supports("avxifma");
+  (void)__builtin_cpu_supports("avxvnniint8");
+  (void)__builtin_cpu_supports("avxneconvert");
+  (void)__builtin_cpu_supports("cmpccxadd");
+  (void)__builtin_cpu_supports("amx-fp16");
+  (void)__builtin_cpu_supports("prefetchi");
+  (void)__builtin_cpu_supports("raoint");
+  (void)__builtin_cpu_supports("amx-complex");
+  (void)__builtin_cpu_supports("avxvnniint16");
+  (void)__builtin_cpu_supports("sm3");
+  (void)__builtin_cpu_supports("sha512");
+  (void)__builtin_cpu_supports("sm4");
+  (void)__builtin_cpu_supports("usermsr");
 }
 
 void verifycpustrings(void) {
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c 
b/compiler-rt/lib/builtins/cpu_model/x86.c
index 0750e29f989a8..c499754890343 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -139,20 +139,77 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+  FEATURE_3DNOW,
+  FEATURE_ADX = 40,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+  FEATURE_CMPXCHG8B,
+  FEATURE_ENQCMD,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,
 
-  FEATURE_CMPXCHG16B = 46,
-  FEATURE_F16C = 49,
   FEATURE_LAHF_LM = 54,
   FEATURE_LM,
-  FEATURE_WP,
+  FEATURE_LWP,
   FEATURE_LZCNT,
   FEATURE_MOVBE,
-
-  FEATURE_AVX512FP16 = 94,
+  FEATURE_MOVDIR64B,
+  FEATURE_MOVDIRI,
+  FEATURE_MWAITX,
+
+  FEATURE_PCONFIG = 63,
+  FEATURE_PKU,
+  FEATURE_PREFETCHWT1,
+  FEATURE_PRFCHW,
+  FEATURE_PTWRITE,
+  FEATURE_RDPID,
+  FEATURE_RDRND,
+  FEATURE_RDSEED,
+  FEATURE_RTM,
+  FEATURE_SERIALIZE,
+  FEATURE_SGX,
+  FEATURE_SHA,
+  FEATURE_SHSTK,
+  FEATURE_TBM,
+  FEATURE_TSXLDTRK,
+  FEATURE_VAES,
+  FEATURE_WAITPKG,
+  FEATURE_WBNOINVD,
+  FEATURE_XSAVE,
+  FEATURE_XSAVEC,
+  FEATURE_XSAVEOPT,
+  FEATURE_XSAVES,
+  FEATURE_AMX_TILE,
+  FEATURE_AMX

[clang-tools-extra] [compiler-rt] [clang] [llvm] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits


@@ -139,20 +139,88 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
-
-  FEATURE_CMPXCHG16B = 46,
-  FEATURE_F16C = 49,
+  // FIXME: Below Features has some missings comparing to gcc, it's because gcc
+  // has some not one-to-one mapped in llvm.
+  FEATURE_3DNOW,
+  // FEATURE_3DNOWP,
+  FEATURE_ADX = 40,
+  // FEATURE_ABM,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+  // FIXME: Not adding FEATURE_CMPXCHG8B is a workaround to make 'generic' as
+  // a cpu string with no X86_FEATURE_COMPAT features, which is required in
+  // current implementantion of cpu_specific/cpu_dispatch FMV feature.
+  // FEATURE_CMPXCHG8B,
+  FEATURE_ENQCMD = 48,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,
+  // FEATURE_FXSAVE,
+  // FEATURE_HLE,
+  // FEATURE_IBT,
   FEATURE_LAHF_LM = 54,
   FEATURE_LM,
-  FEATURE_WP,
+  FEATURE_LWP,
   FEATURE_LZCNT,
   FEATURE_MOVBE,
-
-  FEATURE_AVX512FP16 = 94,
+  FEATURE_MOVDIR64B,
+  FEATURE_MOVDIRI,
+  FEATURE_MWAITX,
+  // FEATURE_OSXSAVE,
+  FEATURE_PCONFIG = 63,
+  FEATURE_PKU,
+  FEATURE_PREFETCHWT1,
+  FEATURE_PRFCHW,
+  FEATURE_PTWRITE,
+  FEATURE_RDPID,
+  FEATURE_RDRND,
+  FEATURE_RDSEED,
+  FEATURE_RTM,
+  FEATURE_SERIALIZE,
+  FEATURE_SGX,
+  FEATURE_SHA,
+  FEATURE_SHSTK,
+  FEATURE_TBM,
+  FEATURE_TSXLDTRK,
+  FEATURE_VAES,
+  FEATURE_WAITPKG,
+  FEATURE_WBNOINVD,
+  FEATURE_XSAVE,
+  FEATURE_XSAVEC,
+  FEATURE_XSAVEOPT,
+  FEATURE_XSAVES,
+  FEATURE_AMX_TILE,
+  FEATURE_AMX_INT8,
+  FEATURE_AMX_BF16,
+  FEATURE_UINTR,
+  FEATURE_HRESET,
+  FEATURE_KL,
+  // FEATURE_AESKLE,
+  FEATURE_WIDEKL = 92,
+  FEATURE_AVXVNNI,
+  FEATURE_AVX512FP16,
   FEATURE_X86_64_BASELINE,
   FEATURE_X86_64_V2,
   FEATURE_X86_64_V3,
   FEATURE_X86_64_V4,
+  FEATURE_AVXIFMA,
+  FEATURE_AVXVNNIINT8,
+  FEATURE_AVXNECONVERT,
+  FEATURE_CMPCCXADD,
+  FEATURE_AMX_FP16,
+  FEATURE_PREFETCHI,
+  FEATURE_RAOINT,
+  FEATURE_AMX_COMPLEX,
+  FEATURE_AVXVNNIINT16,
+  FEATURE_SM3,
+  FEATURE_SHA512,
+  FEATURE_SM4,
+  // FEATURE_APX_F,
+  FEATURE_USERMSR = 112,
+  // FEATURE_AVX10_1_256,
+  // FEATURE_AVX10_1_512,

FreddyLeaf wrote:

addressed in 770ed9a

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


[clang] [clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (PR #79549)

2024-02-04 Thread Owen Pan via cfe-commits

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


[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread Ruihua Dong via cfe-commits

https://github.com/144026 created 
https://github.com/llvm/llvm-project/pull/80592

Extract directive branches information from DirectiveTree, fold branches that 
don't end with eof.

Fixes https://github.com/clangd/clangd/issues/1661

Examples:

Folded: 
https://github.com/llvm/llvm-project/assets/44112701/c5b7ab39-7371-47f8-9d0d-29f11dbc9a1f";>

Unfolded:
https://github.com/llvm/llvm-project/assets/44112701/6bfcb325-26b1-4435-9e3d-f2deed8136ef";>

Folded (unpaired conditionals):
https://github.com/llvm/llvm-project/assets/44112701/fdddfcf8-866f-4ab7-b8a7-6848f9bee0de";>

Unfolded (unpaired conditionals):
https://github.com/llvm/llvm-project/assets/44112701/090a9f31-69d7-41de-ba45-54f86196da9f";>





>From 24e5e2c2703a54b10be654d11c1a1d100d9c7a14 Mon Sep 17 00:00:00 2001
From: Ruihua Dong 
Date: Sun, 4 Feb 2024 16:39:22 +0800
Subject: [PATCH] [clangd] Implement simple folding of preprocessor branches

Extract directive branches information from DirectiveTree, fold branches
that don't end with eof.

Fixes https://github.com/clangd/clangd/issues/1661
---
 .../clangd/SemanticSelection.cpp  | 18 +++
 .../include/clang-pseudo/DirectiveTree.h  |  3 ++
 .../pseudo/lib/DirectiveTree.cpp  | 54 +++
 3 files changed, 75 insertions(+)

diff --git a/clang-tools-extra/clangd/SemanticSelection.cpp 
b/clang-tools-extra/clangd/SemanticSelection.cpp
index 3d687173b2be9..d2aefb51fd49a 100644
--- a/clang-tools-extra/clangd/SemanticSelection.cpp
+++ b/clang-tools-extra/clangd/SemanticSelection.cpp
@@ -220,6 +220,24 @@ getFoldingRanges(const std::string &Code, bool 
LineFoldingOnly) {
   auto EndPosition = [&](const pseudo::Token &T) {
 return offsetToPosition(Code, EndOffset(T));
   };
+
+  // Preprocessor directives
+  auto PPRanges = pseudo::pairDirectiveRanges(DirectiveStructure, OrigStream);
+  for (const auto &R : PPRanges) {
+auto BTok = OrigStream.tokens()[R.Begin];
+auto ETok = OrigStream.tokens()[R.End];
+if (ETok.Kind == tok::eof)
+  continue;
+if (BTok.Line >= ETok.Line)
+  continue;
+
+Position Start = EndPosition(BTok);
+Position End = StartPosition(ETok);
+if (LineFoldingOnly)
+  End.line--;
+AddFoldingRange(Start, End, FoldingRange::REGION_KIND);
+  }
+
   auto Tokens = ParseableStream.tokens();
   // Brackets.
   for (const auto &Tok : Tokens) {
diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
index 2b6cb63297915..2e5f007f94a76 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
@@ -124,6 +124,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
 /// The choices are stored in Conditional::Taken nodes.
 void chooseConditionalBranches(DirectiveTree &, const TokenStream &Code);
 
+std::vector pairDirectiveRanges(const DirectiveTree &Tree,
+  const TokenStream &Code);
+
 } // namespace pseudo
 } // namespace clang
 
diff --git a/clang-tools-extra/pseudo/lib/DirectiveTree.cpp 
b/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
index 9e853e46edc23..4882f01890654 100644
--- a/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
+++ b/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
@@ -353,5 +353,59 @@ TokenStream DirectiveTree::stripDirectives(const 
TokenStream &In) const {
   return Out;
 }
 
+namespace {
+class RangePairer {
+  std::vector &Ranges;
+
+public:
+  RangePairer(std::vector &Ranges) : Ranges(Ranges) {}
+
+  void walk(const DirectiveTree &T) {
+for (const auto &C : T.Chunks)
+  std::visit(*this, C);
+  }
+
+  void operator()(const DirectiveTree::Code &C) {}
+
+  void operator()(const DirectiveTree::Directive &) {}
+
+  void operator()(const DirectiveTree::Conditional &C) {
+Token::Range Range;
+Token::Index Last;
+auto First = true;
+for (const auto &B : C.Branches) {
+  if (First) {
+First = false;
+  } else {
+Range = {Last, B.first.Tokens.Begin};
+Ranges.push_back(Range);
+  }
+  Last = B.first.Tokens.Begin;
+}
+Range = {Last, C.End.Tokens.Begin};
+Ranges.push_back(Range);
+
+for (const auto &B : C.Branches)
+  walk(B.second);
+  }
+};
+} // namespace
+
+std::vector pairDirectiveRanges(const DirectiveTree &Tree,
+  const TokenStream &Code) {
+  std::vector Ranges;
+  RangePairer(Ranges).walk(Tree);
+
+  // Transform paired ranges to start with last token in its logical line
+  for (auto &R : Ranges) {
+const Token *Tok = &Code.tokens()[R.Begin + 1];
+while (Tok->Kind != tok::eof && !Tok->flag(LexFlags::StartsPPLine))
+  ++Tok;
+Tok = Tok - 1;
+R.Begin = Tok->OriginalIndex;
+  }
+  return std::move(Ranges);
+}
+
 } // namespace pseudo
 } // namespace clang

___
cfe-commits mailing list
cfe-commits@lis

[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Ruihua Dong (144026)


Changes

Extract directive branches information from DirectiveTree, fold branches that 
don't end with eof.

Fixes https://github.com/clangd/clangd/issues/1661

Examples:

Folded: 
image;

Unfolded:
image;

Folded (unpaired conditionals):
image;

Unfolded (unpaired conditionals):
image;





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


3 Files Affected:

- (modified) clang-tools-extra/clangd/SemanticSelection.cpp (+18) 
- (modified) clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h (+3) 
- (modified) clang-tools-extra/pseudo/lib/DirectiveTree.cpp (+54) 


``diff
diff --git a/clang-tools-extra/clangd/SemanticSelection.cpp 
b/clang-tools-extra/clangd/SemanticSelection.cpp
index 3d687173b2be9..d2aefb51fd49a 100644
--- a/clang-tools-extra/clangd/SemanticSelection.cpp
+++ b/clang-tools-extra/clangd/SemanticSelection.cpp
@@ -220,6 +220,24 @@ getFoldingRanges(const std::string &Code, bool 
LineFoldingOnly) {
   auto EndPosition = [&](const pseudo::Token &T) {
 return offsetToPosition(Code, EndOffset(T));
   };
+
+  // Preprocessor directives
+  auto PPRanges = pseudo::pairDirectiveRanges(DirectiveStructure, OrigStream);
+  for (const auto &R : PPRanges) {
+auto BTok = OrigStream.tokens()[R.Begin];
+auto ETok = OrigStream.tokens()[R.End];
+if (ETok.Kind == tok::eof)
+  continue;
+if (BTok.Line >= ETok.Line)
+  continue;
+
+Position Start = EndPosition(BTok);
+Position End = StartPosition(ETok);
+if (LineFoldingOnly)
+  End.line--;
+AddFoldingRange(Start, End, FoldingRange::REGION_KIND);
+  }
+
   auto Tokens = ParseableStream.tokens();
   // Brackets.
   for (const auto &Tok : Tokens) {
diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
index 2b6cb63297915..2e5f007f94a76 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
@@ -124,6 +124,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
 /// The choices are stored in Conditional::Taken nodes.
 void chooseConditionalBranches(DirectiveTree &, const TokenStream &Code);
 
+std::vector pairDirectiveRanges(const DirectiveTree &Tree,
+  const TokenStream &Code);
+
 } // namespace pseudo
 } // namespace clang
 
diff --git a/clang-tools-extra/pseudo/lib/DirectiveTree.cpp 
b/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
index 9e853e46edc23..4882f01890654 100644
--- a/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
+++ b/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
@@ -353,5 +353,59 @@ TokenStream DirectiveTree::stripDirectives(const 
TokenStream &In) const {
   return Out;
 }
 
+namespace {
+class RangePairer {
+  std::vector &Ranges;
+
+public:
+  RangePairer(std::vector &Ranges) : Ranges(Ranges) {}
+
+  void walk(const DirectiveTree &T) {
+for (const auto &C : T.Chunks)
+  std::visit(*this, C);
+  }
+
+  void operator()(const DirectiveTree::Code &C) {}
+
+  void operator()(const DirectiveTree::Directive &) {}
+
+  void operator()(const DirectiveTree::Conditional &C) {
+Token::Range Range;
+Token::Index Last;
+auto First = true;
+for (const auto &B : C.Branches) {
+  if (First) {
+First = false;
+  } else {
+Range = {Last, B.first.Tokens.Begin};
+Ranges.push_back(Range);
+  }
+  Last = B.first.Tokens.Begin;
+}
+Range = {Last, C.End.Tokens.Begin};
+Ranges.push_back(Range);
+
+for (const auto &B : C.Branches)
+  walk(B.second);
+  }
+};
+} // namespace
+
+std::vector pairDirectiveRanges(const DirectiveTree &Tree,
+  const TokenStream &Code) {
+  std::vector Ranges;
+  RangePairer(Ranges).walk(Tree);
+
+  // Transform paired ranges to start with last token in its logical line
+  for (auto &R : Ranges) {
+const Token *Tok = &Code.tokens()[R.Begin + 1];
+while (Tok->Kind != tok::eof && !Tok->flag(LexFlags::StartsPPLine))
+  ++Tok;
+Tok = Tok - 1;
+R.Begin = Tok->OriginalIndex;
+  }
+  return std::move(Ranges);
+}
+
 } // namespace pseudo
 } // namespace clang

``




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

[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread via cfe-commits

llvmbot wrote:




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

Author: Ruihua Dong (144026)


Changes

Extract directive branches information from DirectiveTree, fold branches that 
don't end with eof.

Fixes https://github.com/clangd/clangd/issues/1661

Examples:

Folded: 
image;

Unfolded:
image;

Folded (unpaired conditionals):
image;

Unfolded (unpaired conditionals):
image;





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


3 Files Affected:

- (modified) clang-tools-extra/clangd/SemanticSelection.cpp (+18) 
- (modified) clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h (+3) 
- (modified) clang-tools-extra/pseudo/lib/DirectiveTree.cpp (+54) 


``diff
diff --git a/clang-tools-extra/clangd/SemanticSelection.cpp 
b/clang-tools-extra/clangd/SemanticSelection.cpp
index 3d687173b2be9..d2aefb51fd49a 100644
--- a/clang-tools-extra/clangd/SemanticSelection.cpp
+++ b/clang-tools-extra/clangd/SemanticSelection.cpp
@@ -220,6 +220,24 @@ getFoldingRanges(const std::string &Code, bool 
LineFoldingOnly) {
   auto EndPosition = [&](const pseudo::Token &T) {
 return offsetToPosition(Code, EndOffset(T));
   };
+
+  // Preprocessor directives
+  auto PPRanges = pseudo::pairDirectiveRanges(DirectiveStructure, OrigStream);
+  for (const auto &R : PPRanges) {
+auto BTok = OrigStream.tokens()[R.Begin];
+auto ETok = OrigStream.tokens()[R.End];
+if (ETok.Kind == tok::eof)
+  continue;
+if (BTok.Line >= ETok.Line)
+  continue;
+
+Position Start = EndPosition(BTok);
+Position End = StartPosition(ETok);
+if (LineFoldingOnly)
+  End.line--;
+AddFoldingRange(Start, End, FoldingRange::REGION_KIND);
+  }
+
   auto Tokens = ParseableStream.tokens();
   // Brackets.
   for (const auto &Tok : Tokens) {
diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
index 2b6cb63297915..2e5f007f94a76 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveTree.h
@@ -124,6 +124,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
 /// The choices are stored in Conditional::Taken nodes.
 void chooseConditionalBranches(DirectiveTree &, const TokenStream &Code);
 
+std::vector pairDirectiveRanges(const DirectiveTree &Tree,
+  const TokenStream &Code);
+
 } // namespace pseudo
 } // namespace clang
 
diff --git a/clang-tools-extra/pseudo/lib/DirectiveTree.cpp 
b/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
index 9e853e46edc23..4882f01890654 100644
--- a/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
+++ b/clang-tools-extra/pseudo/lib/DirectiveTree.cpp
@@ -353,5 +353,59 @@ TokenStream DirectiveTree::stripDirectives(const 
TokenStream &In) const {
   return Out;
 }
 
+namespace {
+class RangePairer {
+  std::vector &Ranges;
+
+public:
+  RangePairer(std::vector &Ranges) : Ranges(Ranges) {}
+
+  void walk(const DirectiveTree &T) {
+for (const auto &C : T.Chunks)
+  std::visit(*this, C);
+  }
+
+  void operator()(const DirectiveTree::Code &C) {}
+
+  void operator()(const DirectiveTree::Directive &) {}
+
+  void operator()(const DirectiveTree::Conditional &C) {
+Token::Range Range;
+Token::Index Last;
+auto First = true;
+for (const auto &B : C.Branches) {
+  if (First) {
+First = false;
+  } else {
+Range = {Last, B.first.Tokens.Begin};
+Ranges.push_back(Range);
+  }
+  Last = B.first.Tokens.Begin;
+}
+Range = {Last, C.End.Tokens.Begin};
+Ranges.push_back(Range);
+
+for (const auto &B : C.Branches)
+  walk(B.second);
+  }
+};
+} // namespace
+
+std::vector pairDirectiveRanges(const DirectiveTree &Tree,
+  const TokenStream &Code) {
+  std::vector Ranges;
+  RangePairer(Ranges).walk(Tree);
+
+  // Transform paired ranges to start with last token in its logical line
+  for (auto &R : Ranges) {
+const Token *Tok = &Code.tokens()[R.Begin + 1];
+while (Tok->Kind != tok::eof && !Tok->flag(LexFlags::StartsPPLine))
+  ++Tok;
+Tok = Tok - 1;
+R.Begin = Tok->OriginalIndex;
+  }
+  return std::move(Ranges);
+}
+
 } // namespace pseudo
 } // namespace clang

``




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

[clang] [compiler-rt] [clang-tools-extra] [llvm] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Phoebe Wang via cfe-commits


@@ -217,10 +217,11 @@ enum ProcessorFeatures {
   FEATURE_SM3,
   FEATURE_SHA512,
   FEATURE_SM4,
-  // FEATURE_APX_F,
-  FEATURE_USERMSR = 112,
-  // FEATURE_AVX10_1_256,
-  // FEATURE_AVX10_1_512,
+  //FIXME: gcc used string "apxf" instead of "egpr"

phoebewang wrote:

The internal name is not important, so do not need a FIXME if we won't fix it.
I'm more concerning about the name in `(void)__builtin_cpu_supports("egpr");`
Does GCC use `egpr` too? Or we should change to "apxf"?

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


[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Note that clang-pseudo is deprecated and will soon get 
[removed](https://github.com/llvm/llvm-project/pull/80081) from the repository. 
I have no idea about the replacement, and I'm not sure if it makes sense to 
evolve the feature with it. 

I invited some folks (who may be in charge of clang-pseudo) for visibility.

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


[clang] [compiler-rt] [clang-tools-extra] [llvm] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Shengchen Kan via cfe-commits


@@ -217,10 +217,11 @@ enum ProcessorFeatures {
   FEATURE_SM3,
   FEATURE_SHA512,
   FEATURE_SM4,
-  // FEATURE_APX_F,
-  FEATURE_USERMSR = 112,
-  // FEATURE_AVX10_1_256,
-  // FEATURE_AVX10_1_512,
+  //FIXME: gcc used string "apxf" instead of "egpr"

KanRobert wrote:

GCC is using "apxf ". I believe we need to discuss with GCC team about this.

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


[compiler-rt] [llvm] [clang] [clang-tools-extra] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits


@@ -217,10 +217,11 @@ enum ProcessorFeatures {
   FEATURE_SM3,
   FEATURE_SHA512,
   FEATURE_SM4,
-  // FEATURE_APX_F,
-  FEATURE_USERMSR = 112,
-  // FEATURE_AVX10_1_256,
-  // FEATURE_AVX10_1_512,
+  //FIXME: gcc used string "apxf" instead of "egpr"

FreddyLeaf wrote:

Yes, the concern is from that gcc use `apxf` but not `egpr`. I don't think 
adding one more line like this is complete safe. I prefer to not touch APX firs 
and refine it in another PR, WDYT?
```
X86_FEATURE_COMPAT(EGPR,"apxf",   0)
```

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


[clang] [Clang] Fix a crash when dumping a pack indexing type. (PR #80439)

2024-02-04 Thread Björn Pettersson via cfe-commits

bjope wrote:

Seems like this didn't really solve the problem reported by @bevin-hansson (at 
least not completely).
The new test case fails for us:

```
FAIL: Clang :: AST/ast-dump-pack-indexing-crash.cpp (401 of 78930)
 TEST 'Clang :: AST/ast-dump-pack-indexing-crash.cpp' 
FAILED 
Exit Code: 2

Command Output (stderr):
--
RUN: at line 1: not /build/bin/clang -cc1 -internal-isystem 
/build/lib/clang/19/include -nostdsysteminc -std=c++2c -ast-dump 
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp | 
/build/bin/FileCheck  
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp
+ not /build/bin/clang -cc1 -internal-isystem /build/lib/clang/19/include 
-nostdsysteminc -std=c++2c -ast-dump 
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp
+ /build/bin/FileCheck 
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:9:5: error: i 
does not refer to the name of a parameter pack
9 | i...[0]; // expected-error {{i does not refer to the name of a 
parameter pack}}
  | ^
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:10:5: error: V 
does not refer to the name of a parameter pack
   10 | V...[0]; // expected-error {{V does not refer to the name of a 
parameter pack}}
  | ^
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:11:5: error: 
'NotAPack' does not refer to the name of a parameter pack
   11 | NotAPack...[0] a; // expected-error{{'NotAPack' does not refer to 
the name of a parameter pack}}
  | ^
Stack dump:
0.  Program arguments: /build/bin/clang -cc1 -internal-isystem 
/build/lib/clang/19/include -nostdsysteminc -std=c++2c -ast-dump 
/llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp
1.  /llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:11:21: 
current parser token ';'
2.  /llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:3:1: 
parsing namespace 'InvalidPacksShouldNotCrash'
3.  /llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:7:17: 
parsing function body 'InvalidPacksShouldNotCrash::not_pack'
4.  /llvm-project/clang/test/AST/ast-dump-pack-indexing-crash.cpp:7:17: in 
compound statement ('{}')
  #0 0x03b147c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/build/bin/clang+0x3b147c8)
  #1 0x03b11f1c SignalHandler(int) Signals.cpp:0:0
  #2 0x7f49db4aa630 __restore_rt sigaction.c:0:0
  #3 0x071e19f0 clang::PackIndexingType::getSelectedIndex() const 
(.part.0) Type.cpp:0:0
  #4 0x06c9e257 clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e257)
  #5 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
  #6 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
  #7 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
  #8 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
  #9 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #10 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #11 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #12 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #13 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #14 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #15 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #16 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #17 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #18 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #19 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #20 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #21 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #22 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #23 0x06c86ca7 clang::ASTContext::getTypeInfo(clang::Type const*) 
const (/build/bin/clang+0x6c86ca7)
 #24 0x06c9e21b clang::ASTContext::getTypeInfoImpl(clang::Type const*) 
const (/build/bin/clang+0x6c9e21b)
 #25

[compiler-rt] [llvm] [clang] [clang-tools-extra] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Shengchen Kan via cfe-commits


@@ -173,85 +173,86 @@ X86_FEATURE_COMPAT(AVX512VNNI,  "avx512vnni", 
   34)
 X86_FEATURE_COMPAT(AVX512BITALG,"avx512bitalg",  35)
 X86_FEATURE_COMPAT(AVX512BF16,  "avx512bf16",36)
 X86_FEATURE_COMPAT(AVX512VP2INTERSECT, "avx512vp2intersect", 37)
-// Features below here are not in libgcc/compiler-rt.
-X86_FEATURE   (3DNOW,   "3dnow")
+// Below Features has some missings comparing to gcc, it's because gcc has some
+// not one-to-one mapped in llvm.
+X86_FEATURE_COMPAT(3DNOW,   "3dnow",  0)
 X86_FEATURE   (3DNOWA,  "3dnowa")
+X86_FEATURE_COMPAT(ADX, "adx",0)
 X86_FEATURE   (64BIT,   "64bit")
-X86_FEATURE   (ADX, "adx")
-X86_FEATURE   (AMX_BF16,"amx-bf16")
-X86_FEATURE   (AMX_COMPLEX, "amx-complex")
-X86_FEATURE   (AMX_INT8,"amx-int8")
-X86_FEATURE   (AMX_TILE,"amx-tile")
-X86_FEATURE   (CLDEMOTE,"cldemote")
-X86_FEATURE   (CLFLUSHOPT,  "clflushopt")
-X86_FEATURE   (CLWB,"clwb")
-X86_FEATURE_COMPAT(F16C,"f16c",  38)
-X86_FEATURE   (CLZERO,  "clzero")
-X86_FEATURE   (CMPXCHG16B,  "cx16")
+X86_FEATURE_COMPAT(CLDEMOTE,"cldemote",   0)
+X86_FEATURE_COMPAT(CLFLUSHOPT,  "clflushopt", 0)
+X86_FEATURE_COMPAT(CLWB,"clwb",   0)
+X86_FEATURE_COMPAT(CLZERO,  "clzero", 0)
+X86_FEATURE_COMPAT(CMPXCHG16B,  "cx16",   0)
 X86_FEATURE   (CMPXCHG8B,   "cx8")
+X86_FEATURE_COMPAT(ENQCMD,  "enqcmd", 0)
+X86_FEATURE_COMPAT(F16C,"f16c",   0)
+X86_FEATURE_COMPAT(FSGSBASE,"fsgsbase",   0)
 X86_FEATURE   (CRC32,   "crc32")
-X86_FEATURE   (ENQCMD,  "enqcmd")
-X86_FEATURE   (FSGSBASE,"fsgsbase")
-X86_FEATURE   (FXSR,"fxsr")
 X86_FEATURE   (INVPCID, "invpcid")
-X86_FEATURE   (KL,  "kl")
-X86_FEATURE   (WIDEKL,  "widekl")
-X86_FEATURE   (LWP, "lwp")
-X86_FEATURE   (LZCNT,   "lzcnt")
-X86_FEATURE   (MOVBE,   "movbe")
-X86_FEATURE   (MOVDIR64B,   "movdir64b")
-X86_FEATURE   (MOVDIRI, "movdiri")
-X86_FEATURE   (MWAITX,  "mwaitx")
-X86_FEATURE   (PCONFIG, "pconfig")
-X86_FEATURE   (PKU, "pku")
-X86_FEATURE   (PREFETCHI,   "prefetchi")
-X86_FEATURE   (PREFETCHWT1, "prefetchwt1")
-X86_FEATURE   (PRFCHW,  "prfchw")
-X86_FEATURE   (PTWRITE, "ptwrite")
-X86_FEATURE   (RDPID,   "rdpid")
 X86_FEATURE   (RDPRU,   "rdpru")
-X86_FEATURE   (RDRND,   "rdrnd")
-X86_FEATURE   (RDSEED,  "rdseed")
-X86_FEATURE   (RTM, "rtm")
 X86_FEATURE   (SAHF,"sahf")
-X86_FEATURE   (SERIALIZE,   "serialize")
-X86_FEATURE   (SGX, "sgx")
-X86_FEATURE   (SHA, "sha")
-X86_FEATURE   (SHSTK,   "shstk")
-X86_FEATURE   (TBM, "tbm")
-X86_FEATURE   (TSXLDTRK,"tsxldtrk")
-X86_FEATURE   (UINTR,   "uintr")
-X86_FEATURE   (VAES,"vaes")
 X86_FEATURE   (VZEROUPPER,  "vzeroupper")
-X86_FEATURE   (WAITPKG, "waitpkg")
-X86_FEATURE   (WBNOINVD,"wbnoinvd")
+X86_FEATURE_COMPAT(LWP, "lwp",0)
+X86_FEATURE_COMPAT(LZCNT,   "lzcnt",  0)
+X86_FEATURE_COMPAT(MOVBE,   "movbe",  0)
+X86_FEATURE_COMPAT(MOVDIR64B,   "movdir64b",  0)
+X86_FEATURE_COMPAT(MOVDIRI, "movdiri",0)
+X86_FEATURE_COMPAT(MWAITX,  "mwaitx", 0)
 X86_FEATURE   (X87, "x87")
-X86_FEATURE   (XSAVE,   "xsave")
-X86_FEATURE   (XSAVEC,  "xsavec")
-X86_FEATURE   (XSAVEOPT,"xsaveopt")
-X86_FEATURE   (XSAVES,  "xsaves")
-X86_FEATURE_COMPAT(AVX512FP16,  "avx512fp16",39)
-X86_FEATURE   (HRESET,  "hreset")
-X86_FEATURE   (RAOINT,  "raoint")
-X86_FEATURE   (AMX_FP16,"amx-fp16")
-X86_FEATURE   (CMPCCXADD,   "cmpccxadd")
-X86_FEATURE   (AVXNECONVERT,"avxneconvert")
-X86_FEATURE   (AVXVNNI, "avxvnni")
-X86_FEATURE   (AVXIFMA, "avxifma")
-X86_FEATURE   (AVXVNNIINT8, "avxvnniint8")
-X86_FEATURE   (SHA512,  "sha512")
-X86_FEATURE   (SM3, "sm3")
-X86_FEATURE   (SM4, "sm4")
-X86_FEATURE   (AVXVNNIINT16,"avxvnniint16")
-X86_FEATURE   (EVEX512, "evex512")
-X86_FEATURE   (AVX10_1, "avx10.1-256")
-X86_FEATURE   (AVX10_1_512, "avx10.1-512")
-X86_FEATURE   (U

[compiler-rt] [llvm] [clang] [clang-tools-extra] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Shengchen Kan via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["egpr"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

KanRobert wrote:

Same here. Should discuss with GCC team and create a separate PR.

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


[llvm] [clang] [clang-tools-extra] [clang] reject to capture variable in `RequiresExprBodyDecl` (PR #78598)

2024-02-04 Thread via cfe-commits

cor3ntin wrote:

> > Thanks for the patch!
> > Requires Expressions should be in an unevaluated context, so we should 
> > never try to capture variables they mentioned.
> > Maybe we need to test the evaluation context in either `tryCaptureVariable` 
> > or `NeedToCaptureVariable`, rather than a specific handling for requires 
> > expressions
> > https://eel.is/c++draft/expr.prim.lambda.capture#7.sentence-2
> > WDYT?
> > @erichkeane
> 
> We will use `tryCaptureVariable` to diagnose `-Wunused-lambda-capture`. So 
> simply ignoring them in an unevaluated context is not a good idea. I have 
> changed the PR to match this function work even for `RequiresExprBodyDecl`.

You have an example of that? There may be further bugs there.
id-expression that appear in any unevaluated context should not be captured ( 
typeid being an exception
https://eel.is/c++draft/expr.prim.lambda.capture#7.sentence-2 )

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


[clang] [concepts] Fixes for gh72557 (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/80594

Draft for CI.

>From c04bb951d35e0f767ea9b0fed8e200b161d646e1 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 17:35:16 +0800
Subject: [PATCH] [concepts] Fixes for gh72557

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +--
 .../SemaTemplate/concepts-out-of-line-def.cpp  | 18 ++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..c4afe545c4b85 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,9 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fixed a crash where substituting into a requires-expression that involves 
parameter packs
+  during the equivalence determination of two constraint expressions.
+  (`#72557 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 01b78e4424fb5..220883ea9395f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -241,10 +241,21 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
 
 while (const Type *Ty = NNS ? NNS->getAsType() : nullptr) {
   if (NNS->isInstantiationDependent()) {
-if (const auto *TSTy = Ty->getAs())
+if (const auto *TSTy = Ty->getAs()) {
+  ArrayRef Arguments = TSTy->template_arguments();
+  if (TSTy->isCurrentInstantiation()) {
+auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
+if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
+  Arguments = CTD->getInjectedTemplateArgs();
+else if (auto *Specializtion =
+ dyn_cast(RD))
+  Arguments =
+  Specializtion->getTemplateInstantiationArgs().asArray();
+  }
   Result.addOuterTemplateArguments(
-  const_cast(FTD), 
TSTy->template_arguments(),
+  const_cast(FTD), Arguments,
   /*Final=*/false);
+}
   }
 
   NNS = NNS->getPrefix();
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index b6fea2e0b4b31..0142efcdc3ee8 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -581,3 +581,21 @@ void S::test(T target, U... value)
   }
 {}
 } // namespace GH74447
+
+namespace GH72557 {
+
+template 
+concept IsAnyOf = true;
+
+template  struct DerivedCollection {
+  template 
+requires IsAnyOf
+  unsigned long index();
+};
+
+template 
+template 
+  requires IsAnyOf
+unsigned long DerivedCollection::index() {}
+
+} // namespace GH72557

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


[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread Ruihua Dong via cfe-commits

144026 wrote:

@zyn0217  Thanks for the information, seems like a completed removal of pseudo 
parser has been decided in this [discourse 
thread](https://discourse.llvm.org/t/removing-pseudo-parser/71131), and 
shifting back to AST parser for foldingRange support would only lose a marginal 
multi-line comment folding feature.

Dependency of this patch hasn't been touched yet in #80081 , so I tested a 
rebased build of this patch on #80081 on my Linux box, which still could pass 
and work.

I understand that evolving this end-of-life parser only adds maintenance burden 
and should be avoided, but I hope there will be some ways (may be in the 
original AST parser?) to support PP conditional folding, especially when 
reading complex headers.

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


[clang-tools-extra] [clangd] Implement simple folding of preprocessor branches (PR #80592)

2024-02-04 Thread Ruihua Dong via cfe-commits

144026 wrote:

The build pipeline failure is on Windows x64, and appears to be some random 
error irrelevant to this patch:
```
MT: command "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\mt.exe 
/nologo /manifest bin\dexp.exe.manifest /outputresource:bin\dexp.exe;#1" failed 
(exit code 0x1f) with the following output:
mt.exe : general error c101008d: Failed to write the updated manifest to the 
resource of file "bin\dexp.exe". Operation did not complete successfully 
because the file contains a virus or potentially unwanted software.
```


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


[clang] [Clang] Fix a crash when dumping a pack indexing type. (PR #80439)

2024-02-04 Thread via cfe-commits

cor3ntin wrote:

@bjope thanks for letting me know. A reproduction would really help, as 
upstream bots do not exhibit this behavior at all.

https://github.com/llvm/llvm-project/pull/80439
___
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-02-04 Thread via cfe-commits


@@ -1513,6 +1580,11 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) 
{
 // the coroutine and if that is the case we cannot eliminate the suspend point.
 static bool hasCallsInBlockBetween(Instruction *From, Instruction *To) {
   for (Instruction *I = From; I != To; I = I->getNextNode()) {
+// This one could resume the coroutine,
+// but additional analysis before the check should ensure,
+// that it can't happen
+if (isa(I))
+  continue;

fpasserby wrote:

No, because `CoroAwaitSuspendInst` is not a proper `IntrinsicInst`, because it 
can be invoked. I'm not sure what else could be done about it (aside from 
deriving `IntrinisicInst` from `CallBase` instead of `CallInst`). Also it seems 
like special handling for it should be added to `InlineCost.cpp` and this 
intrinisic should return true in `mayLowerToFunctionCall`. Callback metadata 
should probabply be attached to the intrinsic, but I wasn't able to find a way 
to do it. 

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -1575,6 +1650,36 @@ static bool hasCallsBetween(Instruction *Save, 
Instruction *ResumeOrDestroy) {
   return false;
 }
 
+// Check if await-suspend helper is "simple".
+// The conditions are:
+// 1. The return result is exactly coroutine frame parameter, passed to helper
+// 2. There are no calls between any of the returns and helper entry that could
+// resume or destroy it
+// FIXME: perform more sophisiticated analysis?
+static bool isSimpleHelper(CoroAwaitSuspendInst *AWS) {

fpasserby wrote:

This method was added so that previously available optimization is not lost 
after this change. If you really feel this is too minor, I will remove it.

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] [concepts] Fixes for gh72557 (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

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


[clang] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

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


[clang] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80594

>From c04bb951d35e0f767ea9b0fed8e200b161d646e1 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 17:35:16 +0800
Subject: [PATCH 1/2] [concepts] Fixes for gh72557

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +--
 .../SemaTemplate/concepts-out-of-line-def.cpp  | 18 ++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..c4afe545c4b85 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,9 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fixed a crash where substituting into a requires-expression that involves 
parameter packs
+  during the equivalence determination of two constraint expressions.
+  (`#72557 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 01b78e4424fb5..220883ea9395f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -241,10 +241,21 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
 
 while (const Type *Ty = NNS ? NNS->getAsType() : nullptr) {
   if (NNS->isInstantiationDependent()) {
-if (const auto *TSTy = Ty->getAs())
+if (const auto *TSTy = Ty->getAs()) {
+  ArrayRef Arguments = TSTy->template_arguments();
+  if (TSTy->isCurrentInstantiation()) {
+auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
+if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
+  Arguments = CTD->getInjectedTemplateArgs();
+else if (auto *Specializtion =
+ dyn_cast(RD))
+  Arguments =
+  Specializtion->getTemplateInstantiationArgs().asArray();
+  }
   Result.addOuterTemplateArguments(
-  const_cast(FTD), 
TSTy->template_arguments(),
+  const_cast(FTD), Arguments,
   /*Final=*/false);
+}
   }
 
   NNS = NNS->getPrefix();
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index b6fea2e0b4b31..0142efcdc3ee8 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -581,3 +581,21 @@ void S::test(T target, U... value)
   }
 {}
 } // namespace GH74447
+
+namespace GH72557 {
+
+template 
+concept IsAnyOf = true;
+
+template  struct DerivedCollection {
+  template 
+requires IsAnyOf
+  unsigned long index();
+};
+
+template 
+template 
+  requires IsAnyOf
+unsigned long DerivedCollection::index() {}
+
+} // namespace GH72557

>From 70962f401c17151bbe4e9d95b651d1ad5d30206f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 19:20:19 +0800
Subject: [PATCH 2/2] Add comments

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 17 +
 1 file changed, 17 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 220883ea9395f..8faa8c5b5257e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -243,6 +243,23 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
   if (NNS->isInstantiationDependent()) {
 if (const auto *TSTy = Ty->getAs()) {
   ArrayRef Arguments = TSTy->template_arguments();
+  // Prefer template arguments from the injected-class-type if 
possible.
+  // For example,
+  // ```cpp
+  // template  struct S {
+  //   template  void foo();
+  // };
+  // template  template 
+  //   ^ InjectedTemplateArgs
+  //   They're of kind TemplateArgument::Pack, not of
+  //   TemplateArgument::Type.
+  // void S::foo() {}
+  //^^^
+  //TSTy->template_arguments() (which are of PackExpansionType)
+  // ```
+  // This meets the contract in
+  // TreeTransform::TryExpandParameterPacks that the template arguments
+  // for unexpanded parameters should be of a Pack kind.
   if (TSTy->isCurrentInstantiation()) {
 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
 if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())

___
cfe-commit

[clang-tools-extra] [clang] [llvm] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80594

>From c04bb951d35e0f767ea9b0fed8e200b161d646e1 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 17:35:16 +0800
Subject: [PATCH 1/2] [concepts] Fixes for gh72557

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +--
 .../SemaTemplate/concepts-out-of-line-def.cpp  | 18 ++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..c4afe545c4b85 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,9 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fixed a crash where substituting into a requires-expression that involves 
parameter packs
+  during the equivalence determination of two constraint expressions.
+  (`#72557 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 01b78e4424fb5..220883ea9395f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -241,10 +241,21 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
 
 while (const Type *Ty = NNS ? NNS->getAsType() : nullptr) {
   if (NNS->isInstantiationDependent()) {
-if (const auto *TSTy = Ty->getAs())
+if (const auto *TSTy = Ty->getAs()) {
+  ArrayRef Arguments = TSTy->template_arguments();
+  if (TSTy->isCurrentInstantiation()) {
+auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
+if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
+  Arguments = CTD->getInjectedTemplateArgs();
+else if (auto *Specializtion =
+ dyn_cast(RD))
+  Arguments =
+  Specializtion->getTemplateInstantiationArgs().asArray();
+  }
   Result.addOuterTemplateArguments(
-  const_cast(FTD), 
TSTy->template_arguments(),
+  const_cast(FTD), Arguments,
   /*Final=*/false);
+}
   }
 
   NNS = NNS->getPrefix();
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index b6fea2e0b4b31..0142efcdc3ee8 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -581,3 +581,21 @@ void S::test(T target, U... value)
   }
 {}
 } // namespace GH74447
+
+namespace GH72557 {
+
+template 
+concept IsAnyOf = true;
+
+template  struct DerivedCollection {
+  template 
+requires IsAnyOf
+  unsigned long index();
+};
+
+template 
+template 
+  requires IsAnyOf
+unsigned long DerivedCollection::index() {}
+
+} // namespace GH72557

>From 70962f401c17151bbe4e9d95b651d1ad5d30206f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 19:20:19 +0800
Subject: [PATCH 2/2] Add comments

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 17 +
 1 file changed, 17 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 220883ea9395f..8faa8c5b5257e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -243,6 +243,23 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
   if (NNS->isInstantiationDependent()) {
 if (const auto *TSTy = Ty->getAs()) {
   ArrayRef Arguments = TSTy->template_arguments();
+  // Prefer template arguments from the injected-class-type if 
possible.
+  // For example,
+  // ```cpp
+  // template  struct S {
+  //   template  void foo();
+  // };
+  // template  template 
+  //   ^ InjectedTemplateArgs
+  //   They're of kind TemplateArgument::Pack, not of
+  //   TemplateArgument::Type.
+  // void S::foo() {}
+  //^^^
+  //TSTy->template_arguments() (which are of PackExpansionType)
+  // ```
+  // This meets the contract in
+  // TreeTransform::TryExpandParameterPacks that the template arguments
+  // for unexpanded parameters should be of a Pack kind.
   if (TSTy->isCurrentInstantiation()) {
 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
 if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())

___
cfe-commit

[clang-tools-extra] [clang] [llvm] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

Before the constraint substitution, we employ `getTemplateInstantiationArgs`, 
which in turn attempts to inspect `TemplateArgument`s from the function 
template. For parameter packs from their parent contexts, we used to extract 
the arguments from the specialization type, in which could result in 
non-canonical argument types e.g. `PackExpansionType`.

This may break the contract that, during a tree transformation, in 
`TreeTransform::TryExpandParameterPacks`, the corresponding `TemplateArgument`s 
for an `UnexpandedParameterPack` are expected to be of `Pack` kinds if we're 
expanding template parameters.

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+30-2) 
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+18) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3596109bf044f..4d57ea4fd55b8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,9 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fixed a crash where substituting into a requires-expression that involves 
parameter packs
+  during the equivalence determination of two constraint expressions.
+  (`#72557 `_)
 - Fix a crash when specializing an out-of-line member function with a default
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e5999fa50117e..878b557a999e1 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -241,10 +241,38 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
 
 while (const Type *Ty = NNS ? NNS->getAsType() : nullptr) {
   if (NNS->isInstantiationDependent()) {
-if (const auto *TSTy = Ty->getAs())
+if (const auto *TSTy = Ty->getAs()) {
+  ArrayRef Arguments = TSTy->template_arguments();
+  // Prefer template arguments from the injected-class-type if 
possible.
+  // For example,
+  // ```cpp
+  // template  struct S {
+  //   template  void foo();
+  // };
+  // template  template 
+  //   ^ InjectedTemplateArgs
+  //   They're of kind TemplateArgument::Pack, not of
+  //   TemplateArgument::Type.
+  // void S::foo() {}
+  //^^^
+  //TSTy->template_arguments() (which are of PackExpansionType)
+  // ```
+  // This meets the contract in
+  // TreeTransform::TryExpandParameterPacks that the template arguments
+  // for unexpanded parameters should be of a Pack kind.
+  if (TSTy->isCurrentInstantiation()) {
+auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
+if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
+  Arguments = CTD->getInjectedTemplateArgs();
+else if (auto *Specializtion =
+ dyn_cast(RD))
+  Arguments =
+  Specializtion->getTemplateInstantiationArgs().asArray();
+  }
   Result.addOuterTemplateArguments(
-  const_cast(FTD), 
TSTy->template_arguments(),
+  const_cast(FTD), Arguments,
   /*Final=*/false);
+}
   }
 
   NNS = NNS->getPrefix();
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index b6fea2e0b4b31..0142efcdc3ee8 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -581,3 +581,21 @@ void S::test(T target, U... value)
   }
 {}
 } // namespace GH74447
+
+namespace GH72557 {
+
+template 
+concept IsAnyOf = true;
+
+template  struct DerivedCollection {
+  template 
+requires IsAnyOf
+  unsigned long index();
+};
+
+template 
+template 
+  requires IsAnyOf
+unsigned long DerivedCollection::index() {}
+
+} // namespace GH72557

``




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


[clang-tools-extra] [clang] [llvm] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-04 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80594

>From c04bb951d35e0f767ea9b0fed8e200b161d646e1 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 17:35:16 +0800
Subject: [PATCH 1/3] [concepts] Fixes for gh72557

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +--
 .../SemaTemplate/concepts-out-of-line-def.cpp  | 18 ++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..c4afe545c4b85 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,9 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fixed a crash where substituting into a requires-expression that involves 
parameter packs
+  during the equivalence determination of two constraint expressions.
+  (`#72557 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 01b78e4424fb5..220883ea9395f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -241,10 +241,21 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
 
 while (const Type *Ty = NNS ? NNS->getAsType() : nullptr) {
   if (NNS->isInstantiationDependent()) {
-if (const auto *TSTy = Ty->getAs())
+if (const auto *TSTy = Ty->getAs()) {
+  ArrayRef Arguments = TSTy->template_arguments();
+  if (TSTy->isCurrentInstantiation()) {
+auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
+if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
+  Arguments = CTD->getInjectedTemplateArgs();
+else if (auto *Specializtion =
+ dyn_cast(RD))
+  Arguments =
+  Specializtion->getTemplateInstantiationArgs().asArray();
+  }
   Result.addOuterTemplateArguments(
-  const_cast(FTD), 
TSTy->template_arguments(),
+  const_cast(FTD), Arguments,
   /*Final=*/false);
+}
   }
 
   NNS = NNS->getPrefix();
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index b6fea2e0b4b31..0142efcdc3ee8 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -581,3 +581,21 @@ void S::test(T target, U... value)
   }
 {}
 } // namespace GH74447
+
+namespace GH72557 {
+
+template 
+concept IsAnyOf = true;
+
+template  struct DerivedCollection {
+  template 
+requires IsAnyOf
+  unsigned long index();
+};
+
+template 
+template 
+  requires IsAnyOf
+unsigned long DerivedCollection::index() {}
+
+} // namespace GH72557

>From 70962f401c17151bbe4e9d95b651d1ad5d30206f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 4 Feb 2024 19:20:19 +0800
Subject: [PATCH 2/3] Add comments

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 17 +
 1 file changed, 17 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 220883ea9395f..8faa8c5b5257e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -243,6 +243,23 @@ Response HandleFunctionTemplateDecl(const 
FunctionTemplateDecl *FTD,
   if (NNS->isInstantiationDependent()) {
 if (const auto *TSTy = Ty->getAs()) {
   ArrayRef Arguments = TSTy->template_arguments();
+  // Prefer template arguments from the injected-class-type if 
possible.
+  // For example,
+  // ```cpp
+  // template  struct S {
+  //   template  void foo();
+  // };
+  // template  template 
+  //   ^ InjectedTemplateArgs
+  //   They're of kind TemplateArgument::Pack, not of
+  //   TemplateArgument::Type.
+  // void S::foo() {}
+  //^^^
+  //TSTy->template_arguments() (which are of PackExpansionType)
+  // ```
+  // This meets the contract in
+  // TreeTransform::TryExpandParameterPacks that the template arguments
+  // for unexpanded parameters should be of a Pack kind.
   if (TSTy->isCurrentInstantiation()) {
 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
 if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())

>From cf520b632ca54cd70ca5fb6274b5d0e32a8765f3 Mon Sep 17 

[compiler-rt] [clang-tools-extra] [llvm] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/79086

>From b5c8579c5c8e7ea1e8436348bbf60ecee9c3c799 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 19 Jan 2024 09:22:27 +0800
Subject: [PATCH 1/8] [X86] Support more ISAs to enable __builtin_cpu_supports

This patch will also expand supports for attribute/target, while
the priority of newly supported ISAs will be set to zero.
---
 clang/test/CodeGen/target-builtin-noerror.c   |  59 +
 compiler-rt/lib/builtins/cpu_model/x86.c  | 209 +-
 .../llvm/TargetParser/X86TargetParser.def | 135 ++-
 3 files changed, 324 insertions(+), 79 deletions(-)

diff --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 06bb40a2b71ea..16097fa08cb9c 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -84,6 +84,65 @@ void verifyfeaturestrings(void) {
   (void)__builtin_cpu_supports("avx512vp2intersect");
   (void)__builtin_cpu_supports("f16c");
   (void)__builtin_cpu_supports("avx512fp16");
+  (void)__builtin_cpu_supports("3dnow");
+  (void)__builtin_cpu_supports("adx");
+  (void)__builtin_cpu_supports("cldemote");
+  (void)__builtin_cpu_supports("clflushopt");
+  (void)__builtin_cpu_supports("clwb");
+  (void)__builtin_cpu_supports("clzero");
+  (void)__builtin_cpu_supports("cx16");
+  (void)__builtin_cpu_supports("cx8");
+  (void)__builtin_cpu_supports("enqcmd");
+  (void)__builtin_cpu_supports("fsgsbase");
+  (void)__builtin_cpu_supports("lwp");
+  (void)__builtin_cpu_supports("lzcnt");
+  (void)__builtin_cpu_supports("movbe");
+  (void)__builtin_cpu_supports("movdir64b");
+  (void)__builtin_cpu_supports("movdiri");
+  (void)__builtin_cpu_supports("mwaitx");
+  (void)__builtin_cpu_supports("pconfig");
+  (void)__builtin_cpu_supports("pku");
+  (void)__builtin_cpu_supports("prefetchwt1");
+  (void)__builtin_cpu_supports("prfchw");
+  (void)__builtin_cpu_supports("ptwrite");
+  (void)__builtin_cpu_supports("rdpid");
+  (void)__builtin_cpu_supports("rdrnd");
+  (void)__builtin_cpu_supports("rdseed");
+  (void)__builtin_cpu_supports("rtm");
+  (void)__builtin_cpu_supports("serialize");
+  (void)__builtin_cpu_supports("sgx");
+  (void)__builtin_cpu_supports("sha");
+  (void)__builtin_cpu_supports("shstk");
+  (void)__builtin_cpu_supports("tbm");
+  (void)__builtin_cpu_supports("tsxldtrk");
+  (void)__builtin_cpu_supports("vaes");
+  (void)__builtin_cpu_supports("waitpkg");
+  (void)__builtin_cpu_supports("wbnoinvd");
+  (void)__builtin_cpu_supports("xsave");
+  (void)__builtin_cpu_supports("xsavec");
+  (void)__builtin_cpu_supports("xsaveopt");
+  (void)__builtin_cpu_supports("xsaves");
+  (void)__builtin_cpu_supports("amx-tile");
+  (void)__builtin_cpu_supports("amx-int8");
+  (void)__builtin_cpu_supports("amx-bf16");
+  (void)__builtin_cpu_supports("uintr");
+  (void)__builtin_cpu_supports("hreset");
+  (void)__builtin_cpu_supports("kl");
+  (void)__builtin_cpu_supports("widekl");
+  (void)__builtin_cpu_supports("avxvnni");
+  (void)__builtin_cpu_supports("avxifma");
+  (void)__builtin_cpu_supports("avxvnniint8");
+  (void)__builtin_cpu_supports("avxneconvert");
+  (void)__builtin_cpu_supports("cmpccxadd");
+  (void)__builtin_cpu_supports("amx-fp16");
+  (void)__builtin_cpu_supports("prefetchi");
+  (void)__builtin_cpu_supports("raoint");
+  (void)__builtin_cpu_supports("amx-complex");
+  (void)__builtin_cpu_supports("avxvnniint16");
+  (void)__builtin_cpu_supports("sm3");
+  (void)__builtin_cpu_supports("sha512");
+  (void)__builtin_cpu_supports("sm4");
+  (void)__builtin_cpu_supports("usermsr");
 }
 
 void verifycpustrings(void) {
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c 
b/compiler-rt/lib/builtins/cpu_model/x86.c
index 0750e29f989a8..c499754890343 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -139,20 +139,77 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+  FEATURE_3DNOW,
+  FEATURE_ADX = 40,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+  FEATURE_CMPXCHG8B,
+  FEATURE_ENQCMD,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,
 
-  FEATURE_CMPXCHG16B = 46,
-  FEATURE_F16C = 49,
   FEATURE_LAHF_LM = 54,
   FEATURE_LM,
-  FEATURE_WP,
+  FEATURE_LWP,
   FEATURE_LZCNT,
   FEATURE_MOVBE,
-
-  FEATURE_AVX512FP16 = 94,
+  FEATURE_MOVDIR64B,
+  FEATURE_MOVDIRI,
+  FEATURE_MWAITX,
+
+  FEATURE_PCONFIG = 63,
+  FEATURE_PKU,
+  FEATURE_PREFETCHWT1,
+  FEATURE_PRFCHW,
+  FEATURE_PTWRITE,
+  FEATURE_RDPID,
+  FEATURE_RDRND,
+  FEATURE_RDSEED,
+  FEATURE_RTM,
+  FEATURE_SERIALIZE,
+  FEATURE_SGX,
+  FEATURE_SHA,
+  FEATURE_SHSTK,
+  FEATURE_TBM,
+  FEATURE_TSXLDTRK,
+  FEATURE_VAES,
+  FEATURE_WAITPKG,
+  FEATURE_WBNOINVD,
+  FEATURE_XSAVE,
+  FEATURE_XSAVEC,
+  FEATURE_XSAVEOPT,
+  FEATURE_XSAVES,
+  FEATURE_AMX_TILE,
+  FEATURE_AMX

[compiler-rt] [clang-tools-extra] [llvm] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Phoebe Wang via cfe-commits


@@ -217,8 +217,7 @@ enum ProcessorFeatures {
   FEATURE_SM3,
   FEATURE_SHA512,
   FEATURE_SM4,
-  //FIXME: gcc used string "apxf" instead of "egpr"
-  FEATURE_EGPR,
+  // FEATURE_APXF,
   FEATURE_USERMSR,

phoebewang wrote:

You need to change the number then.

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


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

2024-02-04 Thread via cfe-commits

https://github.com/fpasserby edited 
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


[compiler-rt] [clang-tools-extra] [llvm] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/79086

>From b5c8579c5c8e7ea1e8436348bbf60ecee9c3c799 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 19 Jan 2024 09:22:27 +0800
Subject: [PATCH 1/9] [X86] Support more ISAs to enable __builtin_cpu_supports

This patch will also expand supports for attribute/target, while
the priority of newly supported ISAs will be set to zero.
---
 clang/test/CodeGen/target-builtin-noerror.c   |  59 +
 compiler-rt/lib/builtins/cpu_model/x86.c  | 209 +-
 .../llvm/TargetParser/X86TargetParser.def | 135 ++-
 3 files changed, 324 insertions(+), 79 deletions(-)

diff --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 06bb40a2b71ea..16097fa08cb9c 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -84,6 +84,65 @@ void verifyfeaturestrings(void) {
   (void)__builtin_cpu_supports("avx512vp2intersect");
   (void)__builtin_cpu_supports("f16c");
   (void)__builtin_cpu_supports("avx512fp16");
+  (void)__builtin_cpu_supports("3dnow");
+  (void)__builtin_cpu_supports("adx");
+  (void)__builtin_cpu_supports("cldemote");
+  (void)__builtin_cpu_supports("clflushopt");
+  (void)__builtin_cpu_supports("clwb");
+  (void)__builtin_cpu_supports("clzero");
+  (void)__builtin_cpu_supports("cx16");
+  (void)__builtin_cpu_supports("cx8");
+  (void)__builtin_cpu_supports("enqcmd");
+  (void)__builtin_cpu_supports("fsgsbase");
+  (void)__builtin_cpu_supports("lwp");
+  (void)__builtin_cpu_supports("lzcnt");
+  (void)__builtin_cpu_supports("movbe");
+  (void)__builtin_cpu_supports("movdir64b");
+  (void)__builtin_cpu_supports("movdiri");
+  (void)__builtin_cpu_supports("mwaitx");
+  (void)__builtin_cpu_supports("pconfig");
+  (void)__builtin_cpu_supports("pku");
+  (void)__builtin_cpu_supports("prefetchwt1");
+  (void)__builtin_cpu_supports("prfchw");
+  (void)__builtin_cpu_supports("ptwrite");
+  (void)__builtin_cpu_supports("rdpid");
+  (void)__builtin_cpu_supports("rdrnd");
+  (void)__builtin_cpu_supports("rdseed");
+  (void)__builtin_cpu_supports("rtm");
+  (void)__builtin_cpu_supports("serialize");
+  (void)__builtin_cpu_supports("sgx");
+  (void)__builtin_cpu_supports("sha");
+  (void)__builtin_cpu_supports("shstk");
+  (void)__builtin_cpu_supports("tbm");
+  (void)__builtin_cpu_supports("tsxldtrk");
+  (void)__builtin_cpu_supports("vaes");
+  (void)__builtin_cpu_supports("waitpkg");
+  (void)__builtin_cpu_supports("wbnoinvd");
+  (void)__builtin_cpu_supports("xsave");
+  (void)__builtin_cpu_supports("xsavec");
+  (void)__builtin_cpu_supports("xsaveopt");
+  (void)__builtin_cpu_supports("xsaves");
+  (void)__builtin_cpu_supports("amx-tile");
+  (void)__builtin_cpu_supports("amx-int8");
+  (void)__builtin_cpu_supports("amx-bf16");
+  (void)__builtin_cpu_supports("uintr");
+  (void)__builtin_cpu_supports("hreset");
+  (void)__builtin_cpu_supports("kl");
+  (void)__builtin_cpu_supports("widekl");
+  (void)__builtin_cpu_supports("avxvnni");
+  (void)__builtin_cpu_supports("avxifma");
+  (void)__builtin_cpu_supports("avxvnniint8");
+  (void)__builtin_cpu_supports("avxneconvert");
+  (void)__builtin_cpu_supports("cmpccxadd");
+  (void)__builtin_cpu_supports("amx-fp16");
+  (void)__builtin_cpu_supports("prefetchi");
+  (void)__builtin_cpu_supports("raoint");
+  (void)__builtin_cpu_supports("amx-complex");
+  (void)__builtin_cpu_supports("avxvnniint16");
+  (void)__builtin_cpu_supports("sm3");
+  (void)__builtin_cpu_supports("sha512");
+  (void)__builtin_cpu_supports("sm4");
+  (void)__builtin_cpu_supports("usermsr");
 }
 
 void verifycpustrings(void) {
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c 
b/compiler-rt/lib/builtins/cpu_model/x86.c
index 0750e29f989a8..c499754890343 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -139,20 +139,77 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+  FEATURE_3DNOW,
+  FEATURE_ADX = 40,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+  FEATURE_CMPXCHG8B,
+  FEATURE_ENQCMD,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,
 
-  FEATURE_CMPXCHG16B = 46,
-  FEATURE_F16C = 49,
   FEATURE_LAHF_LM = 54,
   FEATURE_LM,
-  FEATURE_WP,
+  FEATURE_LWP,
   FEATURE_LZCNT,
   FEATURE_MOVBE,
-
-  FEATURE_AVX512FP16 = 94,
+  FEATURE_MOVDIR64B,
+  FEATURE_MOVDIRI,
+  FEATURE_MWAITX,
+
+  FEATURE_PCONFIG = 63,
+  FEATURE_PKU,
+  FEATURE_PREFETCHWT1,
+  FEATURE_PRFCHW,
+  FEATURE_PTWRITE,
+  FEATURE_RDPID,
+  FEATURE_RDRND,
+  FEATURE_RDSEED,
+  FEATURE_RTM,
+  FEATURE_SERIALIZE,
+  FEATURE_SGX,
+  FEATURE_SHA,
+  FEATURE_SHSTK,
+  FEATURE_TBM,
+  FEATURE_TSXLDTRK,
+  FEATURE_VAES,
+  FEATURE_WAITPKG,
+  FEATURE_WBNOINVD,
+  FEATURE_XSAVE,
+  FEATURE_XSAVEC,
+  FEATURE_XSAVEOPT,
+  FEATURE_XSAVES,
+  FEATURE_AMX_TILE,
+  FEATURE_AMX

[compiler-rt] [clang-tools-extra] [llvm] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang-tools-extra] [clang] [compiler-rt] [llvm] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

Thanks review!

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


[clang] 7210560 - [X86] Support more ISAs to enable __builtin_cpu_supports (#79086)

2024-02-04 Thread via cfe-commits

Author: Freddy Ye
Date: 2024-02-04T21:21:12+08:00
New Revision: 72105605d1fbc816c1219bb1d719693291322011

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

LOG: [X86] Support more ISAs to enable __builtin_cpu_supports (#79086)

This patch will also expand supports for attribute/target, while
the priority of newly supported ISAs will be set to zero.

Added: 


Modified: 
clang/test/CodeGen/target-builtin-noerror.c
compiler-rt/lib/builtins/cpu_model/x86.c
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/lib/TargetParser/X86TargetParser.cpp

Removed: 




diff  --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 06bb40a2b71ea..9608b5f37baaa 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -84,6 +84,66 @@ void verifyfeaturestrings(void) {
   (void)__builtin_cpu_supports("avx512vp2intersect");
   (void)__builtin_cpu_supports("f16c");
   (void)__builtin_cpu_supports("avx512fp16");
+  (void)__builtin_cpu_supports("3dnow");
+  (void)__builtin_cpu_supports("adx");
+  (void)__builtin_cpu_supports("cldemote");
+  (void)__builtin_cpu_supports("clflushopt");
+  (void)__builtin_cpu_supports("clwb");
+  (void)__builtin_cpu_supports("clzero");
+  (void)__builtin_cpu_supports("cx16");
+  (void)__builtin_cpu_supports("enqcmd");
+  (void)__builtin_cpu_supports("fsgsbase");
+  (void)__builtin_cpu_supports("lwp");
+  (void)__builtin_cpu_supports("lzcnt");
+  (void)__builtin_cpu_supports("movbe");
+  (void)__builtin_cpu_supports("movdir64b");
+  (void)__builtin_cpu_supports("movdiri");
+  (void)__builtin_cpu_supports("mwaitx");
+  (void)__builtin_cpu_supports("pconfig");
+  (void)__builtin_cpu_supports("pku");
+  (void)__builtin_cpu_supports("prefetchwt1");
+  (void)__builtin_cpu_supports("prfchw");
+  (void)__builtin_cpu_supports("ptwrite");
+  (void)__builtin_cpu_supports("rdpid");
+  (void)__builtin_cpu_supports("rdrnd");
+  (void)__builtin_cpu_supports("rdseed");
+  (void)__builtin_cpu_supports("rtm");
+  (void)__builtin_cpu_supports("serialize");
+  (void)__builtin_cpu_supports("sgx");
+  (void)__builtin_cpu_supports("sha");
+  (void)__builtin_cpu_supports("shstk");
+  (void)__builtin_cpu_supports("tbm");
+  (void)__builtin_cpu_supports("tsxldtrk");
+  (void)__builtin_cpu_supports("vaes");
+  (void)__builtin_cpu_supports("waitpkg");
+  (void)__builtin_cpu_supports("wbnoinvd");
+  (void)__builtin_cpu_supports("xsave");
+  (void)__builtin_cpu_supports("xsavec");
+  (void)__builtin_cpu_supports("xsaveopt");
+  (void)__builtin_cpu_supports("xsaves");
+  (void)__builtin_cpu_supports("amx-tile");
+  (void)__builtin_cpu_supports("amx-int8");
+  (void)__builtin_cpu_supports("amx-bf16");
+  (void)__builtin_cpu_supports("uintr");
+  (void)__builtin_cpu_supports("hreset");
+  (void)__builtin_cpu_supports("kl");
+  (void)__builtin_cpu_supports("widekl");
+  (void)__builtin_cpu_supports("avxvnni");
+  (void)__builtin_cpu_supports("avxifma");
+  (void)__builtin_cpu_supports("avxvnniint8");
+  (void)__builtin_cpu_supports("avxneconvert");
+  (void)__builtin_cpu_supports("cmpccxadd");
+  (void)__builtin_cpu_supports("amx-fp16");
+  (void)__builtin_cpu_supports("prefetchi");
+  (void)__builtin_cpu_supports("raoint");
+  (void)__builtin_cpu_supports("amx-complex");
+  (void)__builtin_cpu_supports("avxvnniint16");
+  (void)__builtin_cpu_supports("sm3");
+  (void)__builtin_cpu_supports("sha512");
+  (void)__builtin_cpu_supports("sm4");
+  (void)__builtin_cpu_supports("usermsr");
+  (void)__builtin_cpu_supports("avx10.1-256");
+  (void)__builtin_cpu_supports("avx10.1-512");
 }
 
 void verifycpustrings(void) {

diff  --git a/compiler-rt/lib/builtins/cpu_model/x86.c 
b/compiler-rt/lib/builtins/cpu_model/x86.c
index 0750e29f989a8..1afa468c4ae8c 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -139,20 +139,88 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
-
-  FEATURE_CMPXCHG16B = 46,
-  FEATURE_F16C = 49,
+  // FIXME: Below Features has some missings comparing to gcc, it's because gcc
+  // has some not one-to-one mapped in llvm.
+  FEATURE_3DNOW,
+  // FEATURE_3DNOWP,
+  FEATURE_ADX = 40,
+  // FEATURE_ABM,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+  // FIXME: Not adding FEATURE_CMPXCHG8B is a workaround to make 'generic' as
+  // a cpu string with no X86_FEATURE_COMPAT features, which is required in
+  // current implementantion of cpu_specific/cpu_dispatch FMV feature.
+  // FEATURE_CMPXCHG8B,
+  FEATURE_ENQCMD = 48,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,
+  // FEATURE_FXSAVE,
+  // FEATURE_HLE,
+  // FEATUR

[clang-tools-extra] [clang] [compiler-rt] [llvm] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-04 Thread Freddy Ye via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-02-04 Thread Shourya Goel via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-02-04 Thread Shourya Goel via cfe-commits

Sh0g0-1758 wrote:

gentle ping. Please check the mergeability of this PR. 

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-04 Thread Mark de Wever via cfe-commits

mordante wrote:

Thanks for reverting @AaronBallman I somehow missed this comment.

@kaz7 it should work on all platforms AFAIK. I don't have access to a VE 
system. Looking at some VE tests I wonder whether the following patch would 
work.
[patch.txt](https://github.com/llvm/llvm-project/files/14157135/patch.txt)


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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-04 Thread Yaxun Liu via cfe-commits

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

LGTM. Thanks

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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-04 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

> It looks reasonable to me, although I'm not really an AMDGPU person. /me 
> summons @arsenm ?

AMDGPU backend relies on LLVM passes to translate printf at IR level. 
__builtin_printf and printf should be equivalent other than the name.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread via cfe-commits


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

mydeveloperday wrote:

I've seen this used extensively, I'm not sure it triggers a compile warning.

assert(!"fail")  

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


[clang-tools-extra] [clang] [libcxx] [libc++] Implement `views::join_with` (PR #65536)

2024-02-04 Thread Jakub Mazurkiewicz via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [clang] reject to capture variable in `RequiresExprBodyDecl` (PR #78598)

2024-02-04 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> You have an example of that? There may be further bugs there.
> id-expression that appear in any unevaluated context should not be captured ( 
> typeid being an exception

I think it is from standard, but from user-friendly site. Now clang will hint 
user some variables is not need to capture. Which means it need to capture it 
and analyze it not need to capture.
https://godbolt.org/z/9jnx93r6e
```c++
auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; };
```

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


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

2024-02-04 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Humble Ping! (as per the rules ping after week of inactivity) @PiotrZSL , 
@5chmidti , @felix642 , @EugeneZelenko , I think its nearly done.

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-04 Thread Owen Pan via cfe-commits


@@ -1909,6 +1909,14 @@ TEST_F(FormatTestComments, ReflowsComments) {
"// @param arg",
getLLVMStyleWithColumns(20)));
 
+  // Don't reflow lines starting with '\'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// \\param arg",
+format("// long long long long\n"
+   "// \\param arg",
+   getLLVMStyleWithColumns(20)));

owenca wrote:

Redundant?

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-04 Thread Owen Pan via cfe-commits


@@ -1909,6 +1909,14 @@ TEST_F(FormatTestComments, ReflowsComments) {
"// @param arg",
getLLVMStyleWithColumns(20)));
 
+  // Don't reflow lines starting with '\'.
+  EXPECT_EQ("// long long long\n"

owenca wrote:

Can you use `verifyFormat` or `verifyNoChange` instead?

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-04 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-04 Thread Owen Pan via cfe-commits

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


[clang] [flang] [flang][driver] Add support for -isysroot in the frontend (PR #77365)

2024-02-04 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

Thank you for your continued effort to improve this!

> Anyone knows if this is expected and Visibility should be explicitly 
> specified in each alias, to add support to flang-new, or is this an issue and 
> the alias should have the same visibility as the original option?

IIRC, when `Visibility` is omitted then it defaults to "Clang" (or something to 
that effect). That would explain what you see. Something to be fixed :) 

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-04 Thread Fernando Tagawa via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/80381

>From efd816282e5f5b71d6f88038a2121fa698becf7a Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 2 Feb 2024 00:27:57 -0300
Subject: [PATCH 1/2] [clang-format] Handle doxygen comments starting with \

---
 clang/lib/Format/BreakableToken.cpp   | 4 ++--
 clang/unittests/Format/FormatTestComments.cpp | 8 
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index 473908e8fee3b..75304908dc650 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -449,11 +449,11 @@ const FormatToken &BreakableComment::tokenAt(unsigned 
LineIndex) const {
 
 static bool mayReflowContent(StringRef Content) {
   Content = Content.trim(Blanks);
-  // Lines starting with '@' commonly have special meaning.
+  // Lines starting with '@' or '\' commonly have special meaning.
   // Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists.
   bool hasSpecialMeaningPrefix = false;
   for (StringRef Prefix :
-   {"@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
+   {"@", "\\", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
 if (Content.starts_with(Prefix)) {
   hasSpecialMeaningPrefix = true;
   break;
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index c249f4d9333fd..0327937e4496a 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -1909,6 +1909,14 @@ TEST_F(FormatTestComments, ReflowsComments) {
"// @param arg",
getLLVMStyleWithColumns(20)));
 
+  // Don't reflow lines starting with '\'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// \\param arg",
+format("// long long long long\n"
+   "// \\param arg",
+   getLLVMStyleWithColumns(20)));
+
   // Don't reflow lines starting with 'TODO'.
   EXPECT_EQ("// long long long\n"
 "// long\n"

>From cd291925afc7748e31e8be5d2eb484231fe64e24 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sun, 4 Feb 2024 16:19:57 -0300
Subject: [PATCH 2/2] Use verifyFormat

---
 clang/unittests/Format/FormatTestComments.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 0327937e4496a..d705cf34d8af0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -1910,12 +1910,12 @@ TEST_F(FormatTestComments, ReflowsComments) {
getLLVMStyleWithColumns(20)));
 
   // Don't reflow lines starting with '\'.
-  EXPECT_EQ("// long long long\n"
-"// long\n"
-"// \\param arg",
-format("// long long long long\n"
-   "// \\param arg",
-   getLLVMStyleWithColumns(20)));
+  verifyFormat("// long long long\n"
+   "// long\n"
+   "// \\param arg",
+   "// long long long long\n"
+   "// \\param arg",
+   getLLVMStyleWithColumns(20));
 
   // Don't reflow lines starting with 'TODO'.
   EXPECT_EQ("// long long long\n"

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-04 Thread Owen Pan via cfe-commits

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


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


[clang] [polly] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-02-04 Thread Björn Schäpers via cfe-commits

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


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


[clang] 2562007 - [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (#78011)

2024-02-04 Thread via cfe-commits

Author: rmarker
Date: 2024-02-04T12:26:32-08:00
New Revision: 256200732111afd03bb7437564f3a3d77c0ec3f5

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

LOG: [clang-format] Add Automatic and ExceptShortType options for 
AlwaysBreakAfterReturnType. (#78011)

The RTBS_None option in Clang-format avoids breaking after a short
return type.
However, there was an issue with the behaviour in that it wouldn't take
the leading indentation of the line into account.
This meant that the behaviour wasn't applying when intended.

In order to address this situation without breaking the existing
formatting, RTBS_None has been deprecated.
In its place are two new options for AlwaysBreakAfterReturnType.
The option RTBS_Automatic will break after the return type based on
PenaltyReturnTypeOnItsOwnLine.
The option RTBS_ExceptShortType will take the leading indentation into
account and prevent breaking after short return types.

This allows the inconsistent behaviour of RTBS_None to be avoided and
users to decide whether they want to allow breaking after short return
types or not.

Resolves #78010

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0b887288fe2cb..976d9e2716ef3 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1537,8 +1537,10 @@ the configuration (without a prefix: ``Auto``).
   Possible values:
 
   * ``RTBS_None`` (in configuration: ``None``)
-Break after return type automatically.
-``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
+This is **deprecated**. See ``Automatic`` below.
+
+  * ``RTBS_Automatic`` (in configuration: ``Automatic``)
+Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
 
 .. code-block:: c++
 
@@ -1547,6 +1549,22 @@ the configuration (without a prefix: ``Auto``).
   };
   int f();
   int f() { return 1; }
+  int
+  LongName::AnotherLongName();
+
+  * ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
+Same as ``Automatic`` above, except that there is no break after short
+return types.
+
+.. code-block:: c++
+
+  class A {
+int f() { return 0; };
+  };
+  int f();
+  int f() { return 1; }
+  int LongName::
+  AnotherLongName();
 
   * ``RTBS_All`` (in configuration: ``All``)
 Always break after the return type.
@@ -1565,6 +1583,8 @@ the configuration (without a prefix: ``Auto``).
   f() {
 return 1;
   }
+  int
+  LongName::AnotherLongName();
 
   * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
 Always break after the return types of top-level functions.
@@ -1580,6 +1600,8 @@ the configuration (without a prefix: ``Auto``).
   f() {
 return 1;
   }
+  int
+  LongName::AnotherLongName();
 
   * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
 Always break after the return type of function definitions.
@@ -1597,6 +1619,8 @@ the configuration (without a prefix: ``Auto``).
   f() {
 return 1;
   }
+  int
+  LongName::AnotherLongName();
 
   * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
 Always break after the return type of top-level definitions.
@@ -1611,6 +1635,8 @@ the configuration (without a prefix: ``Auto``).
   f() {
 return 1;
   }
+  int
+  LongName::AnotherLongName();
 
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..2ca80a7889f8c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -914,16 +914,31 @@ struct FormatStyle {
   /// Different ways to break after the function definition or
   /// declaration return type.
   enum ReturnTypeBreakingStyle : int8_t {
-/// Break after return type automatically.
-/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
+/// This is **deprecated**. See ``Automatic`` below.
+RTBS_None,
+/// Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
 /// \code
 ///   class A {
 /// int f() { return 0; };
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int
+///   LongName::AnotherLongName();
 /// \endcode
-RTBS_None,
+RTBS_Automatic,
+/// Same as ``Automatic`` above, except that there is no break after short
+/// ret

[clang] [polly] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-02-04 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Owen Pan via cfe-commits


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

owenca wrote:

You're right!

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


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

2024-02-04 Thread Piotr Zegar via cfe-commits

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

LGTM.
The only thing that I'm still thinking is if std is needed in name, and maybe 
it should be like just use-min-max.

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


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

2024-02-04 Thread via cfe-commits

https://github.com/fpasserby edited 
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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits

https://github.com/fpasserby edited 
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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits

https://github.com/fpasserby edited 
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] Frontend: sink vendor definitions from Basic to Frontend (PR #80364)

2024-02-04 Thread Saleem Abdulrasool via cfe-commits

https://github.com/compnerd updated 
https://github.com/llvm/llvm-project/pull/80364

>From c895dff0e59b9d851c15e5b3b25a735478b811fc Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool 
Date: Thu, 1 Feb 2024 15:37:39 -0800
Subject: [PATCH] Frontend: sink vendor definitions from Basic to Frontend

The vendor specific macro definitions are based on the vendor rather
than the target specific information. This ensures that `__APPLE__` is
always defined for `*-apple-*` targets. Take the opportunity to do
likewise with the `__AMD__` vendor macro.
---
 clang/lib/Basic/Targets/AMDGPU.cpp  | 1 -
 clang/lib/Basic/Targets/OSTargets.cpp   | 1 -
 clang/lib/Frontend/InitPreprocessor.cpp | 5 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 141501e8a4d9a..c6d68f591a5a8 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -266,7 +266,6 @@ ArrayRef 
AMDGPUTargetInfo::getTargetBuiltins() const {
 
 void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const {
-  Builder.defineMacro("__AMD__");
   Builder.defineMacro("__AMDGPU__");
 
   if (isAMDGCN(getTriple()))
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 899aefa6173ac..64b4514ba55bb 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -23,7 +23,6 @@ void getDarwinDefines(MacroBuilder &Builder, const 
LangOptions &Opts,
   const llvm::Triple &Triple, StringRef &PlatformName,
   VersionTuple &PlatformMinVersion) {
   Builder.defineMacro("__APPLE_CC__", "6000");
-  Builder.defineMacro("__APPLE__");
   Builder.defineMacro("__STDC_NO_THREADS__");
 
   // AddressSanitizer doesn't play well with source fortification, which is on
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bf..42c391a7214dc 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -804,6 +804,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 }
   }
 
+  if (TI.getTriple().getVendor() == llvm::Triple::AMD)
+Builder.defineMacro("__AMD__");
+  if (TI.getTriple().getVendor() == llvm::Triple::Apple)
+Builder.defineMacro("__APPLE__");
+
   // Define macros for the C11 / C++11 memory orderings
   Builder.defineMacro("__ATOMIC_RELAXED", "0");
   Builder.defineMacro("__ATOMIC_CONSUME", "1");

___
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-02-04 Thread via cfe-commits


@@ -1744,6 +1744,273 @@ a call to ``llvm.coro.suspend.retcon`` after resuming 
abnormally.
 In a yield-once coroutine, it is undefined behavior if the coroutine
 executes a call to ``llvm.coro.suspend.retcon`` after resuming in any way.
 
+.. _coro.await.suspend:
+
+'llvm.coro.await.suspend' Intrinsic

fpasserby wrote:

Renamed to `coro.await.suspend.void`

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


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

2024-02-04 Thread via cfe-commits


@@ -5036,14 +5036,17 @@ class CoroutineSuspendExpr : public Expr {
 
   Stmt *SubExprs[SubExpr::Count];
   OpaqueValueExpr *OpaqueValue = nullptr;
+  OpaqueValueExpr *OpaqueFramePtr = nullptr;

fpasserby wrote:

Now `__builtin_coro_frame` is used.

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -232,16 +237,59 @@ static LValueOrRValue 
emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
-  CGF.CurCoro.InSuspendBlock = true;
-  auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
-  CGF.CurCoro.InSuspendBlock = false;
+  const auto AwaitSuspendCanThrow =
+  AwaitSuspendStmtCanThrow(S.getSuspendExpr());
+
+  auto SuspendHelper = CodeGenFunction(CGF.CGM).generateAwaitSuspendHelper(
+  CGF.CurFn->getName(), Prefix, S, AwaitSuspendCanThrow);
 
-  if (SuspendRet != nullptr && SuspendRet->getType()->isIntegerTy(1)) {
-// Veto suspension if requested by bool returning await_suspend.
-BasicBlock *RealSuspendBlock =
-CGF.createBasicBlock(Prefix + Twine(".suspend.bool"));
-CGF.Builder.CreateCondBr(SuspendRet, RealSuspendBlock, ReadyBlock);
-CGF.EmitBlock(RealSuspendBlock);
+  llvm::CallBase *SuspendRet = nullptr;
+
+  {
+CGF.CurCoro.InSuspendBlock = true;
+
+auto FramePtrBinder = CodeGenFunction::OpaqueValueMappingData::bind(
+CGF, S.getOpaqueFramePtr(), S.getOpaqueFramePtr()->getSourceExpr());
+auto UnbindFramePtrOnExit =
+llvm::make_scope_exit([&] { FramePtrBinder.unbind(CGF); });
+
+SmallVector SuspendHelperCallArgs;
+SuspendHelperCallArgs.push_back(
+
CGF.getOrCreateOpaqueLValueMapping(S.getOpaqueValue()).getPointer(CGF));
+SuspendHelperCallArgs.push_back(
+CGF.getOrCreateOpaqueRValueMapping(S.getOpaqueFramePtr())
+.getScalarVal());
+SuspendHelperCallArgs.push_back(SuspendHelper);
+
+auto IID = llvm::Intrinsic::coro_await_suspend;
+if (S.getSuspendExpr()->getType()->isBooleanType())
+  IID = llvm::Intrinsic::coro_await_suspend_bool;
+else if (S.getSuspendExpr()->getType()->isVoidPointerType())
+  IID = llvm::Intrinsic::coro_await_suspend_handle;

fpasserby wrote:

Added switch.

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -1744,6 +1744,273 @@ a call to ``llvm.coro.suspend.retcon`` after resuming 
abnormally.
 In a yield-once coroutine, it is undefined behavior if the coroutine
 executes a call to ``llvm.coro.suspend.retcon`` after resuming in any way.
 
+.. _coro.await.suspend:
+
+'llvm.coro.await.suspend' Intrinsic
+^^
+::
+
+  declare void @llvm.coro.await.suspend(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``void awaiter.await_suspend(...)``' variant.
+
+Arguments:
+""
+
+The first argument is a pointer to `awaiter` object.
+
+The second argument is a pointer to the current coroutine's frame.
+
+The third argument is a pointer to the helper function encapsulating
+`await-suspend` logic. Its signature must be
+
+.. code-block:: llvm
+
+declare void @await_suspend_function(ptr %awaiter, ptr %hdl)
+
+Semantics:
+""
+
+The intrinsic must be used between corresponding `coro.save`_ and 
+`coro.suspend`_ calls. It is lowered to an inlined 
+`await_suspend_function` call during `CoroSplit`_ pass.
+
+Example:
+
+
+.. code-block:: llvm
+
+  ; before lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+call void @llvm.coro.await.suspend(
+ptr %awaiter,
+ptr %hdl,
+ptr @await_suspend_function)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+...
+
+  ; after lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+; the call to await_suspend_function is inlined

fpasserby wrote:

Fixed

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -1744,6 +1744,273 @@ a call to ``llvm.coro.suspend.retcon`` after resuming 
abnormally.
 In a yield-once coroutine, it is undefined behavior if the coroutine
 executes a call to ``llvm.coro.suspend.retcon`` after resuming in any way.
 
+.. _coro.await.suspend:
+
+'llvm.coro.await.suspend' Intrinsic
+^^
+::
+
+  declare void @llvm.coro.await.suspend(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``void awaiter.await_suspend(...)``' variant.

fpasserby wrote:

Added motivation (copied that comment almost verbatim)

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -1744,6 +1744,273 @@ a call to ``llvm.coro.suspend.retcon`` after resuming 
abnormally.
 In a yield-once coroutine, it is undefined behavior if the coroutine
 executes a call to ``llvm.coro.suspend.retcon`` after resuming in any way.
 
+.. _coro.await.suspend:
+
+'llvm.coro.await.suspend' Intrinsic
+^^
+::
+
+  declare void @llvm.coro.await.suspend(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``void awaiter.await_suspend(...)``' variant.
+
+Arguments:
+""
+
+The first argument is a pointer to `awaiter` object.
+
+The second argument is a pointer to the current coroutine's frame.
+
+The third argument is a pointer to the helper function encapsulating
+`await-suspend` logic. Its signature must be
+
+.. code-block:: llvm
+
+declare void @await_suspend_function(ptr %awaiter, ptr %hdl)
+
+Semantics:
+""
+
+The intrinsic must be used between corresponding `coro.save`_ and 
+`coro.suspend`_ calls. It is lowered to an inlined 
+`await_suspend_function` call during `CoroSplit`_ pass.
+
+Example:
+
+
+.. code-block:: llvm
+
+  ; before lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+call void @llvm.coro.await.suspend(
+ptr %awaiter,
+ptr %hdl,
+ptr @await_suspend_function)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+...
+
+  ; after lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+; the call to await_suspend_function is inlined
+call void @await_suspend_function(
+ptr %awaiter,
+ptr %hdl)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)   
+...
+
+  ; helper function example
+  define void @await_suspend_function(ptr %awaiter, ptr %hdl)
+entry:
+  %hdl.tmp = alloca %"struct.std::coroutine_handle"
+  %hdl.result.tmp = alloca %"struct.std::coroutine_handle"
+  %hdl.promise.tmp = alloca %"struct.std::coroutine_handle.0"
+  %hdl.promise = call ptr 
@"std::corouine_handle::from_address"(ptr %hdl)
+  %hdl.promise.tmp.dive = getelementptr inbounds 
%"struct.std::coroutine_handle.0",
+ptr %hdl.promise.tmp, i32 0, i32 0
+  %hdl.promise.tmp.dive2 = getelementptr inbounds 
%"struct.std::coroutine_handle",
+ptr %hdl.promise.tmp.dive, i32 0, i32 0
+  store ptr %hdl.promise, ptr %hdl.promise.tmp.dive2
+  call void @llvm.memcpy.p0.p0.i64(ptr %hdl.tmp, ptr %hdl.promise.tmp, i64 
8, i1 false)
+  %hdl.tmp.dive = getelementptr inbounds %"struct.std::coroutine_handle",
+ptr %hdl.tmp, i32 0, i32 0
+  %hdl.arg = load ptr, ptr %hdl.tmp.dive
+  call void @"Awaiter::await_suspend"(ptr %awaiter, ptr %hdl.arg)
+  ret void
+
+.. _coro.await.suspend.bool:
+
+'llvm.coro.await.suspend.bool' Intrinsic
+^^
+::
+
+  declare i1 @llvm.coro.await.suspend.bool(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend.bool``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``bool awaiter.await_suspend(...)``' variant.
+
+Arguments:
+""
+
+The first argument is a pointer to `awaiter` object.
+
+The second argument is a pointer to the current coroutine's frame.
+
+The third argument is a pointer to the helper function encapsulating
+`await-suspend` logic. Its signature must be
+
+.. code-block:: llvm
+
+declare i1 @await_suspend_function(ptr %awaiter, ptr %hdl)
+
+Semantics:
+""
+
+The intrinsic must be used between corresponding `coro.save`_ and 
+`coro.suspend`_ calls. It is lowered to an inlined 
+`await_suspend_function` call during `CoroSplit`_ pass.
+
+If `await_suspend_function` call returns `true`, the current coroutine is
+immediately resumed.
+
+Example:
+
+
+.. code-block:: llvm
+
+  ; before lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+%resume = call i1 @llvm.coro.await.suspend(
+ptr %awaiter,
+ptr %hdl,
+ptr @await_suspend_function)
+br i1 %resume, %await.suspend.bool, %await.ready
+  await.suspend.bool:
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+...
+  await.ready:
+call void @"Awaiter::await_ready"(ptr %awaiter)

fpasserby wrote:

Yes, was a typo.

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -1744,6 +1744,273 @@ a call to ``llvm.coro.suspend.retcon`` after resuming 
abnormally.
 In a yield-once coroutine, it is undefined behavior if the coroutine
 executes a call to ``llvm.coro.suspend.retcon`` after resuming in any way.
 
+.. _coro.await.suspend:
+
+'llvm.coro.await.suspend' Intrinsic
+^^
+::
+
+  declare void @llvm.coro.await.suspend(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``void awaiter.await_suspend(...)``' variant.
+
+Arguments:
+""
+
+The first argument is a pointer to `awaiter` object.
+
+The second argument is a pointer to the current coroutine's frame.
+
+The third argument is a pointer to the helper function encapsulating
+`await-suspend` logic. Its signature must be
+
+.. code-block:: llvm
+
+declare void @await_suspend_function(ptr %awaiter, ptr %hdl)
+
+Semantics:
+""
+
+The intrinsic must be used between corresponding `coro.save`_ and 
+`coro.suspend`_ calls. It is lowered to an inlined 
+`await_suspend_function` call during `CoroSplit`_ pass.
+
+Example:
+
+
+.. code-block:: llvm
+
+  ; before lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+call void @llvm.coro.await.suspend(
+ptr %awaiter,
+ptr %hdl,
+ptr @await_suspend_function)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+...
+
+  ; after lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+; the call to await_suspend_function is inlined
+call void @await_suspend_function(
+ptr %awaiter,
+ptr %hdl)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)   
+...
+
+  ; helper function example
+  define void @await_suspend_function(ptr %awaiter, ptr %hdl)
+entry:
+  %hdl.tmp = alloca %"struct.std::coroutine_handle"
+  %hdl.result.tmp = alloca %"struct.std::coroutine_handle"
+  %hdl.promise.tmp = alloca %"struct.std::coroutine_handle.0"
+  %hdl.promise = call ptr 
@"std::corouine_handle::from_address"(ptr %hdl)
+  %hdl.promise.tmp.dive = getelementptr inbounds 
%"struct.std::coroutine_handle.0",
+ptr %hdl.promise.tmp, i32 0, i32 0
+  %hdl.promise.tmp.dive2 = getelementptr inbounds 
%"struct.std::coroutine_handle",
+ptr %hdl.promise.tmp.dive, i32 0, i32 0
+  store ptr %hdl.promise, ptr %hdl.promise.tmp.dive2
+  call void @llvm.memcpy.p0.p0.i64(ptr %hdl.tmp, ptr %hdl.promise.tmp, i64 
8, i1 false)
+  %hdl.tmp.dive = getelementptr inbounds %"struct.std::coroutine_handle",
+ptr %hdl.tmp, i32 0, i32 0
+  %hdl.arg = load ptr, ptr %hdl.tmp.dive

fpasserby wrote:

Reduced the amount of IR

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -79,6 +79,73 @@ using namespace llvm;
 
 namespace {
 
+// Created on demand if the coro-early pass has work to do.
+class Lowerer : public coro::LowererBase {

fpasserby wrote:

Yes, it is possible. Switched to a simple function.

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] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-04 Thread via cfe-commits


@@ -79,6 +79,73 @@ using namespace llvm;
 
 namespace {
 
+// Created on demand if the coro-early pass has work to do.
+class Lowerer : public coro::LowererBase {
+  IRBuilder<> Builder;
+  void lowerAwaitSuspend(CoroAwaitSuspendInst *CB);
+
+public:
+  Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
+
+  void lowerAwaitSuspends(Function &F);
+};
+
+void Lowerer::lowerAwaitSuspend(CoroAwaitSuspendInst *CB) {
+  auto Helper = CB->getHelperFunction();
+  auto Awaiter = CB->getAwaiter();
+  auto FramePtr = CB->getFrame();
+
+  Builder.SetInsertPoint(CB);
+
+  CallBase *NewCall = nullptr;
+  if (auto Invoke = dyn_cast(CB)) {
+auto HelperInvoke =
+Builder.CreateInvoke(Helper, Invoke->getNormalDest(),
+ Invoke->getUnwindDest(), {Awaiter, FramePtr});
+
+HelperInvoke->setCallingConv(Invoke->getCallingConv());
+std::copy(Invoke->bundle_op_info_begin(), Invoke->bundle_op_info_end(),
+  HelperInvoke->bundle_op_info_begin());
+AttributeList NewAttributes =
+Invoke->getAttributes().removeParamAttributes(Context, 2);
+HelperInvoke->setAttributes(NewAttributes);
+HelperInvoke->setDebugLoc(Invoke->getDebugLoc());
+NewCall = HelperInvoke;
+  } else if (auto Call = dyn_cast(CB)) {
+auto HelperCall = Builder.CreateCall(Helper, {Awaiter, FramePtr});
+
+AttributeList NewAttributes =
+Call->getAttributes().removeParamAttributes(Context, 2);
+HelperCall->setAttributes(NewAttributes);
+HelperCall->setDebugLoc(Call->getDebugLoc());
+NewCall = HelperCall;
+  }

fpasserby wrote:

Added unreachable

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


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

2024-02-04 Thread via cfe-commits


@@ -79,6 +79,73 @@ using namespace llvm;
 
 namespace {
 
+// Created on demand if the coro-early pass has work to do.
+class Lowerer : public coro::LowererBase {
+  IRBuilder<> Builder;
+  void lowerAwaitSuspend(CoroAwaitSuspendInst *CB);
+
+public:
+  Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
+
+  void lowerAwaitSuspends(Function &F);
+};
+
+void Lowerer::lowerAwaitSuspend(CoroAwaitSuspendInst *CB) {
+  auto Helper = CB->getHelperFunction();
+  auto Awaiter = CB->getAwaiter();
+  auto FramePtr = CB->getFrame();
+
+  Builder.SetInsertPoint(CB);
+
+  CallBase *NewCall = nullptr;
+  if (auto Invoke = dyn_cast(CB)) {
+auto HelperInvoke =
+Builder.CreateInvoke(Helper, Invoke->getNormalDest(),
+ Invoke->getUnwindDest(), {Awaiter, FramePtr});
+
+HelperInvoke->setCallingConv(Invoke->getCallingConv());
+std::copy(Invoke->bundle_op_info_begin(), Invoke->bundle_op_info_end(),
+  HelperInvoke->bundle_op_info_begin());
+AttributeList NewAttributes =
+Invoke->getAttributes().removeParamAttributes(Context, 2);
+HelperInvoke->setAttributes(NewAttributes);
+HelperInvoke->setDebugLoc(Invoke->getDebugLoc());
+NewCall = HelperInvoke;
+  } else if (auto Call = dyn_cast(CB)) {
+auto HelperCall = Builder.CreateCall(Helper, {Awaiter, FramePtr});
+
+AttributeList NewAttributes =
+Call->getAttributes().removeParamAttributes(Context, 2);
+HelperCall->setAttributes(NewAttributes);
+HelperCall->setDebugLoc(Call->getDebugLoc());
+NewCall = HelperCall;
+  }
+
+  CB->replaceAllUsesWith(NewCall);
+  CB->eraseFromParent();
+
+  InlineFunctionInfo FnInfo;
+  auto InlineRes = InlineFunction(*NewCall, FnInfo);
+  assert(InlineRes.isSuccess() && "Expected inlining to succeed");
+  (void)InlineRes;

fpasserby wrote:

Removed manual inlining

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


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

2024-02-04 Thread via cfe-commits


@@ -79,6 +79,73 @@ using namespace llvm;
 
 namespace {
 
+// Created on demand if the coro-early pass has work to do.
+class Lowerer : public coro::LowererBase {
+  IRBuilder<> Builder;
+  void lowerAwaitSuspend(CoroAwaitSuspendInst *CB);
+
+public:
+  Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
+
+  void lowerAwaitSuspends(Function &F);
+};
+
+void Lowerer::lowerAwaitSuspend(CoroAwaitSuspendInst *CB) {
+  auto Helper = CB->getHelperFunction();
+  auto Awaiter = CB->getAwaiter();
+  auto FramePtr = CB->getFrame();
+
+  Builder.SetInsertPoint(CB);
+
+  CallBase *NewCall = nullptr;
+  if (auto Invoke = dyn_cast(CB)) {
+auto HelperInvoke =
+Builder.CreateInvoke(Helper, Invoke->getNormalDest(),
+ Invoke->getUnwindDest(), {Awaiter, FramePtr});
+
+HelperInvoke->setCallingConv(Invoke->getCallingConv());
+std::copy(Invoke->bundle_op_info_begin(), Invoke->bundle_op_info_end(),
+  HelperInvoke->bundle_op_info_begin());
+AttributeList NewAttributes =
+Invoke->getAttributes().removeParamAttributes(Context, 2);
+HelperInvoke->setAttributes(NewAttributes);
+HelperInvoke->setDebugLoc(Invoke->getDebugLoc());
+NewCall = HelperInvoke;
+  } else if (auto Call = dyn_cast(CB)) {
+auto HelperCall = Builder.CreateCall(Helper, {Awaiter, FramePtr});
+
+AttributeList NewAttributes =
+Call->getAttributes().removeParamAttributes(Context, 2);
+HelperCall->setAttributes(NewAttributes);
+HelperCall->setDebugLoc(Call->getDebugLoc());
+NewCall = HelperCall;
+  }
+
+  CB->replaceAllUsesWith(NewCall);
+  CB->eraseFromParent();
+
+  InlineFunctionInfo FnInfo;
+  auto InlineRes = InlineFunction(*NewCall, FnInfo);
+  assert(InlineRes.isSuccess() && "Expected inlining to succeed");
+  (void)InlineRes;
+}
+
+void Lowerer::lowerAwaitSuspends(Function &F) {

fpasserby wrote:

Moved collection to the construction of Shape

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


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

2024-02-04 Thread via cfe-commits


@@ -1744,6 +1744,273 @@ a call to ``llvm.coro.suspend.retcon`` after resuming 
abnormally.
 In a yield-once coroutine, it is undefined behavior if the coroutine
 executes a call to ``llvm.coro.suspend.retcon`` after resuming in any way.
 
+.. _coro.await.suspend:
+
+'llvm.coro.await.suspend' Intrinsic
+^^
+::
+
+  declare void @llvm.coro.await.suspend(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``void awaiter.await_suspend(...)``' variant.
+
+Arguments:
+""
+
+The first argument is a pointer to `awaiter` object.
+
+The second argument is a pointer to the current coroutine's frame.
+
+The third argument is a pointer to the helper function encapsulating
+`await-suspend` logic. Its signature must be
+
+.. code-block:: llvm
+
+declare void @await_suspend_function(ptr %awaiter, ptr %hdl)
+
+Semantics:
+""
+
+The intrinsic must be used between corresponding `coro.save`_ and 
+`coro.suspend`_ calls. It is lowered to an inlined 
+`await_suspend_function` call during `CoroSplit`_ pass.
+
+Example:
+
+
+.. code-block:: llvm
+
+  ; before lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+call void @llvm.coro.await.suspend(
+ptr %awaiter,
+ptr %hdl,
+ptr @await_suspend_function)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+...
+
+  ; after lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+; the call to await_suspend_function is inlined
+call void @await_suspend_function(
+ptr %awaiter,
+ptr %hdl)
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)   
+...
+
+  ; helper function example
+  define void @await_suspend_function(ptr %awaiter, ptr %hdl)
+entry:
+  %hdl.tmp = alloca %"struct.std::coroutine_handle"
+  %hdl.result.tmp = alloca %"struct.std::coroutine_handle"
+  %hdl.promise.tmp = alloca %"struct.std::coroutine_handle.0"
+  %hdl.promise = call ptr 
@"std::corouine_handle::from_address"(ptr %hdl)
+  %hdl.promise.tmp.dive = getelementptr inbounds 
%"struct.std::coroutine_handle.0",
+ptr %hdl.promise.tmp, i32 0, i32 0
+  %hdl.promise.tmp.dive2 = getelementptr inbounds 
%"struct.std::coroutine_handle",
+ptr %hdl.promise.tmp.dive, i32 0, i32 0
+  store ptr %hdl.promise, ptr %hdl.promise.tmp.dive2
+  call void @llvm.memcpy.p0.p0.i64(ptr %hdl.tmp, ptr %hdl.promise.tmp, i64 
8, i1 false)
+  %hdl.tmp.dive = getelementptr inbounds %"struct.std::coroutine_handle",
+ptr %hdl.tmp, i32 0, i32 0
+  %hdl.arg = load ptr, ptr %hdl.tmp.dive
+  call void @"Awaiter::await_suspend"(ptr %awaiter, ptr %hdl.arg)
+  ret void
+
+.. _coro.await.suspend.bool:
+
+'llvm.coro.await.suspend.bool' Intrinsic
+^^
+::
+
+  declare i1 @llvm.coro.await.suspend.bool(
+ptr ,
+ptr ,
+ptr )
+
+Overview:
+"
+
+The '``llvm.coro.await.suspend.bool``' intrinsic hides C++ `await-suspend`
+block code from optimizations on presplit coroutine body 
+to avoid miscompilations. This version of intrinsic corresponds to 
+'``bool awaiter.await_suspend(...)``' variant.
+
+Arguments:
+""
+
+The first argument is a pointer to `awaiter` object.
+
+The second argument is a pointer to the current coroutine's frame.
+
+The third argument is a pointer to the helper function encapsulating
+`await-suspend` logic. Its signature must be
+
+.. code-block:: llvm
+
+declare i1 @await_suspend_function(ptr %awaiter, ptr %hdl)
+
+Semantics:
+""
+
+The intrinsic must be used between corresponding `coro.save`_ and 
+`coro.suspend`_ calls. It is lowered to an inlined 
+`await_suspend_function` call during `CoroSplit`_ pass.
+
+If `await_suspend_function` call returns `true`, the current coroutine is
+immediately resumed.
+
+Example:
+
+
+.. code-block:: llvm
+
+  ; before lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+%resume = call i1 @llvm.coro.await.suspend(
+ptr %awaiter,
+ptr %hdl,
+ptr @await_suspend_function)
+br i1 %resume, %await.suspend.bool, %await.ready
+  await.suspend.bool:
+%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+...
+  await.ready:
+call void @"Awaiter::await_ready"(ptr %awaiter)
+...
+
+  ; after lowering
+  await.suspend:
+%save = call token @llvm.coro.save(ptr %hdl)
+; the call to await_suspend_function is inlined
+%resume = call i1 @await_suspend_function(
+ptr %awaiter,
+ptr %hdl)
+ 

[clang] [Clang] Fix a crash when dumping a pack indexing type. (PR #80439)

2024-02-04 Thread Björn Pettersson via cfe-commits

bjope wrote:

@cor3ntin , our downstream code is doing some extra semantic checks using code 
like this in Sema::CheckVariableDeclarationType:

```
  if (!T->isIncompleteType() && !isDependentOrGNUAutoType(T) && 
!T->isPlaceholderType()) {
uint64_t Size = Context.getTypeSizeInChars(T).getQuantity();
   ...
  }
```
That is hitting the infinite recursion.

So we protect the type size calculation by checking if the type is incomplete, 
dependent, etc.
But as Bevin pointed out here 
https://github.com/llvm/llvm-project/pull/72644/files#r1469490392 the "broken" 
PackIndexingType isn't reported as isDependent, and neither as isIncomplete.

I must say that I don't know that much about this to say what is correct. Maybe 
out downstream semantic checks should be protected in some more way to avoid 
this problem.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

zygoloid wrote:

For `not!`, I think adding a space is the right choice for a C++ code 
formatter: `not !b` should probably be formatted with a space, not as `not!b`, 
even though it's a pretty strange thing to write.

I wonder if this should instead be:
```suggestion
if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::comma)) {
```
... with the `)` and `,` cases firing only in places where we can locally tell 
this isn't actually a `not` operator at all.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

zygoloid wrote:

Another data point: the [Python style 
guide](https://peps.python.org/pep-0008/#other-recommendations) also recommends 
always putting a space after `not`.

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


[llvm] [clang] [RISCV] Add support for RISC-V Pointer Masking (PR #79929)

2024-02-04 Thread Michael Maitland via cfe-commits

https://github.com/michaelmaitland updated 
https://github.com/llvm/llvm-project/pull/79929

>From bc844fb4e033063c0d7b5ab361c44e4823e76fa3 Mon Sep 17 00:00:00 2001
From: Michael Maitland 
Date: Mon, 29 Jan 2024 12:33:59 -0800
Subject: [PATCH 1/3] [RISCV] Add support for RISC-V Pointer Masking

This patch implements the v0.8.1 specification. This includes support of
the `Ssnpm`, `Smnpm`, `Smmpm`, `Sspm` and `Supm` extensions that make up
RISC-V pointer masking.

All of these extensions only require emitting attribute containing
correct `march` string. `Ssnpm`, `Smnpm`, `Smmpm` extensions introduce a
2-bit WARL field (PMM). The extension does not specify how PMM is set,
and therefore this patch does not need to address this. One example of
how it *could* be set is using the Zicsr instructions to update the PMM
bits of the described registers.

The full specification can be found at
https://github.com/riscv/riscv-j-extension/blob/master/zjpm-spec.pdf
---
 .../test/Preprocessor/riscv-target-features.c | 45 +++
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/lib/Support/RISCVISAInfo.cpp |  6 +++
 llvm/lib/Target/RISCV/RISCVFeatures.td| 34 ++
 llvm/test/CodeGen/RISCV/attributes.ll | 20 +
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |  5 +++
 7 files changed, 114 insertions(+)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 2361c83a5a610..82d2efd51a091 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -142,6 +142,11 @@
 
 // Experimental extensions
 
+// CHECK-NOT: __riscv_smmpm{{.*$}}
+// CHECK-NOT: __riscv_smnpm{{.*$}}
+// CHECK-NOT: __riscv_ssnpm{{.*$}}
+// CHECK-NOT: __riscv_sspm{{.*$}}
+// CHECK-NOT: __riscv_supm{{.*$}}
 // CHECK-NOT: __riscv_zaamo {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalrsc {{.*$}}
@@ -1405,6 +1410,46 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
 // CHECK-ZICFISS-EXT: __riscv_zicfiss 4000{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_ssnpm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_ssnpm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
+// CHECK-SSNPM-EXT: __riscv_ssnpm 8000{{$}}
+
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_smnpm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_smnpm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
+// CHECK-SMNPM-EXT: __riscv_smnpm 8000{{$}}
+
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_smmpm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_smmpm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
+// CHECK-SMMPM-EXT: __riscv_smmpm 8000{{$}}
+
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_sspm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_sspm0p8 -E -dM %s -menable-experimental-extensions \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
+// CHECK-SSPM-EXT: __riscv_sspm 8000{{$}}
+
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_supm0p8 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_supm0p8 -E -dM %s -menable-experimental-extensions \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
+// CHECK-SUPM-EXT: __riscv_supm 8000{{$}}
+
 // Misaligned
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 06292f05b90b8..d07f0480f7024 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -226,6 +226,9 @@ LLVM supports (to various degrees) a number of experimental 
extensions.  All exp
 
 The primary goal of experimental support is to assist in the process of 
ratification by providing an existence proof of an implementation, and 
simplifying efforts to validate the value of a proposed extension against large 
code bases.  Experimental extensions are expected to either transition to 
ratified status, or be eventually removed.  The decision on whether to accept 
an experimental extension is currently done on an entirely case by case basis; 
if you want to propose one, a

[clang] ffaedc2 - [Basic] Simplify uses of StringRef::consume_front (NFC)

2024-02-04 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-02-04T14:57:26-08:00
New Revision: ffaedc2735cfcf2595fe65a75ed910a9c661391b

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

LOG: [Basic] Simplify uses of StringRef::consume_front (NFC)

Added: 


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

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 90a1516ecdd20..e80589dde0ecb 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -168,9 +168,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   return true;
 }
 
-bool HasLeftParen = false;
-if (S.consume_front("{"))
-  HasLeftParen = true;
+bool HasLeftParen = S.consume_front("{");
 if (S.empty())
   return false;
 if (S.front() != 'v' && S.front() != 's' && S.front() != 'a') {
@@ -196,9 +194,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   Name = S.data() - 1;
   return true;
 }
-bool HasLeftBracket = false;
-if (S.consume_front("["))
-  HasLeftBracket = true;
+bool HasLeftBracket = S.consume_front("[");
 unsigned long long N;
 if (S.empty() || consumeUnsignedInteger(S, 10, N))
   return false;



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


[clang-tools-extra] 92d5f64 - [clang-tidy] Use StringRef::contains (NFC)

2024-02-04 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-02-04T14:57:30-08:00
New Revision: 92d5f644281cba56baa9b42dfc298db7f2c30003

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

LOG: [clang-tidy] Use StringRef::contains (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index e6f44dd51b459..5db9e99ab2370 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -658,7 +658,7 @@ std::string 
IdentifierNamingCheck::HungarianNotation::getEnumPrefix(
   const auto *ED = cast(ECD->getDeclContext());
 
   std::string Name = ED->getName().str();
-  if (std::string::npos != Name.find("enum")) {
+  if (StringRef(Name).contains("enum")) {
 Name = Name.substr(strlen("enum"), Name.length() - strlen("enum"));
 Name = Name.erase(0, Name.find_first_not_of(' '));
   }



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


[clang] [Clang] Fix a crash when dumping a pack indexing type. (PR #80439)

2024-02-04 Thread Björn Pettersson via cfe-commits


@@ -0,0 +1,25 @@
+// RUN: not %clang_cc1 -std=c++2c -ast-dump %s | FileCheck  %s
+
+namespace InvalidPacksShouldNotCrash {
+
+struct NotAPack;
+template  typename Tp>
+void not_pack() {
+int i = 0;
+i...[0]; // expected-error {{i does not refer to the name of a parameter 
pack}}
+V...[0]; // expected-error {{V does not refer to the name of a parameter 
pack}}
+NotAPack...[0] a; // expected-error{{'NotAPack' does not refer to the name 
of a parameter pack}}

bjope wrote:

If you change this to an array, such as

`NotAPack...[0] a[2];`

then I think you hit the same kind of infinite recursion as we see downstream 
even without the array nodtation.

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


[clang] [Format] Fix detection of languages when reading from stdin (PR #79051)

2024-02-04 Thread Owen Pan via cfe-commits

owenca wrote:

@bhamiltoncx Thanks for the fix! Nevertheless, it seems that this triggered a 
new regression. See #80621.

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


[clang-tools-extra] [clangd] Add 'apply all clangd fixes' and 'apply all '_' fixes' QuickFixes (PR #79867)

2024-02-04 Thread Tor Shepherd via cfe-commits

torshepherd wrote:

Also pinging @kadircet who recently worked on Include Cleaner's similar batch 
fixes

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


[clang-tools-extra] [clang] [llvm] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits


@@ -526,12 +542,13 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) 
const {
   case Instruction::ICmp:
 // TODO: Cover additional opcodes.
 return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ComputeReductionResult:
+return true;

ayalz wrote:

nit: fallthrough to join other `true` opcodes below?

Can these two improvements of onlyFirstLaneUsed() (additional opcodes and 
additional operands) be pushed independently?

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


[llvm] [clang] [clang-tools-extra] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits


@@ -512,7 +518,17 @@ void VPInstruction::execute(VPTransformState &State) {
 if (!hasResult())
   continue;
 assert(GeneratedValue && "generateInstruction must produce a value");
-State.set(this, GeneratedValue, Part);
+if (GeneratedValue->getType()->isVectorTy())
+  State.set(this, GeneratedValue, Part);
+else {
+  if (getOpcode() == VPInstruction::ComputeReductionResult) {
+State.set(this, GeneratedValue, VPIteration(Part, 0));
+  } else {
+assert((State.VF.isScalar() || vputils::onlyFirstLaneUsed(this)) &&
+   "scalar value but not only first lane used");
+State.set(this, GeneratedValue, VPIteration(Part, 0));

ayalz wrote:

nit: can simplify into a single State.set() with the condition folded into the 
assert.

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


[clang] [clang-tools-extra] [llvm] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits

https://github.com/ayalz commented:

> At the moment, some VPInstructions create only a single scalar value, but use 
> VPTransformatState's 'vector' storage for this value. Those values are 
> effectively uniform-per-VF (or in some cases uniform-across-VF-and-UF). Using 
> the vector/per-part storage doesn't interact well with other recipes, that 
> more accurately using (Part, Lane) to look up scalar values and prevents 
> VPInstructions creating scalars from interacting with other recipes working 
> with scalars.
> 
> This PR tries to unify handling of scalars by using (Part, 0) for scalar 
> values where only the first lane is demanded. This allows using 
> VPInstructions with other recipes like VPScalarCastRecipe and is also needed 
> when using VPInstructions in more cases otuside the vector loop region to 
> generate scalars.
> 

Perhaps it is the "other recipes" who should be fixed, to more consistently 
store their single scalar in per-part storage rather than lane zero? The 
current design of State is to hold UF per-part Values whenever possible, be 
they vectors or (uniform) scalars, and otherwise holds VF*UF per-lane Values, 
for every VPValue. The hasVectorValue() and hasScalarValue() indicators should 
better be renamed hasValuePerPart() and hasValuePerLane(), respectively.

Unrolling loop-regions in VPlan by UF would simplify State to hold a single 
per-part Value or VF per-lane Values.  Further unrolling replicating-regions 
and replicating-recipes by VF would simplify State to hold a single Value per 
VPValue.

The current get() functions are overly complex, as they bridge gaps by packing 
VF scalar elements into a vector on-demand for a scalar producer to feed a 
vector consumer, by extracting VF scalar elements from a vector producer to 
feed a scalar-replicating consumer, and more. Introducing explicit pack and 
extract recipes in VPlan could simplify its code-gen and State, prior to 
unrollings.

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


[clang] [clang-tools-extra] [llvm] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits


@@ -213,8 +213,13 @@ VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi() {
 }
 
 Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) {
-  if (Def->isLiveIn())
-return Def->getLiveInIRValue();
+  if (Def->isLiveIn()) {
+if (Value *V = Def->getLiveInIRValue())

ayalz wrote:

A LiveIn Def must have a LiveInIRValue, is this `if` an assert?

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


[clang-tools-extra] [clang] [llvm] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits


@@ -1389,6 +1389,13 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {
 
   /// Returns the result type of the cast.
   Type *getResultType() const { return ResultTy; }
+
+  bool onlyFirstLaneUsed(const VPValue *Op) const override {
+// At the moment, only scalar codegen is implemented.

ayalz wrote:

```suggestion
// At the moment, only uniform codegen is implemented.
```
?
scalar codegen in general may use other lanes.

Can this improvement of onlyFirstLaneUsed() be pushed independently?

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


[llvm] [clang] [clang-tools-extra] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-04 Thread via cfe-commits


@@ -116,8 +116,7 @@ define void @test_widen(ptr noalias %a, ptr readnone %b) #4 
{
 ; TFA_INTERLEAVE-NEXT:[[TMP18:%.*]] = getelementptr inbounds i64, ptr 
[[TMP15]], i64 [[TMP17]]
 ; TFA_INTERLEAVE-NEXT:call void @llvm.masked.store.nxv2i64.p0( [[TMP13]], ptr [[TMP15]], i32 8,  [[ACTIVE_LANE_MASK]])
 ; TFA_INTERLEAVE-NEXT:call void @llvm.masked.store.nxv2i64.p0( [[TMP14]], ptr [[TMP18]], i32 8,  [[ACTIVE_LANE_MASK2]])
-; TFA_INTERLEAVE-NEXT:[[INDEX_NEXT:%.*]] = add i64 [[INDEX]], [[TMP6]]
-; TFA_INTERLEAVE-NEXT:[[INDEX_NEXT4]] = add i64 [[INDEX]], [[TMP6]]
+; TFA_INTERLEAVE-NEXT:[[INDEX_NEXT]] = add i64 [[INDEX]], [[TMP6]]

ayalz wrote:

Only implication visible in existing tests below is cse'ing of the Canonical IV 
bump when active lane masks are used. Would other test(s) be relevant?

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


  1   2   >