[clang] [Clang] Correctly construct template arguments for file-scope template template parameters (PR #76811)

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

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


[clang] [Clang] Correctly construct template arguments for file-scope template template parameters (PR #76811)

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


@@ -345,15 +345,19 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 
   using namespace TemplateInstArgsHelpers;
   const Decl *CurDecl = ND;
+
+  if (!ND)

zyn0217 wrote:

> Can we also get a comment here why this makes sense to call 
> `Decl::castFromDeclContext(DC)` if `CurrDecl` is not present?

I think this has been explained in the comment above the function.
```cpp
/// \param DC In the event we don't HAVE a declaration yet, we instead provide
///  the decl context where it will be created.  In this case, the `Innermost`
///  should likely be provided.  If ND is non-null, this is ignored.
```

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


[clang] [OpenACC] Implement 'default' clause parsing. (PR #77002)

2024-01-04 Thread via cfe-commits


@@ -291,13 +307,63 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser ) 
{
   return DirKind;
 }
 
+bool ClauseHasRequiredParens(OpenACCClauseKind Kind) {
+  return Kind == OpenACCClauseKind::Default;
+}
+
+bool ParseOpenACCClauseParams(Parser , OpenACCClauseKind Kind) {
+  BalancedDelimiterTracker Parens(P, tok::l_paren,
+  tok::annot_pragma_openacc_end);
+
+  if (ClauseHasRequiredParens(Kind)) {
+if (Parens.expectAndConsume()) {
+  // We are missing a paren, so assume that the person just forgot the
+  // parameter.  Return 'false' so we try to continue on and parse the next
+  // clause.
+  P.SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openacc_end,
+  Parser::StopBeforeMatch);
+  return false;
+}
+
+switch (Kind) {
+case OpenACCClauseKind::Default: {
+  Token DefKindTok = P.getCurToken();
+  // 'default' accepts 'present' or 'none'. Be a little liberal here to
+  // allow things like 'auto' or 'default'.
+  // TODO ERICH: Make 'keyword like tokens' via tok::getKeywordSpelling'
+  // or 'getIdentifierInfo' isKeyword
+  if (!DefKindTok.is(tok::identifier) &&
+  (DefKindTok.isAnnotation() || !DefKindTok.getIdentifierInfo() ||
+   !DefKindTok.getIdentifierInfo()->isKeyword(P.getLangOpts( {
+P.Diag(P.getCurToken(), diag::err_expected) << tok::identifier;
+break;
+  }

cor3ntin wrote:

I think `!DefKindTok.is(tok::identifier)` is sufficient here.
A keyword isn't an identifier (even if the both return getIdentifierInfo)  

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-04 Thread via cfe-commits

koute wrote:

> As for your diffs, it seems that you only handle the 
> `__riscv_save/restore_[2|1|0]`, which is incomplete. And the code is not 
> different with non-rve cases?

Yes, I mostly copy-pasted the existing code and removed all of the code dealing 
with registers not available on RV32E, so having only 
`__riscv_save/restore_[2|1|0]` is intended I suppose because there are only 
this many saved registers on RV32E. (There's probably a better way of doing it, 
and it looks like I screwed up the RV64E part of the patch.)

If I remember correctly I think I did this because otherwise compiling 
`compiler-rt` was not possible for RV32E and the compilation was spewing out 
errors about the unavailable registers? But I need to check this again once I 
finish porting this newest version of the patch to the most recent version of 
Rust.

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


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2024-01-04 Thread Haocong Lu via cfe-commits

Luhaocong wrote:

> Thanks for confirming. Do you need me to merge that for you?

It can't be better, thanks.

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


[clang] [Clang] Correctly construct template arguments for file-scope template template parameters (PR #76811)

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

zyn0217 wrote:

Just get back to this again. So, I have explored the other case and found it 
particular to explicit template arguments. In fact, we could slightly revise 
the motivating case to

```cpp
template 
concept C = false;

template  typename T>
int wow(T ts);

template  struct S {};

int main() { return wow(S{}); }
```

with an *explicit* template argument `int`. This takes us to such the branch in 
`DeduceTemplateArguments`,

https://github.com/llvm/llvm-project/blob/e0c554ad87d18dcbfcb9b6485d0da800ae1338d1/clang/lib/Sema/SemaTemplateDeduction.cpp#L4222-L4232

which would deduce the remaining template arguments from the given 
`FunctionTemplate` and fall into our `getTemplateInstantiationArgs` at the end 
of the day. It is also interesting to notice that the given 
`TemplateTemplateParmDecl` originates from this `FunctionTemplate`, and the 
surrounding `DeclContext`s for these `Decl`s has already been *redirected* to 
its associated `FunctionDecl` at `AdoptTemplateParameterList`.

https://github.com/llvm/llvm-project/blob/59af659ee3c790d06cb5e2bf580e042547c24323/clang/lib/AST/DeclTemplate.cpp#L202-L206


Therefore, I think our assumption that the `TemplateTemplateParmDecl` always 
resides in the `TranslationUnitDecl` is probably wrong. And, it is indeed murky 
that the `DeclContext`s where these `Decl`s live depend on the callers to this 
function...

Removing these checks works for the code above and, fortunately, doesn't fail 
any tests.

@erichkeane WDYT?

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-04 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

ping @HazardyKnusperkeks @owenca this is blocking releases on our side, 
anything concerning here?

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-04 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/76795

From 18ef1d8901835f5129f775d292425b808f42fe85 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 3 Jan 2024 09:28:35 +0100
Subject: [PATCH 1/3] [clang-format] Break after string literals with trailing
 line breaks

This restores a subset of functionality that was forego in
d68826dfbd987377ef6771d40c1d984f09ee3b9e.

Streaming multiple string literals is rare enough in practice, hence
that change makes sense in general. But it seems people were
incidentally relying on this for having line breaks after string
literals that ended with `\n`.

This patch tries to restore that behavior to prevent regressions in the
upcoming LLVM release, until we can implement some configuration based
approach as proposed in https://github.com/llvm/llvm-project/pull/69859.
---
 clang/lib/Format/TokenAnnotator.cpp   |  8 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++
 2 files changed, 18 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 3ac3aa3c5e3a22..27c6bb0ef6fe4f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5151,6 +5151,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
+  if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
+  // FIXME: Breaking after newlines seems useful in general. Turn this into
+  // an option and Recognize more cases like endl etc, and break 
independent
+  // of what comes after operator lessless.
+  Right.Next->is(tok::string_literal) &&
+  Left.TokenText.ends_with("\\n\"")) {
+return true;
+  }
   if (Right.is(TT_RequiresClause)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2cafc0438ffb46..cd3ffb611839d2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -10,6 +10,7 @@
 
 #include "FormatTestUtils.h"
 #include "TestLexer.h"
+#include "clang/Basic/TokenKinds.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -2499,6 +2500,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang

From ecc4284ce3d174944a09189d7ff3570df4ccbe70 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Thu, 4 Jan 2024 08:16:17 +0100
Subject: [PATCH 2/3] Add formatting test & drop extra include

---
 clang/unittests/Format/FormatTest.cpp | 2 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..25ef5c680af862 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26708,6 +26708,8 @@ TEST_F(FormatTest, PPBranchesInBracedInit) {
 
 TEST_F(FormatTest, StreamOutputOperator) {
   verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
+  verifyFormat("std::cout << \"foo\\n\"\n"
+   "  << \"bar\";");
 }
 
 TEST_F(FormatTest, BreakAdjacentStringLiterals) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index cd3ffb611839d2..decc0785c5cde7 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -10,7 +10,6 @@
 
 #include "FormatTestUtils.h"
 #include "TestLexer.h"
-#include "clang/Basic/TokenKinds.h"
 #include "gtest/gtest.h"
 
 namespace clang {

From d77d94f28c7553834c6372aee0a43946b53dbcf2 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Fri, 5 Jan 2024 08:48:35 +0100
Subject: [PATCH 3/3] Move comment around

---
 clang/lib/Format/TokenAnnotator.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 27c6bb0ef6fe4f..695eed7412d877 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5151,10 +5151,10 @@ bool TokenAnnotator::mustBreakBefore(const 
AnnotatedLine ,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
+  // FIXME: Breaking after newlines seems useful in general. Turn this into an
+  // option and Recognize more cases like endl etc, and break independent of
+  // what 

[clang] [coroutines] Introduce [[clang::coro_disable_lifetimebound]] (PR #76818)

2024-01-04 Thread Utkarsh Saxena via cfe-commits


@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a

usx95 wrote:

I have asked a person for their input regarding parameter attributes. IMO this 
can be added later as a followup, as the function attribute is definitely 
necessary for brevity (as compared to annotating all parameters).

(Keeping this open for others to comment.)

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


[clang] Update Clang.cpp (PR #77031)

2024-01-04 Thread via cfe-commits

cor3ntin wrote:

Can you provide a more complete description of your change, a better title?
Does this change needs tests? A release note?

Thanks

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


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2024-01-04 Thread via cfe-commits

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

Thanks for confirming.
Do you need me to merge that for you?

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-04 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

> Side note: shouldn't we also update `compiler-rt/lib/builtins/riscv/{save, 
> restore}.S`? E.g. with something like this:
>  [...]
> (I don't remember why exactly since I did it a long time ago, but for some 
> reason I do have this patch in my LLVM fork, so it probably was necessary for 
> _something_.)

Oh, it may be about stack alignment issue for libcalls. I may have fixed it.
As for your diffs, it seems that you only handle the 
`__riscv_save/restore_[2|1|0]`, which is incomplete. And the code is not 
different with non-rve cases?

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


[clang-tools-extra] Fix #75686: add iter_swap and iter_move to the matched name (PR #76117)

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


@@ -586,6 +586,16 @@ void swap(int&, int&) {
   throw 1;
 }
 
+void iter_swap(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_swap' which should not throw exceptions
+  throw 1;
+}
+
+void iter_move(int&, int&) {

PiotrZSL wrote:

One argument would be better. Just to keep it in sync with standard.
But thats not a blocker.

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


[clang] [flang] [compiler-rt] [clang-tools-extra] [libc] [libcxx] [lldb] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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

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


[clang] [flang] [compiler-rt] [clang-tools-extra] [libc] [libcxx] [lldb] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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

phoebewang wrote:

Thanks @FreddyLeaf !

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-04 Thread via cfe-commits

koute wrote:

Side note: shouldn't we also update `compiler-rt/lib/builtins/riscv/{save, 
restore}.S`? E.g. with something like this:

```patch
diff --git a/compiler-rt/lib/builtins/riscv/restore.S 
b/compiler-rt/lib/builtins/riscv/restore.S
index 73f64a920d66..2e185ecae3f7 100644
--- a/compiler-rt/lib/builtins/riscv/restore.S
+++ b/compiler-rt/lib/builtins/riscv/restore.S
@@ -20,6 +20,46 @@
 
   .text
 
+#if __riscv_abi_rve == 1
+
+#if __riscv_xlen == 32
+  .globl  __riscv_restore_2
+  .type   __riscv_restore_2,@function
+  .globl  __riscv_restore_1
+  .type   __riscv_restore_1,@function
+  .globl  __riscv_restore_0
+  .type   __riscv_restore_0,@function
+__riscv_restore_1:
+__riscv_restore_0:
+  lw  s1,  4(sp)
+  lw  s0,  8(sp)
+  lw  ra,  12(sp)
+  addisp, sp, 16
+  ret
+#elif __riscv_xlen == 64
+  .globl  __riscv_restore_2
+  .type   __riscv_restore_2,@function
+__riscv_restore_2:
+  ld  s1,  8(sp)
+  addisp, sp, 16
+  // fallthrough into __riscv_restore_1/0
+
+  .globl  __riscv_restore_1
+  .type   __riscv_restore_1,@function
+  .globl  __riscv_restore_0
+  .type   __riscv_restore_0,@function
+__riscv_restore_1:
+__riscv_restore_0:
+  ld  s0,  0(sp)
+  ld  ra,  8(sp)
+  addisp, sp, 16
+  ret
+#else
+# error "xlen must be 32 or 64 for save-restore implementation
+#endif
+
+#else
+
 #if __riscv_xlen == 32
 
   .globl  __riscv_restore_12
@@ -164,3 +204,5 @@ __riscv_restore_0:
 #else
 # error "xlen must be 32 or 64 for save-restore implementation
 #endif
+
+#endif
diff --git a/compiler-rt/lib/builtins/riscv/save.S 
b/compiler-rt/lib/builtins/riscv/save.S
index 85501aeb4c2e..86b62a369cd0 100644
--- a/compiler-rt/lib/builtins/riscv/save.S
+++ b/compiler-rt/lib/builtins/riscv/save.S
@@ -16,6 +16,54 @@
 
   .text
 
+#if __riscv_abi_rve == 1
+
+#if __riscv_xlen == 32
+  .globl  __riscv_save_2
+  .type   __riscv_save_2,@function
+  .globl  __riscv_save_1
+  .type   __riscv_save_1,@function
+  .globl  __riscv_save_0
+  .type   __riscv_save_0,@function
+__riscv_save_3:
+__riscv_save_2:
+__riscv_save_1:
+__riscv_save_0:
+  addisp, sp, -16
+  sw  s1,  4(sp)
+  sw  s0,  8(sp)
+  sw  ra,  12(sp)
+  jr  t0
+#elif __riscv_xlen == 64
+  .globl  __riscv_save_2
+  .type   __riscv_save_2,@function
+__riscv_save_3:
+__riscv_save_2:
+  addi   sp, sp, -112
+  li t1, 80
+.Lriscv_save_3_2:
+  sd s1, 88(sp)
+  sd s0, 96(sp)
+  sd ra, 104(sp)
+  addsp, sp, t1
+  jr t0
+
+  .globl  __riscv_save_1
+  .type   __riscv_save_1,@function
+  .globl  __riscv_save_0
+  .type   __riscv_save_0,@function
+__riscv_save_1:
+__riscv_save_0:
+  addi   sp, sp, -16
+  sd s0, 0(sp)
+  sd ra, 8(sp)
+  jr t0
+#else
+# error "xlen must be 32 or 64 for save-restore implementation
+#endif
+
+#else
+
 #if __riscv_xlen == 32
 
   .globl  __riscv_save_12
@@ -184,3 +232,5 @@ __riscv_save_0:
 #else
 # error "xlen must be 32 or 64 for save-restore implementation
 #endif
+
+#endif
```

(I don't remember why exactly since I did it a long time ago, but for some 
reason I do have this patch in my LLVM fork, so it probably was necessary for 
*something*.)

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


[clang] [flang] [compiler-rt] [clang-tools-extra] [libc] [libcxx] [lldb] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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


@@ -22,10 +22,7 @@ define void @add(ptr %pa, ptr %pb, ptr %pc) nounwind {
 ; X86-NEXT:vaddss %xmm0, %xmm1, %xmm0
 ; X86-NEXT:vmovss %xmm0, (%esp)
 ; X86-NEXT:calll __truncsfbf2
-; X86-NEXT:fstps {{[0-9]+}}(%esp)
-; X86-NEXT:vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; X86-NEXT:vmovd %xmm0, %eax
-; X86-NEXT:movw %ax, (%esi)
+; X86-NEXT:vmovsh %xmm0, (%esi)

FreddyLeaf wrote:

Thanks for explaining.

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


[clang] [flang] [compiler-rt] [clang-tools-extra] [libc] [libcxx] [lldb] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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

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

LGTM

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


[clang] [llvm] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-04 Thread Yeting Kuo via cfe-commits

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


[clang] [flang] [compiler-rt] [clang-tools-extra] [libc] [libcxx] [lldb] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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

https://github.com/phoebewang edited 
https://github.com/llvm/llvm-project/pull/76901
___
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] [libc] [flang] [libcxxabi] [libcxx] [lld] [lldb] [llvm] [mlir] [clang] static operators should evaluate object argument (PR #68485)

2024-01-04 Thread Tianlan Zhou via cfe-commits

SuperSodaSea wrote:

Problem solved :)

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


[clang] [flang] [compiler-rt] [clang-tools-extra] [libc] [libcxx] [lldb] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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


@@ -22,10 +22,7 @@ define void @add(ptr %pa, ptr %pb, ptr %pc) nounwind {
 ; X86-NEXT:vaddss %xmm0, %xmm1, %xmm0
 ; X86-NEXT:vmovss %xmm0, (%esp)
 ; X86-NEXT:calll __truncsfbf2
-; X86-NEXT:fstps {{[0-9]+}}(%esp)
-; X86-NEXT:vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; X86-NEXT:vmovd %xmm0, %eax
-; X86-NEXT:movw %ax, (%esi)
+; X86-NEXT:vmovsh %xmm0, (%esi)

phoebewang wrote:

`vmovsh` can store the low 16-bit to memory directly.
The original codes has ABI mistake, which store `bf16` without `f32`. Since 
`f32` uses X87 registers on 32-bit target, it need to store to another memory 
first, reload to store again.
The patch makes the result in XMM0, so one `vmovsh` is enough.

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


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2024-01-04 Thread Haocong Lu via cfe-commits

Luhaocong wrote:

> LGTM.
> 
> The format diagnostics are new in Clang 18 and as such we do not need a 
> release note. Correct?

This format diagnostics is existent until 
https://github.com/llvm/llvm-project/commit/04e6178ae932c9a1d939dcfe3ef1189f4bbb21aa
 had been committed. Clang 17.0.1 gives a warning: 
https://godbolt.org/z/xMdK9cETY.


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


[libc] [flang] [clang-tools-extra] [lldb] [llvm] [clang] [libcxx] [compiler-rt] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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


@@ -22,10 +22,7 @@ define void @add(ptr %pa, ptr %pb, ptr %pc) nounwind {
 ; X86-NEXT:vaddss %xmm0, %xmm1, %xmm0
 ; X86-NEXT:vmovss %xmm0, (%esp)
 ; X86-NEXT:calll __truncsfbf2
-; X86-NEXT:fstps {{[0-9]+}}(%esp)
-; X86-NEXT:vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; X86-NEXT:vmovd %xmm0, %eax
-; X86-NEXT:movw %ax, (%esi)
+; X86-NEXT:vmovsh %xmm0, (%esi)

FreddyLeaf wrote:

Sorry being not clear. I saw the original codes containing `; X86-NEXT: movw 
%ax, (%esi)` seems like we are changing from a word store to a xmm store here.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2024-01-04 Thread via cfe-commits


@@ -3369,6 +3369,36 @@ static void handleSectionAttr(Sema , Decl *D, const 
ParsedAttr ) {
   }
 }
 
+static void handleCodeModelAttr(Sema , Decl *D, const ParsedAttr ) {
+  StringRef CM;
+  StringRef Str;
+  SourceLocation LiteralLoc;
+  bool Ok = false;
+  // Check that it is a string.
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, ))
+return;
+
+  CM = Str;
+  if (S.getASTContext().getTargetInfo().getTriple().isLoongArch()) {
+Ok = CM == "normal" || CM == "medium" || CM == "extreme";
+CM = llvm::StringSwitch(CM)

heiher wrote:

Thanks. I can only keep `handleCodeModelAttr` because `handleSimpleAttribute` 
cannot pass a value to the constructor of `CodeModelAttr`.

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


[flang] [libc] [lldb] [compiler-rt] [clang-tools-extra] [llvm] [libcxx] [clang] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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


@@ -22,10 +22,7 @@ define void @add(ptr %pa, ptr %pb, ptr %pc) nounwind {
 ; X86-NEXT:vaddss %xmm0, %xmm1, %xmm0
 ; X86-NEXT:vmovss %xmm0, (%esp)
 ; X86-NEXT:calll __truncsfbf2
-; X86-NEXT:fstps {{[0-9]+}}(%esp)
-; X86-NEXT:vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; X86-NEXT:vmovd %xmm0, %eax
-; X86-NEXT:movw %ax, (%esi)
+; X86-NEXT:vmovsh %xmm0, (%esi)

phoebewang wrote:

What's the mean by truncate?

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2024-01-04 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/72078

>From e3863873ab817dacf8680763bb42d91f005fe5ea Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Fri, 10 Nov 2023 21:07:48 -0600
Subject: [PATCH 01/10] [clang] Add per-global code model attribute

This patch adds a per-global code model attribute, which can override
the target's code model to access global variables.

Currently, the code model attribute is only supported on LoongArch.
This patch also maps GCC's code model names to LLVM's, which allows
for better compatibility between the two compilers.

Suggested-by: Arthur Eubanks 
Signed-off-by: WANG Rui 
Link: 
https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
---
 clang/include/clang/Basic/Attr.td |  8 +
 clang/include/clang/Basic/AttrDocs.td |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 13 
 clang/lib/Sema/SemaDeclAttr.cpp   | 30 +++
 clang/test/CodeGen/LoongArch/attributes.c | 10 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Sema/loongarch-attr-model.c| 13 
 8 files changed, 86 insertions(+)
 create mode 100644 clang/test/CodeGen/LoongArch/attributes.c
 create mode 100644 clang/test/Sema/loongarch-attr-model.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1800f584c7e108..d5b5717f3d77cb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2718,6 +2718,14 @@ def PragmaClangTextSection : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
+def CodeModel : InheritableAttr {
+  let Spellings = [GCC<"model">];
+  let Args = [StringArgument<"Model">];
+  let Subjects =
+  SubjectList<[ GlobalVar ], ErrorDiag>;
+  let Documentation = [CodeModelDocs];
+}
+
 def Sentinel : InheritableAttr {
   let Spellings = [GCC<"sentinel">];
   let Args = [DefaultIntArgument<"Sentinel", 0>,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b45ec6bbb8d37e..1d37c2da6bec05 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -57,6 +57,15 @@ global variable or function should be in after translation.
   let Heading = "section, __declspec(allocate)";
 }
 
+def CodeModelDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``model`` attribute allows you to specify a specific code model a
+global variable should be in after translation.
+  }];
+  let Heading = "model";
+}
+
 def UsedDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203a..d438fdde9ac7eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;
+
 def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dea58a7ff4146a..1f49721e79ddc4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4841,6 +4841,19 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
   GV->setSection(".cp.rodata");
 
+// Handle code model attribute
+if (D->hasAttr()) {
+  if (const CodeModelAttr *CMA = D->getAttr()) {
+auto CM = llvm::StringSwitch(CMA->getModel())
+  .Case("tiny", llvm::CodeModel::Tiny)
+  .Case("kernel", llvm::CodeModel::Kernel)
+  .Case("medium", llvm::CodeModel::Medium)
+  .Case("large", llvm::CodeModel::Large)
+  .Default(llvm::CodeModel::Small);
+GV->setCodeModel(CM);
+  }
+}
+
 // Check if we a have a const declaration with an initializer, we may be
 // able to emit it as available_externally to expose it's value to the
 // optimizer.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 87c78d742d0ff4..64aa242dbb04f8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3369,6 +3369,33 @@ static void handleSectionAttr(Sema , Decl *D, const 
ParsedAttr ) {
   }
 }
 
+static void 

[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-04 Thread Luke Lau via cfe-commits


@@ -42,9 +42,10 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  const auto ISAInfoFeatures = (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+  /*IgnoreUnknown=*/false);
+  Features.insert(Features.end(), ISAInfoFeatures.begin(),
+  ISAInfoFeatures.end());

lukel97 wrote:

Argh I was trying to be too clever and forgot that we need to call 
Args.MakeArgString, I've just replaced it with the push_back loop again.

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


[clang] [llvm] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-04 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76942

>From caa25a73dd69268490c89d5e9e91b8d545bce760 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 14:02:39 +0900
Subject: [PATCH 1/5] [RISCV] Deduplicate
 RISCVISAInfo::toFeatures/toFeatureVector. NFC

toFeatures and toFeatureVector both output a list of target feature flags, just
with a slightly different interface. toFeatures keeps any unsupported
extensions, and also provides a way to append negative extensions
(AddAllExtensions=true).

This patch combines them into one function, so that a later patch will be be
able to get a std::vector of features that includes all the negative
extensions, which was previously only possible through the StrAlloc interface.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  6 ++--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp  |  6 ++--
 llvm/include/llvm/Support/RISCVISAInfo.h|  6 ++--
 llvm/lib/Object/ELFObjectFile.cpp   |  2 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 38 +++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 30 +---
 6 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..64f5f9e9215dcb 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -245,7 +245,7 @@ collectNonISAExtFeature(ArrayRef 
FeaturesNeedOverride, int XLen) {
 return std::vector();
   }
 
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   std::vector NonISAExtFeatureVec;
 
@@ -303,7 +303,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -420,7 +420,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..b97224426b916a 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (std::string  : (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+ /*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);
diff --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..6d267fae5a5dc6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,37 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;

[llvm] [clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-04 Thread Yeting Kuo via cfe-commits


@@ -57,11 +57,12 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and ``-mllvm 
-riscv-hardware-shadow-stack``.

yetingk wrote:

Modified. The latest patch I add new options `{m,mno}-forced-sw-shadow-stack` 
to control feature `forced-sw-shadow-stack`

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


[clang-tools-extra] [llvm] [lldb] [clang] [openmp] [mlir] [libcxx] [SEH] Fix register liveness verification for EHa (PR #76933)

2024-01-04 Thread via cfe-commits


@@ -0,0 +1,65 @@
+; RUN: llc --verify-machineinstrs < %s
+source_filename = "test.cpp"
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.12.0"
+
+$"?test@Test@@Plugin@@Host@@@Z" = comdat any
+
+declare i32 @__CxxFrameHandler3(...)
+
+; Function Attrs: nounwind memory(none)
+declare void @llvm.seh.scope.begin() #1
+
+; Function Attrs: nobuiltin allocsize(0)
+declare ptr @"??2@Test@Z"(i64) #1
+
+; Function Attrs: nounwind memory(none)
+declare void @llvm.seh.scope.end() #0
+
+; Function Attrs: nobuiltin nounwind
+declare void @"??3@YAXPEAX@Z"(ptr) #2
+
+; Function Attrs: mustprogress uwtable
+define ptr @"?test@Test@@Plugin@@Host@@@Z"(ptr %this, ptr %host) #3 comdat 
align 2 personality ptr @__CxxFrameHandler3 {
+entry:
+  %host.addr = alloca ptr, align 8
+  %this.addr = alloca ptr, align 8
+  store ptr %host, ptr %host.addr, align 8
+  store ptr %this, ptr %this.addr, align 8
+  %this1 = load ptr, ptr %this.addr, align 8
+  %call = call noalias ptr @"??2@Test@Z"(i64 152) #5

HaohaiWen wrote:

```
// Check that VNI is live-out of all predecessors.
for (const MachineBasicBlock *Pred : MFI->predecessors()) {
  SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
  // Predecessor of landing pad live-out on last call for sync EH.
  if (MFI->isEHPad()) {
assert(!IsEHa && "EHa may raise exception on non call");
for (const MachineInstr  : llvm::reverse(*Pred)) {
  if (MI.isCall()) {
PEnd = Indexes->getInstructionIndex(MI).getBoundaryIndex();
break;
  }
}
  }
  const VNInfo *PVNI = LR.getVNInfoBefore(PEnd);
```
Verifier think exception raised only by call so it trims live range until call. 
From bellowing log we can see %1 was defined after call but before scope.begin. 
It's valid.

```
# After Register Coalescer
** INTERVALS **
CH [0B,32r:0)[112r,128r:3)[304r,336r:2)[544r,560r:1) 0@0B-phi 1@544r 2@304r 
3@112r
CL [0B,32r:0)[112r,128r:3)[304r,336r:2)[544r,560r:1) 0@0B-phi 1@544r 2@304r 
3@112r
DH [0B,16r:0)[320r,336r:1) 0@0B-phi 1@320r
DL [0B,16r:0)[320r,336r:1) 0@0B-phi 1@320r
HCX [0B,32r:0)[112r,128r:3)[304r,336r:2)[544r,560r:1) 0@0B-phi 1@544r 2@304r 
3@112r
HDX [0B,16r:0)[320r,336r:1) 0@0B-phi 1@320r
%0 [32r,320r:0) 0@32r  weight:0.00e+00
%1 [160r,464r:0)[496B,544r:0) 0@160r  weight:0.00e+00
%3 [16r,64r:0) 0@16r  weight:0.00e+00
RegMasks: 128r 336r 496B 560r
** MACHINEINSTRS **
# Machine code for function ?test@Test@@Plugin@@Host@@@Z: NoPHIs, 
TracksLiveness, TiedOpsRewritten
Frame Objects:
  fi#0: size=8, align=8, at location [SP+8]
  fi#1: size=8, align=8, at location [SP+8]
Function Live Ins: $rcx in %2, $rdx in %3

0B  bb.0.entry:
  successors: %bb.1(0x7800), %bb.4(0x0800); %bb.1(100.00%), 
%bb.4(0.00%)
  liveins: $rcx, $rdx
16B   %3:gr64 = COPY $rdx
32B   %0:gr64 = COPY $rcx
48B   EH_LABEL 
64B   MOV64mr %stack.0.host.addr, 1, $noreg, 0, $noreg, %3:gr64 :: (store 
(s64) into %ir.host.addr)
80B   MOV64mr %stack.1.this.addr, 1, $noreg, 0, $noreg, %0:gr64 :: (store 
(s64) into %ir.this.addr)
96B   ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def 
dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
112B  $rcx = MOV32ri64 152
128B  CALL64pcrel32 @"??2@Test@Z", , 
implicit $rsp, implicit $ssp, implicit $rcx, implicit-def $rsp, implicit-def 
$ssp, implicit-def $rax
144B  ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead 
$eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
160B  %1:gr64 = COPY killed $rax
192B  EH_LABEL 
208B  JMP_1 %bb.1

224Bbb.1.invoke.cont:
; predecessors: %bb.0
  successors: %bb.2(0x7800), %bb.4(0x0800); %bb.2(100.00%), 
%bb.4(0.00%)

240B  EH_LABEL 
256B  EH_LABEL 
288B  ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def 
dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
304B  $rcx = COPY %1:gr64
320B  $rdx = COPY %0:gr64
336B  CALL64pcrel32 @"??Test@?A0x2749C4FD@@QEAA@Test@Test@@@Z", , implicit $rsp, implicit $ssp, implicit $rcx, implicit 
$rdx, implicit-def $rsp, implicit-def $ssp, implicit-def dead $rax
352B  ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead 
$eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
368B  EH_LABEL 
384B  EH_LABEL 
400B  JMP_1 %bb.2

416Bbb.2.invoke.cont2:
; predecessors: %bb.1
  successors: %bb.3(0x7800), %bb.4(0x0800); %bb.3(100.00%), 
%bb.4(0.00%)

432B  JMP_1 %bb.3

448Bbb.3.invoke.cont4:
; predecessors: %bb.2

464B  $rax = COPY %1:gr64
480B  RET 0, killed $rax

496Bbb.4.ehcleanup (machine-block-address-taken, landing-pad, 
ehfunclet-entry):
; predecessors: %bb.0, %bb.1, %bb.2

512B   

[llvm] [clang-tools-extra] create new clang-tidy check to add namespaces to symbol references (PR #70621)

2024-01-04 Thread via cfe-commits

https://github.com/daltairwalter updated 
https://github.com/llvm/llvm-project/pull/70621

>From f44d7746a990a3bd8e53de047a30baee4da2c790 Mon Sep 17 00:00:00 2001
From: Daniel Walter 
Date: Mon, 30 Oct 2023 00:08:56 -0500
Subject: [PATCH 1/9] Initial commit of add new check before changes

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../UseExplicitNamespacesCheck.cpp| 33 +++
 .../readability/UseExplicitNamespacesCheck.h  | 30 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/use-explicit-namespaces.rst   |  6 
 .../readability/use-explicit-namespaces.cpp   | 14 
 8 files changed, 93 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/use-explicit-namespaces.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/use-explicit-namespaces.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..6bcc9ca3e646ce 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -51,6 +51,7 @@ add_clang_library(clangTidyReadabilityModule
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
   UseAnyOfAllOfCheck.cpp
+  UseExplicitNamespacesCheck.cpp
 
   LINK_LIBS
   clangTidy
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..bdb253f90cebc2 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -54,6 +54,7 @@
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
 #include "UseAnyOfAllOfCheck.h"
+#include "UseExplicitNamespacesCheck.h"
 
 namespace clang::tidy {
 namespace readability {
@@ -151,6 +152,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-uppercase-literal-suffix");
 CheckFactories.registerCheck(
 "readability-use-anyofallof");
+CheckFactories.registerCheck(
+"readability-use-explicit-namespaces");
   }
 };
 
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
new file mode 100644
index 00..a803179b822bd2
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
@@ -0,0 +1,33 @@
+//===--- UseExplicitNamespacesCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseExplicitNamespacesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseExplicitNamespacesCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(functionDecl().bind("x"), this);
+}
+
+void UseExplicitNamespacesCheck::check(const MatchFinder::MatchResult ) 
{
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
+return;
+  diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
+  << MatchedDecl
+  << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
+  diag(MatchedDecl->getLocation(), "insert 'awesome'", DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
new file mode 100644
index 00..846e47930d0566
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
@@ -0,0 +1,30 @@
+//===--- UseExplicitNamespacesCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 

[clang] [llvm] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-04 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/68075

>From be70878169742f7e9cbb276a05254019c586897b Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 3 Oct 2023 16:08:06 +0800
Subject: [PATCH 1/5] [RISCV] Implement shadow stack on shadow stack mode with
 Zicfiss.

There are two shadow stack implements with Zicfiss in [spec] now.
In Shadow stack mode, programs still store the return address to regular 
address.
In Control stack mode, programs only store the return address to shadow stack.
This patch only supports the shadow stack mode.

[spec]: 
https://github.com/riscv/riscv-cfi/blob/main/cfi_backward.adoc#push-to-and-pop-from-the-shadow-stack
---
 llvm/lib/Target/RISCV/RISCVFrameLowering.cpp |  14 +-
 llvm/test/CodeGen/RISCV/shadowcallstack.ll   | 130 +++
 2 files changed, 142 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 8dfea6d3862057..6f043ade98f409 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -51,9 +51,14 @@ static void emitSCSPrologue(MachineFunction , 
MachineBasicBlock ,
   CSI, [&](CalleeSavedInfo ) { return CSR.getReg() == RAReg; }))
 return;
 
+  const RISCVInstrInfo *TII = STI.getInstrInfo();
+  if (STI.hasFeature(RISCV::FeatureStdExtZicfiss)) {
+BuildMI(MBB, MI, DL, TII->get(RISCV::SSPUSH)).addReg(RAReg);
+return;
+  }
+
   Register SCSPReg = RISCVABI::getSCSPReg();
 
-  const RISCVInstrInfo *TII = STI.getInstrInfo();
   bool IsRV64 = STI.hasFeature(RISCV::Feature64Bit);
   int64_t SlotSize = STI.getXLen() / 8;
   // Store return address to shadow call stack
@@ -106,9 +111,14 @@ static void emitSCSEpilogue(MachineFunction , 
MachineBasicBlock ,
   CSI, [&](CalleeSavedInfo ) { return CSR.getReg() == RAReg; }))
 return;
 
+  const RISCVInstrInfo *TII = STI.getInstrInfo();
+  if (STI.hasFeature(RISCV::FeatureStdExtZicfiss)) {
+BuildMI(MBB, MI, DL, TII->get(RISCV::SSPOPCHK)).addReg(RAReg);
+return;
+  }
+
   Register SCSPReg = RISCVABI::getSCSPReg();
 
-  const RISCVInstrInfo *TII = STI.getInstrInfo();
   bool IsRV64 = STI.hasFeature(RISCV::Feature64Bit);
   int64_t SlotSize = STI.getXLen() / 8;
   // Load return address from shadow call stack
diff --git a/llvm/test/CodeGen/RISCV/shadowcallstack.ll 
b/llvm/test/CodeGen/RISCV/shadowcallstack.ll
index fee067ee3ad141..8fbe7ed9ca0766 100644
--- a/llvm/test/CodeGen/RISCV/shadowcallstack.ll
+++ b/llvm/test/CodeGen/RISCV/shadowcallstack.ll
@@ -3,6 +3,10 @@
 ; RUN:   | FileCheck %s --check-prefix=RV32
 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
 ; RUN:   | FileCheck %s --check-prefix=RV64
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfiss -verify-machineinstrs 
< %s \
+; RUN:   | FileCheck %s --check-prefix=RV32-ZICFISS
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfiss -verify-machineinstrs 
< %s \
+; RUN:   | FileCheck %s --check-prefix=RV64-ZICFISS
 
 define void @f1() shadowcallstack {
 ; RV32-LABEL: f1:
@@ -12,6 +16,14 @@ define void @f1() shadowcallstack {
 ; RV64-LABEL: f1:
 ; RV64:   # %bb.0:
 ; RV64-NEXT:ret
+;
+; RV32-ZICFISS-LABEL: f1:
+; RV32-ZICFISS:   # %bb.0:
+; RV32-ZICFISS-NEXT:ret
+;
+; RV64-ZICFISS-LABEL: f1:
+; RV64-ZICFISS:   # %bb.0:
+; RV64-ZICFISS-NEXT:ret
   ret void
 }
 
@@ -25,6 +37,14 @@ define void @f2() shadowcallstack {
 ; RV64-LABEL: f2:
 ; RV64:   # %bb.0:
 ; RV64-NEXT:tail foo@plt
+;
+; RV32-ZICFISS-LABEL: f2:
+; RV32-ZICFISS:   # %bb.0:
+; RV32-ZICFISS-NEXT:tail foo@plt
+;
+; RV64-ZICFISS-LABEL: f2:
+; RV64-ZICFISS:   # %bb.0:
+; RV64-ZICFISS-NEXT:tail foo@plt
   tail call void @foo()
   ret void
 }
@@ -65,6 +85,32 @@ define i32 @f3() shadowcallstack {
 ; RV64-NEXT:addi gp, gp, -8
 ; RV64-NEXT:.cfi_restore gp
 ; RV64-NEXT:ret
+;
+; RV32-ZICFISS-LABEL: f3:
+; RV32-ZICFISS:   # %bb.0:
+; RV32-ZICFISS-NEXT:sspush ra
+; RV32-ZICFISS-NEXT:addi sp, sp, -16
+; RV32-ZICFISS-NEXT:.cfi_def_cfa_offset 16
+; RV32-ZICFISS-NEXT:sw ra, 12(sp) # 4-byte Folded Spill
+; RV32-ZICFISS-NEXT:.cfi_offset ra, -4
+; RV32-ZICFISS-NEXT:call bar@plt
+; RV32-ZICFISS-NEXT:lw ra, 12(sp) # 4-byte Folded Reload
+; RV32-ZICFISS-NEXT:addi sp, sp, 16
+; RV32-ZICFISS-NEXT:sspopchk ra
+; RV32-ZICFISS-NEXT:ret
+;
+; RV64-ZICFISS-LABEL: f3:
+; RV64-ZICFISS:   # %bb.0:
+; RV64-ZICFISS-NEXT:sspush ra
+; RV64-ZICFISS-NEXT:addi sp, sp, -16
+; RV64-ZICFISS-NEXT:.cfi_def_cfa_offset 16
+; RV64-ZICFISS-NEXT:sd ra, 8(sp) # 8-byte Folded Spill
+; RV64-ZICFISS-NEXT:.cfi_offset ra, -8
+; RV64-ZICFISS-NEXT:call bar@plt
+; RV64-ZICFISS-NEXT:ld ra, 8(sp) # 8-byte Folded Reload
+; RV64-ZICFISS-NEXT:addi sp, sp, 16
+; RV64-ZICFISS-NEXT:sspopchk ra
+; RV64-ZICFISS-NEXT:ret
   %res = call i32 @bar()
   %res1 = add i32 %res, 1
   ret i32 %res
@@ -140,6 

[clang] [llvm] [openmp] [lldb] [clang-tools-extra] [mlir] [libcxx] [SEH] Fix register liveness verification for EHa (PR #76933)

2024-01-04 Thread via cfe-commits

HaohaiWen wrote:

Refer https://github.com/llvm/llvm-project/pull/76921 for failure output

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-01-04 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> I'm Sam's colleague and wanted to mention that Sam won't be available until 
> January 15. It probably does not make much sense for someone else to take 
> over at this point as the change is large and waiting for Sam is more 
> efficient than ramping up someone else at this point.
> 
> Sorry about the delays.

Got it. Yes, there is no many other alternatives to progress. We can only be 
patience in such cases.

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


[clang-tools-extra] [libc] [mlir] [compiler-rt] [llvm] [clang] [lld] [libcxxabi] [flang] [libcxx] [lldb] [clang] static operators should evaluate object argument (PR #68485)

2024-01-04 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/10] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, , Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *CE,
+

[clang-tools-extra] [libc] [mlir] [compiler-rt] [llvm] [clang] [lld] [libcxxabi] [flang] [libcxx] [lldb] [clang] static operators should evaluate object argument (PR #68485)

2024-01-04 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 054b5fc0fd41bcbadcc6967c39a5f6bb151bdcd1 
eb42407a523f9a79afca4fbf221b344330888cc6 -- 
clang/test/AST/ast-dump-static-operators.cpp 
clang/test/SemaCXX/cxx2b-static-operator.cpp clang/lib/AST/ExprConstant.cpp 
clang/lib/CodeGen/CGExpr.cpp clang/lib/Sema/SemaChecking.cpp 
clang/lib/Sema/SemaOverload.cpp 
clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp 
clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1810fdd12b..f9c7cf9b65 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5682,7 +5682,9 @@ static ImplicitConversionSequence 
TryObjectArgumentInitialization(
   // const volatile object.
   // Also, a static operator can be invoked for a const, volatile or const
   // volatile object, apparently.
-  bool IsStaticOperator = Method->getDeclName().getCXXOverloadedOperator() != 
OO_None && Method->isStatic();
+  bool IsStaticOperator =
+  Method->getDeclName().getCXXOverloadedOperator() != OO_None &&
+  Method->isStatic();
   Qualifiers Quals = Method->getMethodQualifiers();
   if (isa(Method) || IsStaticOperator) {
 Quals.addConst();

``




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


[clang-tools-extra] [libc] [mlir] [compiler-rt] [llvm] [clang] [lld] [libcxxabi] [flang] [libcxx] [lldb] [clang] static operators should evaluate object argument (PR #68485)

2024-01-04 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 1/9] [clang] static operators should evaluate object argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, , Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *CE,
+   

[clang-tools-extra] [openmp] [libc] [compiler-rt] [llvm] [clang] [lld] [flang] [libcxx] [lldb] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-04 Thread via cfe-commits

WenleiHe wrote:

> ongoing effort to extends PGO instrumentation to GPU device code

Is there a high level description for this effort and its goal? Traditional 
compiler PGO is mostly for profiling control-flow, but we don't usually have a 
lot of control flow for GPU kernels. 

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


[clang] [libc] [lld] [openmp] [llvm] [flang] [libcxx] [lldb] [compiler-rt] [clang-tools-extra] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-04 Thread Ethan Luis McDonough via cfe-commits


@@ -163,3 +163,87 @@ Error 
GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy ,
 
   return Plugin::success();
 }
+
+bool GenericGlobalHandlerTy::hasProfilingGlobals(GenericDeviceTy ,
+ DeviceImageTy ) {
+  GlobalTy global(getInstrProfNamesVarName().str(), 0);
+  if (auto Err = getGlobalMetadataFromImage(Device, Image, global)) {
+consumeError(std::move(Err));
+return false;
+  }
+  return true;
+}
+
+Expected
+GenericGlobalHandlerTy::readProfilingGlobals(GenericDeviceTy ,
+ DeviceImageTy ) {
+  GPUProfGlobals profdata;
+  auto ELFObj = getELFObjectFile(Image);
+  if (!ELFObj)
+return ELFObj.takeError();
+  profdata.targetTriple = ELFObj->makeTriple();
+  // Iterate through elf symbols
+  for (auto  : ELFObj->symbols()) {
+if (auto name = sym.getName()) {
+  // Check if given current global is a profiling global based
+  // on name
+  if (name->equals(getInstrProfNamesVarName())) {
+// Read in profiled function names
+std::vector chars(sym.getSize() / sizeof(char), ' ');
+GlobalTy NamesGlobal(name->str(), sym.getSize(), chars.data());
+if (auto Err = readGlobalFromDevice(Device, Image, NamesGlobal))
+  return Err;
+std::string names(chars.begin(), chars.end());
+profdata.names = std::move(names);
+  } else if (name->starts_with(getInstrProfCountersVarPrefix())) {

EthanLuisMcDonough wrote:

Those functions are defined in 
[InstrProf.h](https://github.com/llvm/llvm-project/blob/597086c60959dd5b3c032552e8b42dd1d053f233/llvm/include/llvm/ProfileData/InstrProf.h#L92-L96).

https://github.com/llvm/llvm-project/blob/597086c60959dd5b3c032552e8b42dd1d053f233/llvm/include/llvm/ProfileData/InstrProf.h#L92-L96

They're used in the creation of PGO global names.

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


[clang-tools-extra] [openmp] [libc] [compiler-rt] [llvm] [clang] [lld] [flang] [libcxx] [lldb] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-04 Thread Ethan Luis McDonough via cfe-commits


@@ -163,3 +163,87 @@ Error 
GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy ,
 
   return Plugin::success();
 }
+
+bool GenericGlobalHandlerTy::hasProfilingGlobals(GenericDeviceTy ,
+ DeviceImageTy ) {
+  GlobalTy global(getInstrProfNamesVarName().str(), 0);
+  if (auto Err = getGlobalMetadataFromImage(Device, Image, global)) {
+consumeError(std::move(Err));
+return false;
+  }
+  return true;
+}
+
+Expected
+GenericGlobalHandlerTy::readProfilingGlobals(GenericDeviceTy ,
+ DeviceImageTy ) {
+  GPUProfGlobals profdata;
+  auto ELFObj = getELFObjectFile(Image);
+  if (!ELFObj)
+return ELFObj.takeError();
+  profdata.targetTriple = ELFObj->makeTriple();
+  // Iterate through elf symbols
+  for (auto  : ELFObj->symbols()) {
+if (auto name = sym.getName()) {
+  // Check if given current global is a profiling global based
+  // on name
+  if (name->equals(getInstrProfNamesVarName())) {
+// Read in profiled function names
+std::vector chars(sym.getSize() / sizeof(char), ' ');
+GlobalTy NamesGlobal(name->str(), sym.getSize(), chars.data());

EthanLuisMcDonough wrote:

`__llvm_prf_nm` is emitted as an array. For example:

```
@__llvm_prf_nm = protected addrspace(1) constant [63 x i8] 
c"_=x\DA+I-.\D1K\B6\8A\8F\CF\CF-\88\CFOK\CB\C9OL\C9\CCK\8F7\B1\887M65J41\B5\88\CFM\CC\CC\8B\CF1\B4d,!Z\B1\B1\01X\B1!\00O\F6
 \CF", section "__llvm_prf_names", align 1
```

Eventually this data is going to be passed to a function in compiler-rt's 
profiling library so it can be used to generate a profiling file.

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


[openmp] [clang] [lldb] [libc] [compiler-rt] [libcxx] [flang] [lld] [clang-tools-extra] [llvm] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-04 Thread Ethan Luis McDonough via cfe-commits


@@ -163,3 +163,87 @@ Error 
GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy ,
 
   return Plugin::success();
 }
+
+bool GenericGlobalHandlerTy::hasProfilingGlobals(GenericDeviceTy ,
+ DeviceImageTy ) {
+  GlobalTy global(getInstrProfNamesVarName().str(), 0);
+  if (auto Err = getGlobalMetadataFromImage(Device, Image, global)) {
+consumeError(std::move(Err));
+return false;
+  }
+  return true;
+}
+
+Expected
+GenericGlobalHandlerTy::readProfilingGlobals(GenericDeviceTy ,
+ DeviceImageTy ) {
+  GPUProfGlobals profdata;
+  auto ELFObj = getELFObjectFile(Image);
+  if (!ELFObj)
+return ELFObj.takeError();
+  profdata.targetTriple = ELFObj->makeTriple();
+  // Iterate through elf symbols
+  for (auto  : ELFObj->symbols()) {
+if (auto name = sym.getName()) {
+  // Check if given current global is a profiling global based
+  // on name
+  if (name->equals(getInstrProfNamesVarName())) {
+// Read in profiled function names
+std::vector chars(sym.getSize() / sizeof(char), ' ');

EthanLuisMcDonough wrote:

I'm allocating a vector so that I have memory to write the GPU value to.

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


[clang] [libc] [lld] [openmp] [llvm] [flang] [libcxx] [lldb] [compiler-rt] [clang-tools-extra] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-04 Thread Ethan Luis McDonough via cfe-commits


@@ -58,6 +60,22 @@ class GlobalTy {
   void setPtr(void *P) { Ptr = P; }
 };
 
+typedef void *IntPtrT;

EthanLuisMcDonough wrote:

`IntPtrT` isn't defined in `profile/InstrProfData.inc`. There are multiple 
examples of this type being defined. before InstProfData.inc is included. I'm 
not entirely sure what its for, but I'm assuming its to account for different 
platforms with different integer sizes.

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


[openmp] [libcxx] [clang-tools-extra] [clang] [llvm] [libc] [flang] [lld] [lldb] [compiler-rt] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-04 Thread Ethan Luis McDonough via cfe-commits


@@ -58,6 +60,22 @@ class GlobalTy {
   void setPtr(void *P) { Ptr = P; }
 };
 
+typedef void *IntPtrT;
+struct __llvm_profile_data {
+#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+/// PGO profiling data extracted from a GPU device
+struct GPUProfGlobals {
+  std::string names;
+  std::vector> counts;
+  std::vector<__llvm_profile_data> data;
+  Triple targetTriple;
+

EthanLuisMcDonough wrote:

The basic idea is that the fields in this struct are going to be passed to 
compiler-rt to be made into a profraw file for this specific target.

I don't know if `llvm::StringRef` would work for the names field. The names 
data is constant on the GPU device, but dynamic data still has to be allocated 
on the host in order to read the GPU value. I think it makes the most sense to 
make the struct own the name data. 

Do you think I should change all the vectors to `SmallVector` or just the 
innermost `Counts` vector?

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (XDeme)


Changes

Fixes llvm/llvm-project#76716
Added a check to prevent null deferencing

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


2 Files Affected:

- (modified) clang/lib/Format/WhitespaceManager.cpp (+2-1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+6) 


``diff
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 3bc6915b8df0a7..95693f4588c631 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,7 +1444,8 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+const FormatToken *Next = C.Tok->getNextNonComment();
+if (Next && Next->isNot(tok::r_brace)) // dangling comma
   ++Cell;
   }
 } else if (Depth == 1) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..c9f91953c13f52 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21084,6 +21084,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"
"\"dy\"}   },\n"

``




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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-04 Thread via cfe-commits

https://github.com/XDeme created https://github.com/llvm/llvm-project/pull/77045

Fixes llvm/llvm-project#76716
Added a check to prevent null deferencing

>From d9cbbe48b96d27bff3fc926b60d039ed05f00489 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 01:23:16 -0300
Subject: [PATCH] [clang-format] Fix crash involving array designators and
 dangling comma Fixes llvm/llvm-project#76716 Added a check to prevent null
 deferencing

---
 clang/lib/Format/WhitespaceManager.cpp | 3 ++-
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 3bc6915b8df0a7..95693f4588c631 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,7 +1444,8 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+const FormatToken *Next = C.Tok->getNextNonComment();
+if (Next && Next->isNot(tok::r_brace)) // dangling comma
   ++Cell;
   }
 } else if (Depth == 1) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..c9f91953c13f52 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21084,6 +21084,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"
"\"dy\"}   },\n"

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


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

2024-01-04 Thread via cfe-commits


@@ -416,6 +416,12 @@ added in the future:
 This calling convention, like the `PreserveMost` calling convention, will 
be
 used by a future version of the ObjectiveC runtime and should be considered
 experimental at this time.
+"``preserve_nonecc``" - The `PreserveNone` calling convention
+This calling convention doesn't preserve any general registers. So all
+general registers are caller saved registers. It also uses all general
+registers to pass arguments. This attribute doesn't impact floating-point

weiguozhi wrote:

> I suspect this should say any `non-general purpose registers (e.g. floating 
> point registers, on x86 XMMs/YMMs)`. Rather than `floating-point registers`. 

Thanks for the correction! Will change it.

> Also isn't this just a hack to increase the number of registers used to pass 
> arguments? If so there has to be a better way of doing this. Maybe a 
> non-exposed attribute which is used only for non-exposed functions? e.g. on 
> x86 (not 64bit), regparm could be used internally there.

It's not a hack, it's a natural extension. Because we don't preserve general 
registers, we can use all of them to pass arguments without the extra cost to 
save/restore those registers, they are clobbered by the function call anyway.

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


[clang-tools-extra] [libc] [compiler-rt] [libcxx] [mlir] [llvm] [lld] [clang] [lldb] [libcxxabi] [flang] [clang] static operators should evaluate object argument (PR #68485)

2024-01-04 Thread Tianlan Zhou via cfe-commits

SuperSodaSea wrote:

Wait a minute, it failes to compile this situation:

```c++
struct Foo {
static int operator()(int a, int b) { return a + b; }
};

void f() {
const Foo foo;
foo(1, 2); // 'this' argument to member function 'operator()' has type 
'const Foo', but function is not marked const
}
```

Let me try to fix this...

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


[clang] [Cygwin] Cygwin general 0 (PR #74936)

2024-01-04 Thread 徐持恒 Xu Chiheng via cfe-commits

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


[clang] [Cygwin] Cygwin general 1 (PR #74936)

2024-01-04 Thread 徐持恒 Xu Chiheng via cfe-commits

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


[clang-tools-extra] [libcxx] [mlir] [openmp] [llvm] [clang] [lldb] [SEH] Fix register liveness verification for EHa (PR #76933)

2024-01-04 Thread via cfe-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/76933

>From 8305e5e15eaaedba58a57b179e32c6d4b2a11a44 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Thu, 4 Jan 2024 15:35:52 +0800
Subject: [PATCH 1/5] [SEH] Add test to track EHa register liveness
 verification

This test tracks bug of MachineVerifier to check live range segment for
EHa. Async exception can happen at any place within seh scope, not only
the call instruction. Need to teach MachineVerifier to know that.
---
 .../X86/windows-seh-EHa-RegisterLiveness.ll   | 69 +++
 1 file changed, 69 insertions(+)
 create mode 100644 llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll

diff --git a/llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll 
b/llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll
new file mode 100644
index 00..d23318c6e16a11
--- /dev/null
+++ b/llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll
@@ -0,0 +1,69 @@
+; XFAIL: *
+; RUN: llc --verify-machineinstrs < %s | FileCheck %s
+source_filename = "test.cpp"
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.12.0"
+
+$"?test@Test@@Plugin@@Host@@@Z" = comdat any
+
+declare dso_local i32 @__CxxFrameHandler3(...)
+
+; Function Attrs: nounwind memory(none)
+declare dso_local void @llvm.seh.scope.begin() #1
+
+; Function Attrs: nobuiltin allocsize(0)
+declare dso_local noundef nonnull ptr @"??2@Test@Z"(i64 noundef) #1
+
+; Function Attrs: nounwind memory(none)
+declare dso_local void @llvm.seh.scope.end() #0
+
+; Function Attrs: nobuiltin nounwind
+declare dso_local void @"??3@YAXPEAX@Z"(ptr noundef) #2
+
+; Function Attrs: mustprogress uwtable
+define weak_odr dso_local noundef ptr @"?test@Test@@Plugin@@Host@@@Z"(ptr 
noundef nonnull align 8 dereferenceable(48) %this, ptr noundef %host) 
unnamed_addr #3 comdat align 2 personality ptr @__CxxFrameHandler3 {
+entry:
+  %host.addr = alloca ptr, align 8
+  %this.addr = alloca ptr, align 8
+  store ptr %host, ptr %host.addr, align 8
+  store ptr %this, ptr %this.addr, align 8
+  %this1 = load ptr, ptr %this.addr, align 8
+  %call = call noalias noundef nonnull ptr @"??2@Test@Z"(i64 noundef 152) #5
+  invoke void @llvm.seh.scope.begin()
+  to label %invoke.cont unwind label %ehcleanup
+
+invoke.cont:  ; preds = %entry
+  %call3 = invoke noundef ptr @"??Test@?A0x2749C4FD@@QEAA@Test@Test@@@Z"(ptr 
noundef nonnull align 8 dereferenceable(152) %call, ptr noundef %this1)
+  to label %invoke.cont2 unwind label %ehcleanup
+
+invoke.cont2: ; preds = %invoke.cont
+  invoke void @llvm.seh.scope.end()
+  to label %invoke.cont4 unwind label %ehcleanup
+
+invoke.cont4: ; preds = %invoke.cont2
+  ret ptr %call
+
+ehcleanup:; preds = %invoke.cont2, 
%invoke.cont, %entry
+  %0 = cleanuppad within none []
+  call void @"??3@YAXPEAX@Z"(ptr noundef %call) #6 [ "funclet"(token %0) ]
+  cleanupret from %0 unwind to caller
+}
+
+; Function Attrs: uwtable
+declare hidden noundef ptr @"??Test@?A0x2749C4FD@@QEAA@Test@Test@@@Z"(ptr 
noundef nonnull returned align 8 dereferenceable(152), ptr noundef) 
unnamed_addr #4 align 2
+
+attributes #0 = { nounwind memory(none) }
+attributes #1 = { nobuiltin allocsize(0) "target-cpu"="x86-64" 
"target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 "tune-cpu"="generic" }
+attributes #2 = { nobuiltin nounwind "target-cpu"="x86-64" 
"target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 "tune-cpu"="generic" }
+attributes #3 = { mustprogress uwtable "target-cpu"="x86-64" 
"target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 "tune-cpu"="generic" }
+attributes #4 = { uwtable "target-cpu"="x86-64" 
"target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 "tune-cpu"="generic" }
+attributes #5 = { builtin allocsize(0) }
+attributes #6 = { builtin nounwind }
+
+!llvm.module.flags = !{!1, !2, !3, !4, !5}
+
+!1 = !{i32 1, !"wchar_size", i32 2}
+!2 = !{i32 2, !"eh-asynch", i32 1}
+!3 = !{i32 8, !"PIC Level", i32 2}
+!4 = !{i32 7, !"uwtable", i32 2}
+!5 = !{i32 1, !"MaxTLSAlign", i32 65536}

>From 2d60e94362fdfbcf6964f9b50369c45f37a20398 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Thu, 4 Jan 2024 17:15:59 +0800
Subject: [PATCH 2/5] Fix typo

---
 llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll 
b/llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll
index d23318c6e16a11..c21ac1b5436c9c 100644
--- a/llvm/test/CodeGen/X86/windows-seh-EHa-RegisterLiveness.ll
+++ 

[llvm] [clang] [clang-tools-extra] DAG: Implement promotion for strict_fp_round (PR #74332)

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


@@ -2621,6 +2642,29 @@ SDValue 
DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode *N) {
   return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, Round);
 }
 
+// Explicit operation to reduce precision.  Reduce the value to half precision
+// and promote it back to the legal type.
+SDValue DAGTypeLegalizer::PromoteFloatRes_STRICT_FP_ROUND(SDNode *N) {

topperc wrote:

There are two promotion legalizers, Promote and SoftPromoteHalf. X86 and RISC-V 
use SoftPromoteHalf. Other targets use Promote. Promote doesn't convert back to 
fp16 in the right places in my opinion. If I recall correctly Promote doesn't 
convert to fp16 between two promoted fadds for example so it keeps extra 
precision.

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


[clang] Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (PR #77040)

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

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/77040

>From 10a0e9aae5effdd6e26476e78a778b89373358df Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 5 Jan 2024 10:05:15 +0800
Subject: [PATCH] Improve modeling of 'getcwd' in the
 StdLibraryFunctionsChecker

1. Improve the 'errno' modeling.
2. Make the range of the buffer size argument more accurate.
---
 clang/docs/ReleaseNotes.rst   |  5 +++--
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  7 +--
 clang/test/Analysis/errno-stdlibraryfunctions.c   | 11 +++
 .../Analysis/std-c-library-functions-path-notes.c |  6 ++
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce7599ad34beaf..f59fe77b447aec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1138,9 +1138,10 @@ Improvements
 
 
 - Improved the ``unix.StdCLibraryFunctions`` checker by modeling more
-  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp`` and
-  ``errno`` behavior.
+  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp``,
+  ``getcwd`` and ``errno`` behavior.
   (`52ac71f92d38 
`_,
+  `#77040 `_,
   `#76671 `_,
   `#71373 `_,
   `#76557 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..759de10601d08f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2516,12 +2516,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(
-ArgumentCondition(1, WithinRange, Range(0, SizeMax;
+ArgumentCondition(1, WithinRange, Range(1, SizeMax;
 
 // int mkdir(const char *pathname, mode_t mode);
 addToFunctionSummaryMap(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 80e14c4e2923ca..b1317a2e2582de 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -74,3 +74,14 @@ void errno_mkdtemp(char *template) {
 if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
   }
 }
+
+void errno_getcwd(char *Buf, size_t sz) {
+  char *Path = getcwd(Buf, sz);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);  // expected-warning{{TRUE}}
+if (errno) {} // no warning
+  } else {
+clang_analyzer_eval(Path == Buf); // expected-warning{{TRUE}}
+if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
+  }
+}
diff --git a/clang/test/Analysis/std-c-library-functions-path-notes.c 
b/clang/test/Analysis/std-c-library-functions-path-notes.c
index 4df00fe1e60646..0f5b9c08e9c0f3 100644
--- a/clang/test/Analysis/std-c-library-functions-path-notes.c
+++ b/clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -89,3 +89,9 @@ int test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {
   // expected-warning{{Division by zero}} \
   // expected-note{{Division by zero}}
 }
+
+char *test_getcwd_bufsize_zero(char *Buf) {
+  return getcwd(Buf, 0); // \
+  // expected-warning {{The 2nd argument to 'getcwd' is 0 but should be > 0}} \
+  // expected-note{{The 2nd argument to 'getcwd' is 0 but should be > 0}}
+}

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-04 Thread Chuanqi Xu via cfe-commits


@@ -1249,3 +1249,5 @@ void ODRHash::AddQualType(QualType T) {
 void ODRHash::AddBoolean(bool Value) {
   Bools.push_back(Value);
 }
+
+void ODRHash::AddInteger(unsigned Value) { ID.AddInteger(Value); }

ChuanqiXu9 wrote:

Interesting. I didn't recognize this. If this is true, we need to decide if we 
can leave a FIXME here or we must fix it to proceed.

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


[clang] Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (PR #77040)

2024-01-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes

1. Improve the 'errno' modeling.
2. Improve the buffer size argument's constraint.

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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+5-2) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+11) 
- (modified) clang/test/Analysis/std-c-library-functions-arg-constraints.c (+2) 
- (modified) clang/test/Analysis/std-c-library-functions-path-notes.c (+6) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..759de10601d08f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2516,12 +2516,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(
-ArgumentCondition(1, WithinRange, Range(0, SizeMax;
+ArgumentCondition(1, WithinRange, Range(1, SizeMax;
 
 // int mkdir(const char *pathname, mode_t mode);
 addToFunctionSummaryMap(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 80e14c4e2923ca..b1317a2e2582de 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -74,3 +74,14 @@ void errno_mkdtemp(char *template) {
 if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
   }
 }
+
+void errno_getcwd(char *Buf, size_t sz) {
+  char *Path = getcwd(Buf, sz);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);  // expected-warning{{TRUE}}
+if (errno) {} // no warning
+  } else {
+clang_analyzer_eval(Path == Buf); // expected-warning{{TRUE}}
+if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
+  }
+}
diff --git a/clang/test/Analysis/std-c-library-functions-arg-constraints.c 
b/clang/test/Analysis/std-c-library-functions-arg-constraints.c
index 0b817dda98c727..9011aee6b3f714 100644
--- a/clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ b/clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -168,6 +168,7 @@ void test_notnull_concrete(FILE *fp) {
   // bugpath-warning{{The 1st argument to 'fread' is NULL but should not be 
NULL}} \
   // bugpath-note{{The 1st argument to 'fread' is NULL but should not be NULL}}
 }
+
 void test_notnull_symbolic(FILE *fp, int *buf) {
   fread(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(buf != 0); // \
@@ -176,6 +177,7 @@ void test_notnull_symbolic(FILE *fp, int *buf) {
   // bugpath-note{{TRUE}} \
   // bugpath-note{{'buf' is not equal to null}}
 }
+
 void test_notnull_symbolic2(FILE *fp, int *buf) {
   if (!buf)  // bugpath-note{{Assuming 'buf' is null}} 
\
 // bugpath-note{{Taking true branch}}
diff --git a/clang/test/Analysis/std-c-library-functions-path-notes.c 
b/clang/test/Analysis/std-c-library-functions-path-notes.c
index 4df00fe1e60646..0f5b9c08e9c0f3 100644
--- a/clang/test/Analysis/std-c-library-functions-path-notes.c
+++ b/clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -89,3 +89,9 @@ int test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {
   // expected-warning{{Division by zero}} \
   // expected-note{{Division by zero}}
 }
+
+char *test_getcwd_bufsize_zero(char *Buf) {
+  return getcwd(Buf, 0); // \
+  // expected-warning {{The 2nd argument to 'getcwd' is 0 but should be > 0}} \
+  // expected-note{{The 2nd argument to 'getcwd' is 0 but should be > 0}}
+}

``




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


[clang] Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (PR #77040)

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

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

1. Improve the 'errno' modeling.
2. Improve the buffer size argument's constraint.

>From ab7f635446f8277ef305e606ca6973860755e316 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 5 Jan 2024 10:05:15 +0800
Subject: [PATCH] Improve modeling of 'getcwd' in the
 StdLibraryFunctionsChecker

1. Improve the 'errno' modeling.
2. Improve the buffer size argument's constraint.
---
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  7 +--
 clang/test/Analysis/errno-stdlibraryfunctions.c   | 11 +++
 .../std-c-library-functions-arg-constraints.c |  2 ++
 .../Analysis/std-c-library-functions-path-notes.c |  6 ++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..759de10601d08f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2516,12 +2516,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(
-ArgumentCondition(1, WithinRange, Range(0, SizeMax;
+ArgumentCondition(1, WithinRange, Range(1, SizeMax;
 
 // int mkdir(const char *pathname, mode_t mode);
 addToFunctionSummaryMap(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 80e14c4e2923ca..b1317a2e2582de 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -74,3 +74,14 @@ void errno_mkdtemp(char *template) {
 if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
   }
 }
+
+void errno_getcwd(char *Buf, size_t sz) {
+  char *Path = getcwd(Buf, sz);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);  // expected-warning{{TRUE}}
+if (errno) {} // no warning
+  } else {
+clang_analyzer_eval(Path == Buf); // expected-warning{{TRUE}}
+if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
+  }
+}
diff --git a/clang/test/Analysis/std-c-library-functions-arg-constraints.c 
b/clang/test/Analysis/std-c-library-functions-arg-constraints.c
index 0b817dda98c727..9011aee6b3f714 100644
--- a/clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ b/clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -168,6 +168,7 @@ void test_notnull_concrete(FILE *fp) {
   // bugpath-warning{{The 1st argument to 'fread' is NULL but should not be 
NULL}} \
   // bugpath-note{{The 1st argument to 'fread' is NULL but should not be NULL}}
 }
+
 void test_notnull_symbolic(FILE *fp, int *buf) {
   fread(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(buf != 0); // \
@@ -176,6 +177,7 @@ void test_notnull_symbolic(FILE *fp, int *buf) {
   // bugpath-note{{TRUE}} \
   // bugpath-note{{'buf' is not equal to null}}
 }
+
 void test_notnull_symbolic2(FILE *fp, int *buf) {
   if (!buf)  // bugpath-note{{Assuming 'buf' is null}} 
\
 // bugpath-note{{Taking true branch}}
diff --git a/clang/test/Analysis/std-c-library-functions-path-notes.c 
b/clang/test/Analysis/std-c-library-functions-path-notes.c
index 4df00fe1e60646..0f5b9c08e9c0f3 100644
--- a/clang/test/Analysis/std-c-library-functions-path-notes.c
+++ b/clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -89,3 +89,9 @@ int test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {
   // expected-warning{{Division by zero}} \
   // expected-note{{Division by zero}}
 }
+
+char *test_getcwd_bufsize_zero(char *Buf) {
+  return getcwd(Buf, 0); // \
+  // expected-warning {{The 2nd argument to 'getcwd' is 0 but should be > 0}} \
+  // expected-note{{The 2nd argument to 'getcwd' is 0 but should be > 0}}
+}

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-04 Thread Chuanqi Xu via cfe-commits


@@ -2431,10 +2434,14 @@ void 
ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   mergeRedeclarableTemplate(D, Redecl);
 
   if (ThisDeclID == Redecl.getFirstID()) {
-// This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
-// the specializations.
+// This ClassTemplateDecl owns a CommonPtr; read it to keep track of all
+// of the specializations.
 SmallVector SpecIDs;
 readDeclIDList(SpecIDs);
+
+if (Record.readInt())
+  ReadDeclsSpecs(*Loc.F, D, Loc.F->DeclsCursor);

ChuanqiXu9 wrote:

Then it won't fall here. It is the job of the latter patch 
(https://github.com/ChuanqiXu9/llvm-project/commit/7f027f0b6551a8e421034e96bd0a4c953c473df6)

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-04 Thread Chuanqi Xu via cfe-commits


@@ -527,6 +527,10 @@ class ASTWriter : public ASTDeserializationListener,
   bool isLookupResultExternal(StoredDeclsList , DeclContext *DC);
   bool isLookupResultEntirelyExternal(StoredDeclsList , DeclContext 
*DC);
 
+  uint64_t
+  WriteSpecsLookupTable(NamedDecl *D,

ChuanqiXu9 wrote:

Got it. Will do in the next circle.

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-04 Thread Chuanqi Xu via cfe-commits


@@ -150,6 +150,11 @@ class ExternalASTSource : public 
RefCountedBase {
   virtual bool
   FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
 
+  /// Load all the external specialzations for the Decl and the corresponding
+  /// template arguments.
+  virtual void LoadExternalSpecs(const Decl *D,

ChuanqiXu9 wrote:

I feel `Load` may be a better name. Since from the signature it doesn't find  
anything. And if we want consistency, I suggest to rename 
`FindExternalVisibleDeclsByName ` to `LoadExternalVisibleDeclsByName`.

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


[libcxx] [compiler-rt] [flang] [libc] [lldb] [clang] [clang-tools-extra] [llvm] [X86][BF16] Try to use `f16` for lowering (PR #76901)

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


@@ -22,10 +22,7 @@ define void @add(ptr %pa, ptr %pb, ptr %pc) nounwind {
 ; X86-NEXT:vaddss %xmm0, %xmm1, %xmm0
 ; X86-NEXT:vmovss %xmm0, (%esp)
 ; X86-NEXT:calll __truncsfbf2
-; X86-NEXT:fstps {{[0-9]+}}(%esp)
-; X86-NEXT:vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; X86-NEXT:vmovd %xmm0, %eax
-; X86-NEXT:movw %ax, (%esi)
+; X86-NEXT:vmovsh %xmm0, (%esi)

FreddyLeaf wrote:

This change seems to will miss the truncate operation.

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-04 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> This is a great way to start a new year ;)
> 
> The phab link is https://reviews.llvm.org/D41416.
> 
> In general I was wondering could we simplify the implementation by loading 
> the specialization hash table upon module load. That should be relatively 
> cheap as we will read 2 integers per specialization.
> 
> Perhaps we should put both patches together and that'd allow us to test them 
> if they are on par with https://reviews.llvm.org/D41416 which we use 
> downstream.
> 
> Thanks for working on this!

Hi Vassilev, for testing purpose I sent 
https://github.com/ChuanqiXu9/llvm-project/tree/LoadSpecializationUpdatesLazily.
 I didn't create stacked review since I feel a standalone branch may be 
sufficient.

> In general I was wondering could we simplify the implementation by loading 
> the specialization hash table upon module load. That should be relatively 
> cheap as we will read 2 integers per specialization.

IIUC, it looks like what I do in 
https://github.com/ChuanqiXu9/llvm-project/commit/7f027f0b6551a8e421034e96bd0a4c953c473df6#diff-c61a3cce4bfa099b5af032fa83cbf1563f0af4bf58dc112b39571d74b6b681c1R3487-R3499.
 But I don't want to do that with this patch. Since we can avoid load the hash 
table if the template decl is not loaded.

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


[libcxx] [compiler-rt] [libc] [flang] [lldb] [lld] [clang] [libcxxabi] [mlir] [clang-tools-extra] [llvm] [clang] static operators should evaluate object argument (PR #68485)

2024-01-04 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 1/8] [clang] static operators should evaluate object argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, , Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *CE,
+   

[clang-tools-extra] [llvm] [clang] DAG: Implement promotion for strict_fp_round (PR #74332)

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


@@ -2621,6 +2642,29 @@ SDValue 
DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode *N) {
   return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, Round);
 }
 
+// Explicit operation to reduce precision.  Reduce the value to half precision
+// and promote it back to the legal type.
+SDValue DAGTypeLegalizer::PromoteFloatRes_STRICT_FP_ROUND(SDNode *N) {

phoebewang wrote:

Why we need this given we have a handler here 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp#L2996-L3003

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


[clang-tools-extra] [llvm] [clang] DAG: Implement promotion for strict_fp_round (PR #74332)

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


@@ -1097,7 +1097,7 @@ def : Pat <
 multiclass f16_fp_Pats {
   // f16_to_fp patterns
   def : GCNPat <
-(f32 (f16_to_fp i32:$src0)),
+(f32 (any_f16_to_fp i32:$src0)),

arsenm wrote:

Yes, with appropriate tests added alongside it 

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


[clang-tools-extra] [llvm] [clang] DAG: Implement promotion for strict_fp_round (PR #74332)

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


@@ -1097,7 +1097,7 @@ def : Pat <
 multiclass f16_fp_Pats {
   // f16_to_fp patterns
   def : GCNPat <
-(f32 (f16_to_fp i32:$src0)),
+(f32 (any_f16_to_fp i32:$src0)),

phoebewang wrote:

Should we replace more `f16_to_fp` to `any_f16_to_fp` in this file and other 
target files?

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


[clang] f5fd183 - [NFC] [C++20] [Modules] Remove pr60085.cppm with deprecated practice

2024-01-04 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-01-05T11:31:22+08:00
New Revision: f5fd1836836e0d37dea61cc842199713cc0e2fc4

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

LOG: [NFC] [C++20] [Modules] Remove pr60085.cppm with deprecated practice

See https://github.com/llvm/llvm-project/issues/60085 for the complete
story.

Previously I thought the problem got fixed surprisingly. But it is not
true. I just tested it with a deprecated method. My bad. Then the
deprecated style should be removed and the proper style can't work. So
I'll remove the test and reopen that issue to look into it.

Added: 


Modified: 


Removed: 
clang/test/Modules/pr60085.cppm



diff  --git a/clang/test/Modules/pr60085.cppm b/clang/test/Modules/pr60085.cppm
deleted file mode 100644
index fba60120640471..00
--- a/clang/test/Modules/pr60085.cppm
+++ /dev/null
@@ -1,98 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: split-file %s %t
-//
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/d.cppm \
-// RUN: -emit-module-interface -o %t/d.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/c.cppm \
-// RUN: -emit-module-interface -o %t/c.pcm -fmodule-file=%t/d.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/b.cppm \
-// RUN: -emit-module-interface -o %t/b.pcm -fmodule-file=%t/d.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \
-// RUN: -emit-module-interface -o %t/a.pcm -fmodule-file=%t/d.pcm \
-// RUN: -fmodule-file=%t/c.pcm -fmodule-file=%t/b.pcm 
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.pcm \
-// RUN: -S -emit-llvm -disable-llvm-passes -o - | FileCheck %t/a.cppm
-//
-// Use -fmodule-file==
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/d.cppm \
-// RUN: -emit-module-interface -o %t/d.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/c.cppm \
-// RUN: -emit-module-interface -o %t/c.pcm -fmodule-file=%t/d.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/b.cppm \
-// RUN: -emit-module-interface -o %t/b.pcm -fmodule-file=%t/d.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \
-// RUN: -emit-module-interface -o %t/a.pcm -fmodule-file=%t/d.pcm \
-// RUN: -fmodule-file=%t/c.pcm -fmodule-file=%t/b.pcm 
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.pcm \
-// RUN: -S -emit-llvm -disable-llvm-passes -o - | FileCheck %t/a.cppm
-
-//--- d.cppm
-export module d;
-
-export template
-struct integer {
-   using type = int;
-   
-   static constexpr auto value() {
-   return 0;
-   }
-   
-   friend constexpr void f(integer const x) {
-   x.value();
-   }
-};
-
-export constexpr void ddd(auto const value) {
-   f(value);
-}
-
-
-template
-constexpr auto dd = T();
-
-export template
-constexpr auto d() {
-   dd;
-}
-
-//--- c.cppm
-export module c;
-
-import d;
-
-template
-auto cc = T();
-
-auto c() {
-   cc>;
-   integer().value();
-}
-
-//--- b.cppm
-export module b;
-
-import d;
-
-auto b() {
-   integer::type;
-}
-
-//--- a.cppm
-export module a;
-
-import b;
-import c;
-import d;
-
-constexpr void aa() {
-   d>();
-   ddd(integer());
-}
-
-export extern "C" void a() {
-   aa();
-}
-
-// Checks that we emit the IR successfully.
-// CHECK: define{{.*}}@a(



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


[clang] [llvm] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-04 Thread Wang Pengcheng via cfe-commits


@@ -42,9 +42,10 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  const auto ISAInfoFeatures = (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+  /*IgnoreUnknown=*/false);
+  Features.insert(Features.end(), ISAInfoFeatures.begin(),
+  ISAInfoFeatures.end());

wangpc-pp wrote:

```suggestion
  llvm::append_range(Features, (*ISAInfo)->toFeatures(/*AddAllExtension=*/true, 
/*IgnoreUnknown=*/false));
```

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


[clang] [X86] Add ABI handling for __float128 (PR #75156)

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

phoebewang wrote:

> Add a Release notes entry? I always forget exactly what we need to do for ABI 
> fixes/tweaks

Goot point! Done.

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


[clang] [X86] Add ABI handling for __float128 (PR #75156)

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

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/75156

>From 9860e5454bdf3ee3a4283ab7102a8d70c3ebcbbc Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Tue, 12 Dec 2023 17:27:33 +0800
Subject: [PATCH 1/4] [X86] Add ABI handling for fp128

Fixes #74601
---
 clang/lib/CodeGen/Targets/X86.cpp  |  3 ++-
 clang/test/CodeGen/X86/fp128-abi.c | 35 ++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/X86/fp128-abi.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2af24035043884..c4bf38056a673f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1795,7 +1795,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class ,
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
   Current = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
-   k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
+   k == BuiltinType::Float16 || k == BuiltinType::BFloat16 ||
+   k == BuiltinType::Float128) {
   Current = SSE;
 } else if (k == BuiltinType::LongDouble) {
   const llvm::fltSemantics *LDF = ().getLongDoubleFormat();
diff --git a/clang/test/CodeGen/X86/fp128-abi.c 
b/clang/test/CodeGen/X86/fp128-abi.c
new file mode 100644
index 00..1c5d7cf1166ee1
--- /dev/null
+++ b/clang/test/CodeGen/X86/fp128-abi.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +sse2 < %s 
| FileCheck %s --check-prefixes=CHECK
+
+struct st1 {
+  __float128 a;
+};
+
+struct st1 h1(__float128 a) {
+  // CHECK: define{{.*}}fp128 @h1(fp128
+  struct st1 x;
+  x.a = a;
+  return x;
+}
+
+__float128 h2(struct st1 x) {
+  // CHECK: define{{.*}}fp128 @h2(fp128
+  return x.a;
+}
+
+struct st2 {
+  __float128 a;
+  int b;
+};
+
+struct st2 h3(__float128 a, int b) {
+  // CHECK: define{{.*}}void @h3(ptr {{.*}}sret(%struct.st2)
+  struct st2 x;
+  x.a = a;
+  x.b = b;
+  return x;
+}
+
+__float128 h4(struct st2 x) {
+  // CHECK: define{{.*}}fp128 @h4(ptr {{.*}}byval(%struct.st2)
+  return x.a;
+}

>From 2619d6840965fb7447182f2026d5e48eca7b064b Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Thu, 21 Dec 2023 15:33:52 +0800
Subject: [PATCH 2/4] Add non-SSE RUN

---
 clang/lib/CodeGen/Targets/X86.cpp  | 6 --
 clang/test/CodeGen/X86/fp128-abi.c | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index c4bf38056a673f..d053f41ab168f5 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1795,9 +1795,11 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class ,
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
   Current = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
-   k == BuiltinType::Float16 || k == BuiltinType::BFloat16 ||
-   k == BuiltinType::Float128) {
+   k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
   Current = SSE;
+} else if (k == BuiltinType::Float128) {
+  Lo = SSE;
+  Hi = SSEUp;
 } else if (k == BuiltinType::LongDouble) {
   const llvm::fltSemantics *LDF = ().getLongDoubleFormat();
   if (LDF == ::APFloat::IEEEquad()) {
diff --git a/clang/test/CodeGen/X86/fp128-abi.c 
b/clang/test/CodeGen/X86/fp128-abi.c
index 1c5d7cf1166ee1..2a0ae5009338a4 100644
--- a/clang/test/CodeGen/X86/fp128-abi.c
+++ b/clang/test/CodeGen/X86/fp128-abi.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +sse2 < %s 
| FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature -sse2 < %s 
| FileCheck %s --check-prefixes=CHECK
 
 struct st1 {
   __float128 a;

>From 30db4d0a6d74fdc0642801998c8a734c6c82726d Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Fri, 5 Jan 2024 11:13:46 +0800
Subject: [PATCH 3/4] Added release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b62293a33bb9ff..902f64bc9aa144 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -906,6 +906,7 @@ X86 Support
   * Support intrinsic of ``_uwrmsr``.
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
+- Added ABI handling for ``fp128``.
 
 Arm and AArch64 Support
 ^^^

>From af71a05c89240b866154da79cced93eae17821db Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Fri, 5 Jan 2024 11:14:52 +0800
Subject: [PATCH 4/4] Fix typo

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 

[clang] [X86] Add ABI handling for __float128 (PR #75156)

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

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/75156

>From 9860e5454bdf3ee3a4283ab7102a8d70c3ebcbbc Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Tue, 12 Dec 2023 17:27:33 +0800
Subject: [PATCH 1/3] [X86] Add ABI handling for fp128

Fixes #74601
---
 clang/lib/CodeGen/Targets/X86.cpp  |  3 ++-
 clang/test/CodeGen/X86/fp128-abi.c | 35 ++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/X86/fp128-abi.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2af24035043884..c4bf38056a673f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1795,7 +1795,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class ,
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
   Current = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
-   k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
+   k == BuiltinType::Float16 || k == BuiltinType::BFloat16 ||
+   k == BuiltinType::Float128) {
   Current = SSE;
 } else if (k == BuiltinType::LongDouble) {
   const llvm::fltSemantics *LDF = ().getLongDoubleFormat();
diff --git a/clang/test/CodeGen/X86/fp128-abi.c 
b/clang/test/CodeGen/X86/fp128-abi.c
new file mode 100644
index 00..1c5d7cf1166ee1
--- /dev/null
+++ b/clang/test/CodeGen/X86/fp128-abi.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +sse2 < %s 
| FileCheck %s --check-prefixes=CHECK
+
+struct st1 {
+  __float128 a;
+};
+
+struct st1 h1(__float128 a) {
+  // CHECK: define{{.*}}fp128 @h1(fp128
+  struct st1 x;
+  x.a = a;
+  return x;
+}
+
+__float128 h2(struct st1 x) {
+  // CHECK: define{{.*}}fp128 @h2(fp128
+  return x.a;
+}
+
+struct st2 {
+  __float128 a;
+  int b;
+};
+
+struct st2 h3(__float128 a, int b) {
+  // CHECK: define{{.*}}void @h3(ptr {{.*}}sret(%struct.st2)
+  struct st2 x;
+  x.a = a;
+  x.b = b;
+  return x;
+}
+
+__float128 h4(struct st2 x) {
+  // CHECK: define{{.*}}fp128 @h4(ptr {{.*}}byval(%struct.st2)
+  return x.a;
+}

>From 2619d6840965fb7447182f2026d5e48eca7b064b Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Thu, 21 Dec 2023 15:33:52 +0800
Subject: [PATCH 2/3] Add non-SSE RUN

---
 clang/lib/CodeGen/Targets/X86.cpp  | 6 --
 clang/test/CodeGen/X86/fp128-abi.c | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index c4bf38056a673f..d053f41ab168f5 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1795,9 +1795,11 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class ,
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
   Current = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
-   k == BuiltinType::Float16 || k == BuiltinType::BFloat16 ||
-   k == BuiltinType::Float128) {
+   k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
   Current = SSE;
+} else if (k == BuiltinType::Float128) {
+  Lo = SSE;
+  Hi = SSEUp;
 } else if (k == BuiltinType::LongDouble) {
   const llvm::fltSemantics *LDF = ().getLongDoubleFormat();
   if (LDF == ::APFloat::IEEEquad()) {
diff --git a/clang/test/CodeGen/X86/fp128-abi.c 
b/clang/test/CodeGen/X86/fp128-abi.c
index 1c5d7cf1166ee1..2a0ae5009338a4 100644
--- a/clang/test/CodeGen/X86/fp128-abi.c
+++ b/clang/test/CodeGen/X86/fp128-abi.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +sse2 < %s 
| FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature -sse2 < %s 
| FileCheck %s --check-prefixes=CHECK
 
 struct st1 {
   __float128 a;

>From 30db4d0a6d74fdc0642801998c8a734c6c82726d Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Fri, 5 Jan 2024 11:13:46 +0800
Subject: [PATCH 3/3] Added release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b62293a33bb9ff..902f64bc9aa144 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -906,6 +906,7 @@ X86 Support
   * Support intrinsic of ``_uwrmsr``.
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
+- Added ABI handling for ``fp128``.
 
 Arm and AArch64 Support
 ^^^

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


[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-04 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76942

>From caa25a73dd69268490c89d5e9e91b8d545bce760 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 14:02:39 +0900
Subject: [PATCH 1/4] [RISCV] Deduplicate
 RISCVISAInfo::toFeatures/toFeatureVector. NFC

toFeatures and toFeatureVector both output a list of target feature flags, just
with a slightly different interface. toFeatures keeps any unsupported
extensions, and also provides a way to append negative extensions
(AddAllExtensions=true).

This patch combines them into one function, so that a later patch will be be
able to get a std::vector of features that includes all the negative
extensions, which was previously only possible through the StrAlloc interface.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  6 ++--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp  |  6 ++--
 llvm/include/llvm/Support/RISCVISAInfo.h|  6 ++--
 llvm/lib/Object/ELFObjectFile.cpp   |  2 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 38 +++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 30 +---
 6 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..64f5f9e9215dcb 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -245,7 +245,7 @@ collectNonISAExtFeature(ArrayRef 
FeaturesNeedOverride, int XLen) {
 return std::vector();
   }
 
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   std::vector NonISAExtFeatureVec;
 
@@ -303,7 +303,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -420,7 +420,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..b97224426b916a 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (std::string  : (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+ /*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);
diff --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..6d267fae5a5dc6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,37 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;

[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-04 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76942

>From caa25a73dd69268490c89d5e9e91b8d545bce760 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 14:02:39 +0900
Subject: [PATCH 1/3] [RISCV] Deduplicate
 RISCVISAInfo::toFeatures/toFeatureVector. NFC

toFeatures and toFeatureVector both output a list of target feature flags, just
with a slightly different interface. toFeatures keeps any unsupported
extensions, and also provides a way to append negative extensions
(AddAllExtensions=true).

This patch combines them into one function, so that a later patch will be be
able to get a std::vector of features that includes all the negative
extensions, which was previously only possible through the StrAlloc interface.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  6 ++--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp  |  6 ++--
 llvm/include/llvm/Support/RISCVISAInfo.h|  6 ++--
 llvm/lib/Object/ELFObjectFile.cpp   |  2 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 38 +++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 30 +---
 6 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..64f5f9e9215dcb 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -245,7 +245,7 @@ collectNonISAExtFeature(ArrayRef 
FeaturesNeedOverride, int XLen) {
 return std::vector();
   }
 
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   std::vector NonISAExtFeatureVec;
 
@@ -303,7 +303,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -420,7 +420,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..b97224426b916a 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (std::string  : (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+ /*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);
diff --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..6d267fae5a5dc6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,37 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;

[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

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


@@ -470,17 +470,17 @@ std::vector RISCVISAInfo::toFeatures(bool 
AddAllExtensions,
   bool IgnoreUnknown) const {
   std::vector Features;
   for (auto const  : Exts) {
-std::string ExtName = Ext.first;
+StringRef ExtName = Ext.first;

compnerd wrote:

Can we just use destructuring yet?

```c++
for (const auto &[ExtName, _] : Exts) {
```

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


[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

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


@@ -470,17 +470,17 @@ std::vector RISCVISAInfo::toFeatures(bool 
AddAllExtensions,
   bool IgnoreUnknown) const {
   std::vector Features;
   for (auto const  : Exts) {
-std::string ExtName = Ext.first;
+StringRef ExtName = Ext.first;
 
 if (ExtName == "i") // i is not recognized in clang -cc1
   continue;
 if (IgnoreUnknown && !isSupportedExtension(ExtName))
   continue;
 
 if (isExperimentalExtension(ExtName)) {
-  Features.push_back("+experimental-" + ExtName);
+  Features.push_back("+experimental-" + std::string(ExtName));
 } else {
-  Features.push_back("+" + ExtName);
+  Features.push_back("+" + std::string(ExtName));

compnerd wrote:

These do a double string allocation, you can use `Twine` to do a single 
allocation. e.g.,

```c++
(llvm::Twine("+") + ExtName).str()
```

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


[flang] [mlir] [llvm] [libc] [lld] [clang] [openmp] [compiler-rt] [polly] [libcxx] [clang-tools-extra] [CostModel][X86] Fix fpext conversion cost for 16 elements (PR #76278)

2024-01-04 Thread via cfe-commits

HaohaiWen wrote:

There's cross iteration true dependency in previous experiment.
```
vcvtps2pd zmm2, ymm0
vextractf64x4 ymm0, zmm0, 1
vcvtps2pd zmm1, ymm0
```
The second cvt and first cvt of the next iteration need to wait for finish of 
vextract64x4. Therefore its cost is 5.
In real scenario, value of zmm0 should be reset to fpext new input.
```
vmovaps zmm0, zmm3
vcvtps2pd zmm2, ymm0
vextractf64x4 ymm0, zmm0, 1
vcvtps2pd zmm1, ymm0
```
This breaks the dependency and now cost is 3.
```
# ./nanoBench.sh -init "xor zmm0, zmm0" -asm "vmovaps zmm0, zmm3; vcvtps2pd 
zmm2, ymm0; vextractf64x4 ymm0, zmm0, 1; vcvtps2pd zmm1, ymm0" -config 
configs/cfg_SkylakeX_common.txt -unroll 1000 -loop 1000 -warm_up_count 10 -cpu 0
Note: Hyper-threading is enabled; it can be disabled with "sudo ./disable-HT.sh"
CORE_CYCLES: 3.00
INST_RETIRED: 4.00
IDQ.MITE_UOPS: 6.46
IDQ.DSB_UOPS: -0.45
IDQ.MS_UOPS: 0.01
LSD.UOPS: 0.00
UOPS_ISSUED: 6.01
UOPS_EXECUTED: 5.01
UOPS_RETIRED.RETIRE_SLOTS: 6.01
UOPS_DISPATCHED_PORT.PORT_0: 2.00
UOPS_DISPATCHED_PORT.PORT_1: 0.00
UOPS_DISPATCHED_PORT.PORT_2: 0.00
UOPS_DISPATCHED_PORT.PORT_3: 0.00
UOPS_DISPATCHED_PORT.PORT_4: 0.00
UOPS_DISPATCHED_PORT.PORT_5: 3.00
UOPS_DISPATCHED_PORT.PORT_6: 0.01
UOPS_DISPATCHED_PORT.PORT_7: 0.00
```




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


[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-04 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76942

>From caa25a73dd69268490c89d5e9e91b8d545bce760 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 14:02:39 +0900
Subject: [PATCH 1/2] [RISCV] Deduplicate
 RISCVISAInfo::toFeatures/toFeatureVector. NFC

toFeatures and toFeatureVector both output a list of target feature flags, just
with a slightly different interface. toFeatures keeps any unsupported
extensions, and also provides a way to append negative extensions
(AddAllExtensions=true).

This patch combines them into one function, so that a later patch will be be
able to get a std::vector of features that includes all the negative
extensions, which was previously only possible through the StrAlloc interface.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  6 ++--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp  |  6 ++--
 llvm/include/llvm/Support/RISCVISAInfo.h|  6 ++--
 llvm/lib/Object/ELFObjectFile.cpp   |  2 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 38 +++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 30 +---
 6 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..64f5f9e9215dcb 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -245,7 +245,7 @@ collectNonISAExtFeature(ArrayRef 
FeaturesNeedOverride, int XLen) {
 return std::vector();
   }
 
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   std::vector NonISAExtFeatureVec;
 
@@ -303,7 +303,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -420,7 +420,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..b97224426b916a 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (std::string  : (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+ /*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);
diff --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..6d267fae5a5dc6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,37 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;

[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits


@@ -6901,51 +6916,260 @@ bool HandleOperatorDeleteCall(EvalInfo , const 
CallExpr *E) {
 
//===--===//
 namespace {
 
-class BitCastBuffer {
-  // FIXME: We're going to need bit-level granularity when we support
-  // bit-fields.
-  // FIXME: Its possible under the C++ standard for 'char' to not be 8 bits, 
but
-  // we don't support a host or target where that is the case. Still, we should
-  // use a more generic type in case we ever do.
-  SmallVector, 32> Bytes;
+struct BitSlice : public std::slice {
+  BitSlice(size_t Offset, size_t Num) : std::slice(Offset, Num, 1){};
 
-  static_assert(std::numeric_limits::digits >= 8,
-"Need at least 8 bit unsigned char");
+  inline size_t end() const { return start() + size(); }
+};
 
-  bool TargetIsLittleEndian;
+struct BitFieldInfo {
+  /// The offset (in bits) within the appropriate storage type.
+  const unsigned Offset : 16;
+
+  /// The size of the value held by the bit-field, in bits.
+  const unsigned Width : 15;
+
+  /// Whether the bit-field is signed.
+  const unsigned IsSigned : 1;
+
+  /// The storage size in bits which should be used when accessing this
+  /// bitfield.
+  const unsigned StorageSize;
+
+  /// The offset of the bitfield storage from the start of the struct.
+  const CharUnits StorageOffset;
+
+  static BitFieldInfo MakeInfo(const ASTContext , const FieldDecl *FD,
+   const ASTRecordLayout ) {
+const unsigned StorageSize = Ctx.getTypeSize(FD->getType()),
+   FieldOffsetBits = 
Layout.getFieldOffset(FD->getFieldIndex());
+
+unsigned Width = FD->getBitWidthValue(Ctx);
+if (Width > StorageSize) {
+  // e.g. `unsigned uint8_t c : 12`
+  // we truncate to CHAR_BIT * sizeof(T)
+  // (the extra bits are padding)
+  Width = StorageSize;
+}
+unsigned Offset = FieldOffsetBits % StorageSize;
+if (Ctx.getTargetInfo().isBigEndian()) {
+  // big endian bits count from MSB to LSB
+  // so a bit-field of width 16 and size 12 will
+  // occupy bits [0-11] on a little endian machine,
+  // but [3-15] on a big endian machine
+  Offset = StorageSize - (Offset + Width);
+}
+return {
+Offset,
+Width,
+FD->getType()->isSignedIntegerOrEnumerationType(),
+StorageSize,
+Ctx.toCharUnitsFromBits((FieldOffsetBits / StorageSize) * StorageSize),
+};
+  }
+};
 
-public:
-  BitCastBuffer(CharUnits Width, bool TargetIsLittleEndian)
-  : Bytes(Width.getQuantity()),
-TargetIsLittleEndian(TargetIsLittleEndian) {}
-
-  [[nodiscard]] bool readObject(CharUnits Offset, CharUnits Width,
-SmallVectorImpl ) const {
-for (CharUnits I = Offset, E = Offset + Width; I != E; ++I) {
-  // If a byte of an integer is uninitialized, then the whole integer is
-  // uninitialized.
-  if (!Bytes[I.getQuantity()])
+struct BitCastBuffer {
+  // The number of bits in a `char`, needed to handle endianness (which is
+  // assumed to be exclusively big or little) for values with more bits than
+  // this number.
+  //
+  // No current platforms support varying this size.
+  static const uint64_t CharBit = 8;
+
+  const uint64_t BitWidth;
+  const bool IsNativeEndian;
+
+  APInt Data;
+  APInt Invalid; // Indeterminate bits
+
+  BitCastBuffer(uint64_t BitWidth, bool TargetIsLittleEndian, uint64_t CharBit)
+  : BitWidth(BitWidth),
+IsNativeEndian(llvm::sys::IsLittleEndianHost == TargetIsLittleEndian),
+Data(BitWidth, 0), Invalid(BitWidth, ~0, /* extend "sign" bit */ true) 
{
+assert(Invalid.countl_one() == BitWidth);
+assert(CharBit == BitCastBuffer::CharBit);
+  }
+
+  [[nodiscard]] bool readMasked(const uint64_t Offset, APInt ,
+const APInt ) const {
+assert(Output.getBitWidth() == Mask.getBitWidth());
+const BitSlice Which = {Offset, Output.getBitWidth()};
+
+const auto read = [&](const APInt ) {
+  if ((getBits(Invalid, Which) & Mask) != 0)
 return false;
-  Output.push_back(*Bytes[I.getQuantity()]);
+
+  Output = (Output & ~Mask) | (getBits(Data, Which) & Mask);
+  return true;
+};
+
+if (!IsNativeEndian && Output.getBitWidth() > CharBit) {
+  bool OK = read(Mask.byteSwap());
+  Output = Output.byteSwap();
+  return OK;
 }
-if (llvm::sys::IsLittleEndianHost != TargetIsLittleEndian)
-  std::reverse(Output.begin(), Output.end());
+
+return read(Mask);
+  }
+
+  [[nodiscard]] inline bool readObject(const uint64_t Offset,
+   APInt ) const {
+return readObject({Offset, Output.getBitWidth()}, Output);
+  }
+
+  [[nodiscard]] bool readObject(const BitSlice , APInt ) const {
+assert(Output.getBitWidth() <= BitWidth);
+assert(Which.size() <= Output.getBitWidth());
+assert(Which.end() <= BitWidth);
+

[llvm] [clang] [libc] [compiler-rt] [flang] [polly] [clang-tools-extra] [openmp] [libcxx] [lld] [mlir] [CostModel][X86] Fix fpext conversion cost for 16 elements (PR #76278)

2024-01-04 Thread via cfe-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/76278

>From 87f3d68e82dcc752aa727f62b8b1b56b1257b343 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Sat, 23 Dec 2023 13:16:02 +0800
Subject: [PATCH 1/3] [CostModel][X86] Track fpext conversion for 16 elements

---
 llvm/test/Analysis/CostModel/X86/cast.ll | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/llvm/test/Analysis/CostModel/X86/cast.ll 
b/llvm/test/Analysis/CostModel/X86/cast.ll
index 5a83d4e81fd38e..e0173e9df4dc3b 100644
--- a/llvm/test/Analysis/CostModel/X86/cast.ll
+++ b/llvm/test/Analysis/CostModel/X86/cast.ll
@@ -616,27 +616,31 @@ define void @fp_conv(<8 x float> %a, <16 x float>%b, <4 x 
float> %c) {
 ; SSE-LABEL: 'fp_conv'
 ; SSE-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A1 = 
fpext <4 x float> %c to <4 x double>
 ; SSE-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A2 = 
fpext <8 x float> %a to <8 x double>
-; SSE-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A3 = 
fptrunc <4 x double> undef to <4 x float>
-; SSE-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A4 = 
fptrunc <8 x double> undef to <8 x float>
+; SSE-NEXT:  Cost Model: Found an estimated cost of 12 for instruction: %A3 = 
fpext <16 x float> %b to <16 x double>
+; SSE-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A4 = 
fptrunc <4 x double> undef to <4 x float>
+; SSE-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A5 = 
fptrunc <8 x double> undef to <8 x float>
 ; SSE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; AVX-LABEL: 'fp_conv'
 ; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A1 = 
fpext <4 x float> %c to <4 x double>
 ; AVX-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A2 = 
fpext <8 x float> %a to <8 x double>
-; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A3 = 
fptrunc <4 x double> undef to <4 x float>
-; AVX-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A4 = 
fptrunc <8 x double> undef to <8 x float>
+; AVX-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A3 = 
fpext <16 x float> %b to <16 x double>
+; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A4 = 
fptrunc <4 x double> undef to <4 x float>
+; AVX-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A5 = 
fptrunc <8 x double> undef to <8 x float>
 ; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; AVX512-LABEL: 'fp_conv'
 ; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A1 
= fpext <4 x float> %c to <4 x double>
 ; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A2 
= fpext <8 x float> %a to <8 x double>
-; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A3 
= fptrunc <4 x double> undef to <4 x float>
-; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A4 
= fptrunc <8 x double> undef to <8 x float>
+; AVX512-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A3 
= fpext <16 x float> %b to <16 x double>
+; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A4 
= fptrunc <4 x double> undef to <4 x float>
+; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A5 
= fptrunc <8 x double> undef to <8 x float>
 ; AVX512-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret 
void
 ;
   %A1 = fpext <4 x float> %c to <4 x double>
   %A2 = fpext <8 x float> %a to <8 x double>
-  %A3 = fptrunc <4 x double> undef to <4 x float>
-  %A4 = fptrunc <8 x double> undef to <8 x float>
+  %A3 = fpext <16 x float> %b to <16 x double>
+  %A4 = fptrunc <4 x double> undef to <4 x float>
+  %A5 = fptrunc <8 x double> undef to <8 x float>
   ret void
 }

>From 90c9efc967dd02a37ebf2abf0c771011ae670dea Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Sat, 23 Dec 2023 13:28:10 +0800
Subject: [PATCH 2/3] [CostModel][X86] Fix fpext conversion cost for 16
 elements

The fpext conversion cost for 16 elements should be 5.
---
 llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 1 +
 llvm/test/Analysis/CostModel/X86/cast.ll   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp 
b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index 8a04987e768a12..e7b7c9666ed43c 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -2223,6 +2223,7 @@ InstructionCost X86TTIImpl::getCastInstrCost(unsigned 
Opcode, Type *Dst,
   static const TypeConversionCostTblEntry AVX512FConversionTbl[] = {
 { ISD::FP_EXTEND, MVT::v8f64,   MVT::v8f32,  1 },
 { ISD::FP_EXTEND, MVT::v8f64,   MVT::v16f32, 3 },
+{ ISD::FP_EXTEND, MVT::v16f64,  MVT::v16f32, 5 }, // 

[clang] [RISCV] Fix collectNonISAExtFeature returning negative extension features (PR #76962)

2024-01-04 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76962

>From dfaf782113b977c9960358adab88767e23ddbc56 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 20:48:09 +0700
Subject: [PATCH 1/2] [RISCV] Fix collectNonISAExtFeature returning negative
 extension features

collectNonISAExtFeature was returning any negative extension features, e.g.
given an input of

+zifencei,+m,+a,+save-restore,-zbb,-relax,-zfa

It would return

+save-restore,-zbb,-relax,-zfa

Because negative extensions aren't emitted when calling toFeatureVector(), and
so were considered missing. Hence why we still see "-zfa" and "-zfb" in the
tests for the full arch string attributes, even though with a full arch string
we should be overriding the extensions.

This fixes it by using RISCVISAInfo::isSupportedExtensionFeature instead to
check if a feature is an ISA extension.
---
 clang/lib/Basic/Targets/RISCV.cpp | 19 ++-
 .../CodeGen/RISCV/riscv-func-attr-target.c|  8 
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..b98cd093bc9b0e 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -237,22 +237,15 @@ ArrayRef 
RISCVTargetInfo::getTargetBuiltins() const {
 
 static std::vector
 collectNonISAExtFeature(ArrayRef FeaturesNeedOverride, int XLen) {
-  auto ParseResult =
-  llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesNeedOverride);
-
-  if (!ParseResult) {
-consumeError(ParseResult.takeError());
-return std::vector();
-  }
-
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
-
   std::vector NonISAExtFeatureVec;
 
+  auto IsNonISAExtFeature = [](const std::string ) {
+assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
+std::string Ext = Feature.substr(1); // drop the +/-
+return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext);
+  };
   llvm::copy_if(FeaturesNeedOverride, std::back_inserter(NonISAExtFeatureVec),
-[&](const std::string ) {
-  return !llvm::is_contained(ImpliedFeatures, Feat);
-});
+IsNonISAExtFeature);
 
   return NonISAExtFeatureVec;
 }
diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c 
b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
index 506acaba687417..759c33a2250600 100644
--- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
+++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -40,8 +40,8 @@ __attribute__((target("cpu=sifive-u54"))) void 
testAttrCpuOnly() {}
 // CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" 
"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 "tune-cpu"="generic-rv64" }
 // CHECK: attributes #2 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" 
}
 // CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+experimental-zicond,+f,+m,+save-restore,+v,+zbb,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
-// CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,-relax,-zfa"
 }
-// CHECK: attributes #5 = { 
{{.*}}"target-features"="+64bit,+m,+save-restore,-relax,-zbb,-zfa" }
+// CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,-relax"
 }
+// CHECK: attributes #5 = { 
{{.*}}"target-features"="+64bit,+m,+save-restore,-relax" }
 // CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" }
-// CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+m,+save-restore,-relax,-zbb,-zfa" }
-// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zicsr,+zifencei,-relax,-zbb,-zfa"
 }
+// CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+m,+save-restore,-relax" }
+// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zicsr,+zifencei,-relax" 
}

>From 9ab6adf642d71b34280f5b410967c121dbffcc3d Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Fri, 5 Jan 2024 09:40:11 +0700
Subject: [PATCH 2/2] Use StringRef to avoid allocating new std::string

---
 clang/lib/Basic/Targets/RISCV.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index b98cd093bc9b0e..59ae12eed94014 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -241,7 +241,7 @@ collectNonISAExtFeature(ArrayRef 
FeaturesNeedOverride, int XLen) {
 
   auto IsNonISAExtFeature = [](const 

[lld] [llvm] [flang] [clang] [AMDGPU] Introduce Code Object V6 (PR #76954)

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


@@ -1557,140 +1559,98 @@ const EnumEntry ElfHeaderMipsFlags[] = {
   ENUM_ENT(EF_MIPS_ARCH_64R6, "mips64r6")
 };
 
+#define AMDGPU_MACH_ENUM_ENTS  
\
+  ENUM_ENT(EF_AMDGPU_MACH_NONE, "none"),   
\

arsenm wrote:

First one differently indented from the rest

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


[llvm] [lld] [flang] [clang] [AMDGPU] Introduce Code Object V6 (PR #76954)

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


@@ -106,6 +107,25 @@ uint32_t AMDGPU::calcEFlagsV4() const {
   return retMach | retXnack | retSramEcc;
 }
 
+uint32_t AMDGPU::calcEFlagsV6() const {
+  uint32_t flags = calcEFlagsV4();
+
+  uint32_t genericVersion =
+  getEFlags(ctx.objectFiles[0]) & EF_AMDGPU_GENERIC_VERSION;
+
+  // Verify that all input files have compatible generic version.
+  for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
+if (genericVersion != (getEFlags(f) & EF_AMDGPU_GENERIC_VERSION)) {
+  // TODO: test

arsenm wrote:

This is tested?

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


[compiler-rt] [mlir] [libcxx] [clang-tools-extra] [lld] [clang] [flang] [libcxxabi] [libc] [lldb] [llvm] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2024-01-04 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 647f5fe641b30c874bab770fced9fcec9b601161 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/8] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   2 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 456 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0fe3ab44d2466e..dd3ff541fbc7ba 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -110,6 +110,7 @@ set(files
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
   __algorithm/ranges_contains.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 00..16de6c29cb2a1a
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if 

[libcxxabi] [llvm] [flang] [libc] [mlir] [clang] [libcxx] [clang-tools-extra] [compiler-rt] [lldb] [lld] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2024-01-04 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 647f5fe641b30c874bab770fced9fcec9b601161 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/8] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   2 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 456 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0fe3ab44d2466e..dd3ff541fbc7ba 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -110,6 +110,7 @@ set(files
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
   __algorithm/ranges_contains.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 00..16de6c29cb2a1a
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if 

[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits


@@ -6901,51 +6916,260 @@ bool HandleOperatorDeleteCall(EvalInfo , const 
CallExpr *E) {
 
//===--===//
 namespace {
 
-class BitCastBuffer {
-  // FIXME: We're going to need bit-level granularity when we support
-  // bit-fields.
-  // FIXME: Its possible under the C++ standard for 'char' to not be 8 bits, 
but
-  // we don't support a host or target where that is the case. Still, we should
-  // use a more generic type in case we ever do.
-  SmallVector, 32> Bytes;
+struct BitSlice : public std::slice {
+  BitSlice(size_t Offset, size_t Num) : std::slice(Offset, Num, 1){};
 
-  static_assert(std::numeric_limits::digits >= 8,
-"Need at least 8 bit unsigned char");
+  inline size_t end() const { return start() + size(); }
+};
 
-  bool TargetIsLittleEndian;
+struct BitFieldInfo {
+  /// The offset (in bits) within the appropriate storage type.
+  const unsigned Offset : 16;
+
+  /// The size of the value held by the bit-field, in bits.
+  const unsigned Width : 15;
+
+  /// Whether the bit-field is signed.
+  const unsigned IsSigned : 1;
+
+  /// The storage size in bits which should be used when accessing this
+  /// bitfield.
+  const unsigned StorageSize;
+
+  /// The offset of the bitfield storage from the start of the struct.
+  const CharUnits StorageOffset;
+
+  static BitFieldInfo MakeInfo(const ASTContext , const FieldDecl *FD,
+   const ASTRecordLayout ) {

sethp wrote:

This is part-way to the aforementioned refactoring of the bit-field layout & 
access logic between AST and codegen; this `MakeInfo` method happens to make 
the same choices that codegen does, but those choices seem very consistent 
across time and even compilers (sorry, I lost the godbolt link for this one).

Really it's only two:

1. What happens with "oversized" bit-fields, and
2. What "direction" does the offset count on little-endian vs. big-endian?

At this point, the answers seem consistent; most of the complicated stuff 
already got handled in setting up the bit-wise field offsets in the first 
place. 

That said, at this point I'm a little stuck: I can move logic around between 
here, CGRecordBuilder/CGRecordLowering, and `AST/RecordLayoutBuilder.cpp`, but 
I don't have a sense of clarity around the outcome I'd be looking for there. I 
suspect the goal is shaped something like "someone looking to answer those two 
questions differently affects the constant evaluator with their changes", but 
I'm not sure how I'd achieve that.

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


[llvm] [clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-04 Thread Yeting Kuo via cfe-commits

yetingk wrote:

Unwinder could use property `GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS` to know the 
binary uses `ssp` as the shadow stack register.
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/417/files

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


[lld] [libcxxabi] [clang] [clang-tools-extra] [compiler-rt] [lldb] [flang] [libcxx] [mlir] [libc] [llvm] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2024-01-04 Thread via cfe-commits


@@ -0,0 +1,303 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// 
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200
+
+// template S, class T, class Proj = 
identity>
+// requires indirect_binary_predicate, const T*>
+// constexpr bool ranges::contains(I first, S last, const T& value, Proj 
proj = {});   // since C++23
+
+// template
+// requires indirect_binary_predicate, Proj>, const T*>
+// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); 
// since C++23
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "almost_satisfies_types.h"
+#include "boolean_testable.h"

ZijunZhaoCCK wrote:

no, removed

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-04 Thread Akira Hatanaka via cfe-commits

ahatanak wrote:

Any progress on this patch?

As we discussed in https://github.com/llvm/llvm-project/issues/74016, we should 
make sure clang doesn't stop emitting the warning when the definition of a pure 
virtual function is actually needed.

It seems to me that we shouldn't set `NeededForConstantEvaluation` or 
`NeedDefinition` in `Sema::MarkFunctionReferenced` to true when a pure virtual 
function is used in a virtual function call.

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


[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits


@@ -485,16 +869,16 @@ typedef bool bool17 __attribute__((ext_vector_type(17)));
 typedef bool bool32 __attribute__((ext_vector_type(32)));
 typedef bool bool128 __attribute__((ext_vector_type(128)));
 
-static_assert(bit_cast(bool8{1,0,1,0,1,0,1,0}) == (LITTLE_END ? 
0x55 : 0xAA), "");
-static_assert(round_trip(static_cast(0)), "");
-static_assert(round_trip(static_cast(1)), "");
-static_assert(round_trip(static_cast(0x55)), "");
+static_assert(bit_cast(bool8{1,0,1,0,1,0,1,0}) == (LITTLE_END ? 
0x55 : 0xAA));
+static_assert(round_trip('\x00') == 0);
+static_assert(round_trip('\x01') == 0x1);
+static_assert(round_trip('\x55') == 0x55);
 
-static_assert(bit_cast(bool16{1,1,1,1,1,0,0,0, 
1,1,1,1,0,1,0,0}) == (LITTLE_END ? 0x2F1F : 0xF8F4), "");
+static_assert(bit_cast(bool16{1,1,1,1,1,0,0,0, 
1,1,1,1,0,1,0,0}) == (LITTLE_END ? 0x2F1F : 0xF8F4));
 
-static_assert(round_trip(static_cast(0xCAFE)), "");
-static_assert(round_trip(static_cast(0xCAFEBABE)), "");
-static_assert(round_trip(static_cast<__int128_t>(0xCAFEBABE0C05FEFEULL)),
 "");
+static_assert(check_round_trip(static_cast(0xCAFE)));
+static_assert(check_round_trip(static_cast(0xCAFEBABE)));
+static_assert(check_round_trip(static_cast<__int128_t>(0xCAFEBABE0C05FEFEULL)));
 
 // expected-error@+2 {{constexpr variable 'bad_bool9_to_short' must be 
initialized by a constant expression}}
 // expected-note@+1 {{bit_cast involving type 'bool 
__attribute__((ext_vector_type(9)))' (vector of 9 'bool' values) is not allowed 
in a constant expression; element size 1 * element count 9 is not a multiple of 
the byte size 8}}

sethp wrote:

I don't know if it's important or not, but this would be pretty easy to support 
with the new bit-wise `APInt`-backed BitCastBuffer: I didn't try for it because 
there's already quite a lot going on here, but I'm happy to follow up on that 
if it seems worthwhile.

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


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2024-01-04 Thread Haocong Lu via cfe-commits


@@ -18,3 +18,8 @@ void test_floating_promotion(__fp16 *f16, float f32, double 
f64) {
 // CHECK: ImplicitCastExpr {{.*}} 'double' 
 // CHECK-NEXT: 'float'
 }
+
+void test_Float16_no_default_promotion(_Float16 f16) {
+  variadic(1, f16);
+// CHECK-NOT: ImplicitCastExpr {{.*}} 'double' 
+}

Luhaocong wrote:

Done

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


[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits


@@ -404,29 +691,126 @@ constexpr unsigned char identity3b = 
__builtin_bit_cast(unsigned char, identity3
 
 namespace test_bool {
 
-constexpr bool test_bad_bool = bit_cast('A'); // expected-error {{must 
be initialized by a constant expression}} expected-note{{in call}}
+// expected-note@+1 {{cannot be represented in type 'bool'}}
+constexpr bool test_bad_bool = __builtin_bit_cast(bool, 'A'); // 
expected-error {{must be initialized by a constant expression}}
+
+static_assert(round_trip(true));
+static_assert(round_trip(true));
+static_assert(round_trip(false) == false);
 
-static_assert(round_trip(true), "");
-static_assert(round_trip(false), "");
-static_assert(round_trip(false), "");
+static_assert(static_cast(false) == 0x0);
+static_assert(bit_cast(false) == 0x0);
+static_assert(static_cast(true) == 0x1);
+static_assert(bit_cast(true) == 0x1);
 
-static_assert(round_trip((char)0), "");
-static_assert(round_trip((char)1), "");
+static_assert(round_trip(0x01) == 0x1);
+static_assert(round_trip(0x00) == 0x0);
+// expected-note@+2 {{cannot be represented in type 'bool'}}
+// expected-error@+1 {{constant expression}}
+constexpr auto test_bad_bool2 = __builtin_bit_cast(bool, (uint8_t)0x02);
+
+#if LITTLE_END == 1
+constexpr auto okbits = bit_cast>(true);
+#else
+constexpr auto okbits = bit_cast>(true);
+#endif
+static_assert(okbits == 0x1);
+// expected-note@+3 {{bit [1-7]}}
+// expected-note@+2 {{or 'std::byte'; 'bool' is invalid}}
+// expected-error@+1 {{constant expression}}
+constexpr auto _weird_bool = __builtin_bit_cast(bool, okbits);
+
+// these don't work because we're trying to read the whole 8 bits to ensure
+// the value is representable, as above
+// static_assert(round_trip>({0x1}) == 0x1);
+// static_assert(round_trip>({0x0}) == 0x0);
+
+// these work because we're only reading 1 bit of "bool" to ensure
+// "representability"
+static_assert(round_trip, bits<1>>({0x1}) == 0x1);
+static_assert(round_trip, bits<1>>({0x0}) == 0x0);
+
+template 
+constexpr bool extract_bit(unsigned char v) {
+  return static_cast(bit_cast>(v).bits);
 }
+// 0xA5 is a palindrome, so endianness doesn't matter
+// (counting LSB->MSB is the same as MSB->LSB)
+static_assert(extract_bit<0>(0xA5) == 0x1);
+static_assert(extract_bit<2>(0xA5) == 0x1);
+static_assert(extract_bit<5>(0xA5) == 0x1);
+static_assert(extract_bit<7>(0xA5) == 0x1);
+
+static_assert(extract_bit<1>(0xA5) == 0x0);
+static_assert(extract_bit<3>(0xA5) == 0x0);
+static_assert(extract_bit<4>(0xA5) == 0x0);
+static_assert(extract_bit<6>(0xA5) == 0x0);
+
+enum byte : unsigned char {}; // not std::byte or unsigned char
+
+static_assert(extract_bit<5, byte>('\xa5') == 0x1);
+
+struct pad {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  bool : 5; // push field down to the LSB
+#endif
+  bool b : 3;
+};
+
+static_assert(bit_cast(0b001).b == true);
+static_assert(bit_cast(0b000).b == false);
+
+// expected-note@+1 {{cannot be represented in type 'bool'}}
+constexpr auto _bad_bool3 = __builtin_bit_cast(pad, (uint8_t)0b110); // 
expected-error {{must be initialized by a constant expression}}
+
+struct S {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  byte : 7;
+#endif
+  byte z : 1;
+};
+
+constexpr auto s = bit_cast(pad{1});
+static_assert(s.z == 0x1);
+
+// expected-note@+3 {{bit [1-2]}}
+// expected-note@+2 {{or 'std::byte'; 'bool' is invalid}}
+// expected-error@+1 {{constant expression}}
+constexpr auto _bad_bool4 = __builtin_bit_cast(pad, s);
+
+
+// `bool` includes padding bits, but *which* single bit stores the
+// value is under-specified. These tests not-so-secretly assert that
+// it's in fact the LSB that the compiler "sees" as the value.
+struct pack {
+  bool a : 1;
+  bool b : 1;
+
+  // 1 bit of value, 5 bits of padding
+  bool c : 6;
+};
+
+constexpr auto packed = bit_cast(LITTLE_END ? 0x07 : 0xc1);
+static_assert(packed.a && packed.b && packed.c);

sethp wrote:

Taken together this makes a very strong assertion about the ABI of a `boolean`; 
that seems to match the existing behavior, both in how the evaulator handled 
8-bit values and the output from codegen: https://godbolt.org/z/xsjE7aG3e

Probably there's no good reason to make a different decision in the future, but 
it does seem worth calling out: this is far from the only place the evaluator 
rests on the decisions made elsewhere in clang/llvm-land, but it's (partially) 
a new one. 

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


[clang] [CMake][Release] Add option for enabling LTO to cache file (PR #77035)

2024-01-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tom Stellard (tstellar)


Changes

This option is LLVM_RELEASE_ENABLE_LTO and it's turned on by default.

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


1 Files Affected:

- (modified) clang/cmake/caches/Release.cmake (+12-1) 


``diff
diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index 3ea65ce26296c8..a7b9a8d0e29f88 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -2,6 +2,9 @@
 # BOOTSTRAP_* options configure the second build.
 # BOOTSTRAP_BOOTSTRAP_* options configure the third build.
 
+# General Options
+set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
+
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 
 # Stage 1 Bootstrap Setup
@@ -33,9 +36,17 @@ set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
   check-clang CACHE STRING "")
 
 # Stage 2 Options
-set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(STAGE2_PROJECTS "clang")
+if (LLVM_RELEASE_ENABLE_LTO)
+ list(APPEND STAGE2_PROJECTS "lld")
+endif()
+set(BOOTSTRAP_LLVM_ENABLE_PROJECTS ${STAGE2_PROJECTS} CACHE STRING "")
 set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 
 # Stage 3 Options
 set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_PROJECTS 
"clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
+set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LTO ${LLVM_RELEASE_ENABLE_LTO} CACHE 
STRING "")
+if (LLVM_RELEASE_ENABLE_LTO)
+  set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
+endif()

``




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


[clang] [CMake][Release] Add option for enabling LTO to cache file (PR #77035)

2024-01-04 Thread Tom Stellard via cfe-commits

https://github.com/tstellar created 
https://github.com/llvm/llvm-project/pull/77035

This option is LLVM_RELEASE_ENABLE_LTO and it's turned on by default.

>From db643899042aea45da93c1738b523f139f307295 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Fri, 5 Jan 2024 00:58:58 +
Subject: [PATCH] [CMake][Release] Add option for enabling LTO to cache file

This option is LLVM_RELEASE_ENABLE_LTO and it's turned on by default.
---
 clang/cmake/caches/Release.cmake | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index 3ea65ce26296c8..a7b9a8d0e29f88 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -2,6 +2,9 @@
 # BOOTSTRAP_* options configure the second build.
 # BOOTSTRAP_BOOTSTRAP_* options configure the third build.
 
+# General Options
+set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
+
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 
 # Stage 1 Bootstrap Setup
@@ -33,9 +36,17 @@ set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
   check-clang CACHE STRING "")
 
 # Stage 2 Options
-set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(STAGE2_PROJECTS "clang")
+if (LLVM_RELEASE_ENABLE_LTO)
+ list(APPEND STAGE2_PROJECTS "lld")
+endif()
+set(BOOTSTRAP_LLVM_ENABLE_PROJECTS ${STAGE2_PROJECTS} CACHE STRING "")
 set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 
 # Stage 3 Options
 set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_PROJECTS 
"clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
+set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LTO ${LLVM_RELEASE_ENABLE_LTO} CACHE 
STRING "")
+if (LLVM_RELEASE_ENABLE_LTO)
+  set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
+endif()

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


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2024-01-04 Thread Haocong Lu via cfe-commits

https://github.com/Luhaocong updated 
https://github.com/llvm/llvm-project/pull/74439

>From e86dc461c8654b6b9806ad88bf2ba3d731c81d50 Mon Sep 17 00:00:00 2001
From: Lu Haocong 
Date: Tue, 5 Dec 2023 16:45:22 +0800
Subject: [PATCH] [Sema] Warning for _Float16 passed to format specifier '%f'

According to https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2844.pdf,
there are no default argument promotions for _FloatN types.

A warning is needed to notice user to promote _Float16 to double
explicitly, and then pass it to format specifier '%f', which is
consistent with GCC.
---
 clang/lib/AST/FormatString.cpp  |  1 -
 clang/test/Sema/attr-format.c   |  7 +++
 clang/test/SemaCXX/attr-format.cpp  |  1 +
 clang/test/SemaCXX/format-strings-scanf.cpp | 16 ++--
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a24..c5d14b4af7ff15 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -488,7 +488,6 @@ ArgType::matchesType(ASTContext , QualType argTy) const {
 return NoMatchPromotionTypeConfusion;
   break;
 case BuiltinType::Half:
-case BuiltinType::Float16:
 case BuiltinType::Float:
   if (T == C.DoubleTy)
 return MatchPromotion;
diff --git a/clang/test/Sema/attr-format.c b/clang/test/Sema/attr-format.c
index 1f4c864d4f78bd..bdfd8425c4e9a5 100644
--- a/clang/test/Sema/attr-format.c
+++ b/clang/test/Sema/attr-format.c
@@ -16,6 +16,8 @@ typedef const char *xpto;
 void j(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error
 void k(xpto c) __attribute__((format(printf, 1, 0)));   // no-error
 
+void l(char *a, _Float16 b) __attribute__((format(printf, 1, 2))); // 
expected-warning {{GCC requires a function with the 'format' attribute to be 
variadic}}
+
 void y(char *str) __attribute__((format(strftime, 1, 0))); // 
no-error
 void z(char *str, int c, ...) __attribute__((format(strftime, 1, 2))); // 
expected-error {{strftime format attribute requires 3rd parameter to be 0}}
 
@@ -93,6 +95,11 @@ void call_nonvariadic(void) {
   d3("%s", 123); // expected-warning{{format specifies type 'char *' but the 
argument has type 'int'}}
 }
 
+void call_no_default_promotion(void) {
+  a("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' 
but the argument has type '_Float16'}}
+  l("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' 
but the argument has type '_Float16'}}
+}
+
 __attribute__((format(printf, 1, 2)))
 void forward_fixed(const char *fmt, _Bool b, char i, short j, int k, float l, 
double m) { // expected-warning{{GCC requires a function with the 'format' 
attribute to be variadic}}
   forward_fixed(fmt, b, i, j, k, l, m);
diff --git a/clang/test/SemaCXX/attr-format.cpp 
b/clang/test/SemaCXX/attr-format.cpp
index adc05fc46776ca..4509c3a95e8efa 100644
--- a/clang/test/SemaCXX/attr-format.cpp
+++ b/clang/test/SemaCXX/attr-format.cpp
@@ -81,6 +81,7 @@ void do_format() {
 
   format("%c %c %hhd %hd %d\n", (char)'a', 'a', 'a', (short)123, (int)123);
   format("%f %f %f\n", (__fp16)123.f, 123.f, 123.);
+  format("%f", (_Float16)123.f);// expected-warning{{format specifies type 
'double' but the argument has type '_Float16'}}
   format("%Lf", (__fp16)123.f); // expected-warning{{format specifies type 
'long double' but the argument has type '__fp16'}}
   format("%Lf", 123.f); // expected-warning{{format specifies type 'long 
double' but the argument has type 'float'}}
   format("%hhi %hhu %hi %hu %i %u", b, b, b, b, b, b);
diff --git a/clang/test/SemaCXX/format-strings-scanf.cpp 
b/clang/test/SemaCXX/format-strings-scanf.cpp
index 25fe5346791a0d..406c2069e28ca7 100644
--- a/clang/test/SemaCXX/format-strings-scanf.cpp
+++ b/clang/test/SemaCXX/format-strings-scanf.cpp
@@ -22,6 +22,7 @@ union bag {
 unsigned long long ull;
 signed long long sll;
 __fp16 f16;
+_Float16 Float16;
 float ff;
 double fd;
 long double fl;
@@ -51,18 +52,21 @@ void test(void) {
 // expected-warning@+1{{format specifies type 'int *' but the argument has 
type 'short *'}}
 scan("%hhi %i %li", , , );
 
-// expected-warning@+3{{format specifies type 'float *' but the argument 
has type '__fp16 *'}}
+// expected-warning@+4{{format specifies type 'float *' but the argument 
has type '__fp16 *'}}
+// expected-warning@+3{{format specifies type 'float *' but the argument 
has type '_Float16 *'}}
 // expected-warning@+2{{format specifies type 'float *' but the argument 
has type 'double *'}}
 // expected-warning@+1{{format specifies type 'float *' but the argument 
has type 'long double *'}}
-scan("%f %f %f", , , );
+scan("%f %f %f %f", , , , );
 
-// expected-warning@+3{{format specifies type 'double *' but the argument 
has type '__fp16 *'}}
+

[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits


@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple 
x86_64-apple-macosx10.14.0 %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple 
x86_64-apple-macosx10.14.0 %s -fno-signed-char
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple 
aarch64_be-linux-gnu %s
+
+// This is separate from constexpr-builtin-bit-cast.cpp because clangd17 seems 
to behave
+// poorly around __BitInt(N) types, and this isolates that unfortunate 
behavior to one file
+//
+// hopefully a future clangd will not crash or lose track of its syntax 
highlighting, at which
+// point the "bit_precise" namespace ought to be merged back into 
*bit-cast.cpp.
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  define LITTLE_END 1
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#  define LITTLE_END 0
+#else
+#  error "huh?"
+#endif
+
+using uint8_t = unsigned char;
+
+template 
+constexpr To bit_cast(const From ) {
+  static_assert(sizeof(To) == sizeof(From));
+  return __builtin_bit_cast(To, from);
+}
+
+namespace bit_precise {
+// ok so it's a little bit of a lie to say we don't support _BitInt in any 
casts; we do in fact
+// support casting _from_ a _BitInt(N), at least some of the time
+static_assert(bit_cast(0xff) == 0xff);
+template  struct bytes { uint8_t b[N]; };
+static_assert(bit_cast, _BitInt(12)>(0xff).b[(LITTLE_END ? 0 : /* 
fixme */ 0)] == 0xff);
+static_assert(bit_cast, _BitInt(24)>(0xff).b[(LITTLE_END ? 0 : /* 
fixme */ 2)] == 0xff);

sethp wrote:

These tests *also* document the existing (buggy) behavior; I don't expect 
there's a lot of people out there using constexpr `std::bit_cast` on 
`_BitInt(N)` types, but if there are they're having a bad time with it.

That said, I took pains to preserve the existing behavior to try and make this 
change purely "additive"—to the best of my ability I tried to preserve the 
property that no code that previously compiled without error (including badly 
formed constructs such as these) would start producing an error. 

That's a pretty strong stance though, that I went with because I couldn't find 
details on `clang`'s backwards compatibility policy. I'm happy to soften it: in 
this case, I would probably prefer to produce an error instead of a value from 
`APValueToBufferConverter` when it encounders a `_BitInt(N)` type and thereby 
make it consistently unsupported pending future work.

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


[llvm] [clang] [clang-tools-extra] DAG: Implement promotion for strict_fp_round (PR #74332)

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

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


[llvm] [clang] [clang-tools-extra] DAG: Implement promotion for strict_fp_round (PR #74332)

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


@@ -2621,6 +2642,29 @@ SDValue 
DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode *N) {
   return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, Round);
 }
 
+// Explicit operation to reduce precision.  Reduce the value to half precision
+// and promote it back to the legal type.
+SDValue DAGTypeLegalizer::PromoteFloatRes_STRICT_FP_ROUND(SDNode *N) {
+  SDLoc DL(N);
+
+  SDValue Chain = N->getOperand(0);
+  SDValue Op = N->getOperand(1);
+  EVT VT = N->getValueType(0);
+  EVT OpVT = Op->getValueType(0);
+  EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
+  EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
+
+  // Round promoted float to desired precision
+  SDValue Round = DAG.getNode(GetPromotionOpcodeStrict(OpVT, VT), DL,
+  DAG.getVTList(IVT, MVT::Other), Chain, Op);
+  // Promote it back to the legal output type
+  SDValue Res =
+  DAG.getNode(GetPromotionOpcodeStrict(VT, NVT), DL,

arsenm wrote:

They all need updating at some point 

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


[libc] [flang] [clang-tools-extra] [compiler-rt] [libcxx] [lldb] [llvm] [clang] AMDGPU: Make v4bf16 a legal type (PR #76217)

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

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


[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits


@@ -404,29 +691,126 @@ constexpr unsigned char identity3b = 
__builtin_bit_cast(unsigned char, identity3
 
 namespace test_bool {
 
-constexpr bool test_bad_bool = bit_cast('A'); // expected-error {{must 
be initialized by a constant expression}} expected-note{{in call}}
+// expected-note@+1 {{cannot be represented in type 'bool'}}
+constexpr bool test_bad_bool = __builtin_bit_cast(bool, 'A'); // 
expected-error {{must be initialized by a constant expression}}
+
+static_assert(round_trip(true));
+static_assert(round_trip(true));

sethp wrote:

These tests document the existing behavior, but both this and the 
`bit_cast(false)` below are somewhat troublesome in that we're 
promoting the `bool`'s padding bits to "real" bits (by zero-extension). As I 
understand it, that's allowed by the spec (padding bits are "unspecified"), but 
it does mean that we've got to "over-read" `bool`s as being a full `i8` when we 
convert `bit_cast((uint8_t)N)` so that we can refuse to produce a 
constant value if the top bits are non-zero.

It would be more consistent and simplify the implementation a bit to throw an 
error on `bit_cast(false)` in a constexpr context complaining about 
attempting to read padding bits, but I've chosen to preserve the existing 
behavior here in service of backwards compatibility and usability.

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


[libc] [mlir] [flang] [clang-tools-extra] [compiler-rt] [libcxx] [llvm] [clang] [mlir][Linalg] Support dynamic tiles in `lower_pack` transform (PR #76003)

2024-01-04 Thread via cfe-commits

srcarroll wrote:

> To be clear, I am not saying that this is not useful. I just don't know why 
> this is needed.

Fair enough. Me neither. :)

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


[clang] [Clang][C++20] Implement constexpr std::bit_cast for bit-fields (PR #74775)

2024-01-04 Thread via cfe-commits

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


  1   2   3   4   5   6   >