[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jack Styles via cfe-commits

Stylie777 wrote:

It might be worth splitting each feature into its own commit rather than one 
big commit, it makes the review easier. Currently it's difficult to determine 
which section belongs to which feature.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jack Styles via cfe-commits

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jack Styles via cfe-commits

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jonathan Thackray via cfe-commits

jthackray wrote:

> It might be worth splitting each feature into its own commit rather than one 
> big commit, it makes the review easier. Currently it's difficult to determine 
> which section belongs to which feature.

Hmm, yeah possible.

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


[libunwind] [llvm] [AArch64][Libunwind] Add Support for FEAT_PAuthLR DWARF Instruction (PR #112171)

2024-10-16 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 updated 
https://github.com/llvm/llvm-project/pull/112171

>From a702473aacc6a9c47eb80b204ee3200c2ff2eb26 Mon Sep 17 00:00:00 2001
From: Jack Styles 
Date: Thu, 3 Oct 2024 14:20:10 +0100
Subject: [PATCH 1/6] [PAuthLR] Add support for FEAT_PAuth_LR to libunwind

This introduces support for unwinding programs where return addresses
have been signed using FEAT_PAuth_Lr, where the value of PC is used as
a diversifier (-mbranch-protection=pac-ret+pc).

A new vendor specific call frame instruction is added,
named `DW_CFA_AARCH64_negate_ra_state_with_pc`, to instruct the unwinder
tocapture the value of PC at the point of signing and update bit 1 of
the existing `RA_SIGN_STATE` pseudo-register to flag the need to use it
for authentication.

See https://github.com/ARM-software/abi-aa/pull/245 for the ABI change.

Authored-by: pratlucas 
---
 libunwind/src/DwarfInstructions.hpp | 54 ++---
 libunwind/src/DwarfParser.hpp   | 20 +++
 libunwind/src/dwarf2.h  |  3 +-
 3 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881..e7c467de80adb6 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -74,8 +74,10 @@ class DwarfInstructions {
 __builtin_unreachable();
   }
 #if defined(_LIBUNWIND_TARGET_AARCH64)
-  static bool getRA_SIGN_STATE(A &addressSpace, R registers, pint_t cfa,
-   PrologInfo &prolog);
+  static bool isReturnAddressSigned(A &addressSpace, R registers, pint_t cfa,
+PrologInfo &prolog);
+  static bool isReturnAddressSignedWithPC(A &addressSpace, R registers,
+  pint_t cfa, PrologInfo &prolog);
 #endif
 };
 
@@ -173,8 +175,9 @@ v128 DwarfInstructions::getSavedVectorRegister(
 }
 #if defined(_LIBUNWIND_TARGET_AARCH64)
 template 
-bool DwarfInstructions::getRA_SIGN_STATE(A &addressSpace, R registers,
-   pint_t cfa, PrologInfo &prolog) 
{
+bool DwarfInstructions::isReturnAddressSigned(A &addressSpace,
+R registers, pint_t cfa,
+PrologInfo &prolog) {
   pint_t raSignState;
   auto regloc = prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE];
   if (regloc.location == CFI_Parser::kRegisterUnused)
@@ -185,6 +188,22 @@ bool DwarfInstructions::getRA_SIGN_STATE(A 
&addressSpace, R registers,
   // Only bit[0] is meaningful.
   return raSignState & 0x01;
 }
+
+template 
+bool DwarfInstructions::isReturnAddressSignedWithPC(A &addressSpace,
+  R registers,
+  pint_t cfa,
+  PrologInfo &prolog) {
+  pint_t raSignState;
+  auto regloc = prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE];
+  if (regloc.location == CFI_Parser::kRegisterUnused)
+raSignState = static_cast(regloc.value);
+  else
+raSignState = getSavedRegister(addressSpace, registers, cfa, regloc);
+
+  // Only bit[1] is meaningful.
+  return raSignState & 0x02;
+}
 #endif
 
 template 
@@ -288,7 +307,7 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, 
pint_t pc,
   // restored. autia1716 is used instead of autia as autia1716 assembles
   // to a NOP on pre-v8.3a architectures.
   if ((R::getArch() == REGISTERS_ARM64) &&
-  getRA_SIGN_STATE(addressSpace, registers, cfa, prolog) &&
+  isReturnAddressSigned(addressSpace, registers, cfa, prolog) &&
   returnAddress != 0) {
 #if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
 return UNW_ECROSSRASIGNING;
@@ -296,13 +315,24 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 register unsigned long long x17 __asm("x17") = returnAddress;
 register unsigned long long x16 __asm("x16") = cfa;
 
-// These are the autia1716/autib1716 instructions. The hint 
instructions
-// are used here as gcc does not assemble autia1716/autib1716 for pre
-// armv8.3a targets.
-if (cieInfo.addressesSignedWithBKey)
-  asm("hint 0xe" : "+r"(x17) : "r"(x16)); // autib1716
-else
-  asm("hint 0xc" : "+r"(x17) : "r"(x16)); // autia1716
+// We use the hint versions of the authentication instructions below to
+// ensure they're assembled by the compiler even for targets with no
+// FEAT_PAuth/FEAT_PAuth_LR support.
+if(isReturnAddressSignedWithPC(addressSpace, registers, cfa, prolog)) {
+  register unsigned long long x15 __asm("x15") = 
prolog.ptrAuthDiversifier;
+  if(cieInfo.addressesSignedWithBKey) {
+asm("hint 0x27\n\t" // pacm
+"hint 0xe" : "+r"(x17) : "r"(x16),  "r"(x15)); // autib1716
+  } els

[clang] [clang-format] Handle template opener/closer in braced list (PR #112494)

2024-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #112487.

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


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+5) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+6) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c9625c39e527b4..bda9850670ab06 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2504,6 +2504,11 @@ bool UnwrappedLineParser::parseBracedList(bool 
IsAngleBracket, bool IsEnum) {
   // Assume there are no blocks inside a braced init list apart
   // from the ones we explicitly parse out (like lambdas).
   FormatTok->setBlockKind(BK_BracedInit);
+  if (!IsAngleBracket) {
+auto *Prev = FormatTok->Previous;
+if (Prev && Prev->is(tok::greater))
+  Prev->setFinalizedType(TT_TemplateCloser);
+  }
   nextToken();
   parseBracedList();
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 00776dac28a14b..60deae0c9b1129 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3554,6 +3554,12 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
   ASSERT_EQ(Tokens.size(), 21u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);
+
+  Tokens =
+  annotate("auto x{std::conditional_t{}};");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser);
 }
 
 } // namespace

``




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


[clang] [clang-format] Handle template opener/closer in braced list (PR #112494)

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

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/112494

Fixes #112487.

>From f4e0c6554ed63bfb2a1fd17411090ac06038ebc5 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 16 Oct 2024 01:07:14 -0700
Subject: [PATCH] [clang-format] Handle template opener/closer in braced list

Fixes #112487.
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 5 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c9625c39e527b4..bda9850670ab06 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2504,6 +2504,11 @@ bool UnwrappedLineParser::parseBracedList(bool 
IsAngleBracket, bool IsEnum) {
   // Assume there are no blocks inside a braced init list apart
   // from the ones we explicitly parse out (like lambdas).
   FormatTok->setBlockKind(BK_BracedInit);
+  if (!IsAngleBracket) {
+auto *Prev = FormatTok->Previous;
+if (Prev && Prev->is(tok::greater))
+  Prev->setFinalizedType(TT_TemplateCloser);
+  }
   nextToken();
   parseBracedList();
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 00776dac28a14b..60deae0c9b1129 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3554,6 +3554,12 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
   ASSERT_EQ(Tokens.size(), 21u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);
+
+  Tokens =
+  annotate("auto x{std::conditional_t{}};");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser);
 }
 
 } // namespace

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


[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> I also bisected errors on Windows, down to this commit.
> 
> The errors show up when running the compiler-rt testsuite, like this: 
> https://github.com/mstorsjo/llvm-mingw/actions/runs/1135672/job/31598676534
>  A number of tests fail, where `llvm-cov` errors out with `profile uses zlib 
> compression but the profile reader was built without zlib support`.
> 
> This can be reproduced with something as small as `llvm-cov show 
> coverage_comments.cpp.exe -instr-profile coverage_comments.cpp.tmp.profdata`. 
> Binaries of `llvm-cov` from before this change work fine, while binaries from 
> after it produce this error.

This issue can be reproduced with a few prebuilt files: 
https://martin.st/temp/profile/

Download those three files, build `llvm-cov` (on Linux or anywhere), and 
execute this:
```
$ llvm-cov show coverage_comments.cpp.exe -instr-profile 
coverage_comments.cpp.tmp.profdata
```

Before this breaking change, you'll get this:
```
error: C:/path/to/llvm-project/compiler-rt/test/profile/coverage_comments.cpp: 
No such file or directory
warning: The file 
'C:/path/to/llvm-project/compiler-rt/test/profile/coverage_comments.cpp' isn't 
covered.
```
After this change, you instead get this:
```
error: failed to load coverage: 'coverage_comments.cpp.exe': failed to 
uncompress data (zlib)
```

Can someone revert this change to get things back into working order?

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


[clang] [clang][OpenCL][CodeGen][AMDGPU] Do not use `private` as the default AS for when `generic` is available (PR #112442)

2024-10-16 Thread Alex Voicu via cfe-commits


@@ -5903,7 +5904,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   auto Call = RValue::get(
   EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
   if (TmpSize)
-EmitLifetimeEnd(TmpSize, TmpPtr);
+EmitLifetimeEnd(TmpSize, TmpPtr->stripPointerCasts());

AlexVlx wrote:

I would extremely strongly prefer not to mess with this ball of yarn or other 
pieces of functionality (specifically, `CreateMemTemp`), as part of what is 
essentially a point fix of a long standing bug. I'll leave a TODO in place for 
someone that is braver and more skilled.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits

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


[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-16 Thread Yuta Saito via cfe-commits

kateinoigakukun wrote:

Thank you for your detail report and sorry for your inconvenience. I opened a 
PR to revert the root cause: https://github.com/llvm/llvm-project/pull/112520

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


[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits

https://github.com/Mick235711 created 
https://github.com/llvm/llvm-project/pull/112521

A follow-up and alternative proposal to #112289.

In this PR, no new notes are added to avoid noise. Instead, originally, every 
`[[nodiscard]]` trigger, regardless of whether it is on function declaration or 
return type, has the same warning. For instance, for the following program:
```cpp
struct S {};
struct [[nodiscard]] S2 {};
[[nodiscard]] S get1();
S2 get2();
int main() {
  get1();
  get2();
}
```
The generated warning currently is the same for two calls in `main()`: 
([Compiler Explorer](https://godbolt.org/z/8bTa5oqMs))
```cpp
:6:3: warning: ignoring return value of function declared with 
'nodiscard' attribute [-Wunused-result]
6 |   get1();
  |   ^~~~
:7:3: warning: ignoring return value of function declared with 
'nodiscard' attribute [-Wunused-result]
7 |   get2();
  |   ^~~~
2 warnings generated.
```

As suggested by 
https://github.com/llvm/llvm-project/pull/112289#issuecomment-2414341257, this 
PR thus makes a distinction here by making `[[nodiscard]]` that are triggered 
by its placement on return types specifically points out what the return type 
is:
```cpp
test-3.cpp:6:3: warning: ignoring return value of function declared with 
'nodiscard' attribute [-Werror,-Wunused-result]
6 |   get1();
  |   ^~~~
test-3.cpp:7:3: warning: ignoring return value of type 'S2' declared with 
'nodiscard' attribute [-Werror,-Wunused-value]
7 |   get2();
  |   ^~~~
2 warnings generated.
```
In addition to better clarity, this also helps identify which specialization is 
marked as `[[nodiscard]]`, as the standard allows `[[nodiscard]]` to be placed 
on some specializations of a class template only, as demonstrated by 
https://github.com/llvm/llvm-project/pull/112289#issuecomment-2414311233.

For constructor calls, a different warning message is also added. Currently, 
for `[[nodiscard]]` (but not for `__attribute__((warn_unused_result))`), 
temporaries that are discarded as a result of a constructor call generates a 
different warning:
```cpp
warning: ignoring temporary created by a constructor declared with 'nodiscard' 
attribute
```
After this PR, if `[[nodiscard]]` is placed on the constructor itself, nothing 
changed. If `[[nodiscard]]` is placed on the type, the new warning is:
```cpp
warning: ignoring temporary of type 'S' declared with 'nodiscard' attribute
```
("created by a constructor" is removed since "declared with 'nodiscard'" 
applies to the type, not the constructor)

One thing to note here is that for the following scenario:
```cpp
struct [[nodiscard]] S {
  [[nodiscard]] S(int) {}
};
void use() { S(2); }
```
The warning message is generated in the format for constructor placement 
("ignoring temporary created by a constructor"). Similarly, for 
`[[nodiscard]]`/`warn_unused_result` on both functions and its return type, the 
function attribute takes precedence as that is probably "more specific".

Compared to the original PR, `pure` and `const` are not touched, so there are 
no builtin-related issues this time.

Some new test cases are added at the end of `SemaCXX/warn-unused-result.cpp` to 
test the new warning.

>From f673e74f05756c44a0d16420949bd961c0464257 Mon Sep 17 00:00:00 2001
From: Yihe Li 
Date: Wed, 16 Oct 2024 18:53:04 +0800
Subject: [PATCH] [clang] Improve diagnostic on [[nodiscard]] attribute

---
 clang/include/clang/AST/Expr.h|   5 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/AST/Expr.cpp|  18 +--
 clang/lib/Sema/SemaStmt.cpp   |  40 ---
 .../dcl.attr/dcl.attr.nodiscard/p2.cpp|  28 ++---
 .../dcl.attr/dcl.attr.nodiscard/p3.cpp|   2 +-
 clang/test/Sema/c2x-nodiscard.c   |   8 +-
 clang/test/SemaCXX/warn-unused-result.cpp | 111 ++
 8 files changed, 154 insertions(+), 64 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index cbe62411d11bff..8f5679767529fd 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3182,11 +3182,12 @@ class CallExpr : public Expr {
 
   /// Returns the WarnUnusedResultAttr that is either declared on the called
   /// function, or its return type declaration.
-  const Attr *getUnusedResultAttr(const ASTContext &Ctx) const;
+  std::pair
+  getUnusedResultAttr(const ASTContext &Ctx) const;
 
   /// Returns true if this call expression should warn on unused results.
   bool hasUnusedResultAttr(const ASTContext &Ctx) const {
-return getUnusedResultAttr(Ctx) != nullptr;
+return getUnusedResultAttr(Ctx).second != nullptr;
   }
 
   SourceLocation getRParenLoc() const { return RParenLoc; }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c709795e7b21d8..f683bfe1df8dde 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/Di

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yihe Li (Mick235711)


Changes

A follow-up and alternative proposal to #112289.

In this PR, no new notes are added to avoid noise. Instead, originally, every 
`[[nodiscard]]` trigger, regardless of whether it is on function declaration or 
return type, has the same warning. For instance, for the following program:
```cpp
struct S {};
struct [[nodiscard]] S2 {};
[[nodiscard]] S get1();
S2 get2();
int main() {
  get1();
  get2();
}
```
The generated warning currently is the same for two calls in `main()`: 
([Compiler Explorer](https://godbolt.org/z/8bTa5oqMs))
```cpp
:6:3: warning: ignoring return value of function declared with 
'nodiscard' attribute [-Wunused-result]
6 |   get1();
  |   ^~~~
:7:3: warning: ignoring return value of function declared with 
'nodiscard' attribute [-Wunused-result]
7 |   get2();
  |   ^~~~
2 warnings generated.
```

As suggested by 
https://github.com/llvm/llvm-project/pull/112289#issuecomment-2414341257, this 
PR thus makes a distinction here by making `[[nodiscard]]` that are triggered 
by its placement on return types specifically points out what the return type 
is:
```cpp
test-3.cpp:6:3: warning: ignoring return value of function declared with 
'nodiscard' attribute [-Werror,-Wunused-result]
6 |   get1();
  |   ^~~~
test-3.cpp:7:3: warning: ignoring return value of type 'S2' declared with 
'nodiscard' attribute [-Werror,-Wunused-value]
7 |   get2();
  |   ^~~~
2 warnings generated.
```
In addition to better clarity, this also helps identify which specialization is 
marked as `[[nodiscard]]`, as the standard allows `[[nodiscard]]` to be placed 
on some specializations of a class template only, as demonstrated by 
https://github.com/llvm/llvm-project/pull/112289#issuecomment-2414311233.

For constructor calls, a different warning message is also added. Currently, 
for `[[nodiscard]]` (but not for `__attribute__((warn_unused_result))`), 
temporaries that are discarded as a result of a constructor call generates a 
different warning:
```cpp
warning: ignoring temporary created by a constructor declared with 'nodiscard' 
attribute
```
After this PR, if `[[nodiscard]]` is placed on the constructor itself, nothing 
changed. If `[[nodiscard]]` is placed on the type, the new warning is:
```cpp
warning: ignoring temporary of type 'S' declared with 'nodiscard' attribute
```
("created by a constructor" is removed since "declared with 'nodiscard'" 
applies to the type, not the constructor)

One thing to note here is that for the following scenario:
```cpp
struct [[nodiscard]] S {
  [[nodiscard]] S(int) {}
};
void use() { S(2); }
```
The warning message is generated in the format for constructor placement 
("ignoring temporary created by a constructor"). Similarly, for 
`[[nodiscard]]`/`warn_unused_result` on both functions and its return type, the 
function attribute takes precedence as that is probably "more specific".

Compared to the original PR, `pure` and `const` are not touched, so there are 
no builtin-related issues this time.

Some new test cases are added at the end of `SemaCXX/warn-unused-result.cpp` to 
test the new warning.

---

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


8 Files Affected:

- (modified) clang/include/clang/AST/Expr.h (+3-2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6) 
- (modified) clang/lib/AST/Expr.cpp (+10-8) 
- (modified) clang/lib/Sema/SemaStmt.cpp (+26-14) 
- (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp (+14-14) 
- (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p3.cpp (+1-1) 
- (modified) clang/test/Sema/c2x-nodiscard.c (+4-4) 
- (modified) clang/test/SemaCXX/warn-unused-result.cpp (+90-21) 


``diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index cbe62411d11bff..8f5679767529fd 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3182,11 +3182,12 @@ class CallExpr : public Expr {
 
   /// Returns the WarnUnusedResultAttr that is either declared on the called
   /// function, or its return type declaration.
-  const Attr *getUnusedResultAttr(const ASTContext &Ctx) const;
+  std::pair
+  getUnusedResultAttr(const ASTContext &Ctx) const;
 
   /// Returns true if this call expression should warn on unused results.
   bool hasUnusedResultAttr(const ASTContext &Ctx) const {
-return getUnusedResultAttr(Ctx) != nullptr;
+return getUnusedResultAttr(Ctx).second != nullptr;
   }
 
   SourceLocation getRParenLoc() const { return RParenLoc; }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c709795e7b21d8..f683bfe1df8dde 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9265,6 +9265,12 @@ def warn_unus

[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -4020,6 +4079,33 @@ defm STNPD : StorePairNoAlloc<0b01, 1, FPR64Op, simm7s8, 
"stnp">;
 defm STNPQ : StorePairNoAlloc<0b10, 1, FPR128Op, simm7s16, "stnp">;
 }
 
+// Armv9.6-a Load/store no-allocate pair (FEAT_LSUI)
+let Predicates = [HasLSUI] in {
+  defm LDTP: LoadPairOffset<0b11, 0, GPR64z, simm7s8, "ldtp">;
+  def LDTPpre  : LoadPairPreIdx<0b11, 0, GPR64z, simm7s8, "ldtp">;
+  def LDTPpost : LoadPairPostIdx<0b11, 0, GPR64z, simm7s8, "ldtp">;
+
+  defm STTNPX : StorePairNoAllocLSUI<0b11, 0, GPR64z, simm7s8, "sttnp">;
+  defm LDTNPX : LoadPairNoAllocLSUI<0b11, 0, GPR64z, simm7s8, "ldtnp">;
+
+  defm STTP: StorePairOffset<0b11, 0, GPR64z, simm7s8, "sttp">;
+  def STTPpre  : StorePairPreIdx<0b11, 0, GPR64z, simm7s8, "sttp">;
+  def STTPpost : StorePairPostIdx<0b11, 0, GPR64z, simm7s8, "sttp">;
+}
+
+let Predicates = [HasLSUI, HasFPARMv8] in {

CarolineConcatto wrote:

I am not sure if this should be HasSIMD128 instead of HasFPARMv8.
Why it is using HasFPARMv8?

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


[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits

Mick235711 wrote:

CC @Sirraide @erichkeane. (Sorry, I do not have permission to request 
reviewers, so instead used ping)

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


[clang] [OpenCL] Restore addrspacecast for pipe builtins and update test (PR #112514)

2024-10-16 Thread Matt Arsenault via cfe-commits

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


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


[clang] [OpenCL] Restore addrspacecast for pipe builtins and update test (PR #112514)

2024-10-16 Thread Matt Arsenault via cfe-commits


@@ -1,69 +1,67 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
-// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple

arsenm wrote:

It's 2 different paths that both should work, with different output so both 
should be tested 

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-10-16 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 15d85769f119061fbfcae6e9de43982b534ef724 
01a538fbbd93a7f26e1309c9c95d5be0c8500402 --extensions h,cpp -- 
clang/test/Misc/warning-suppression-mappings.cpp 
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
clang/include/clang/Basic/Diagnostic.h 
clang/include/clang/Basic/DiagnosticOptions.h 
clang/include/clang/Frontend/CompilerInstance.h clang/lib/Basic/Diagnostic.cpp 
clang/lib/Basic/DiagnosticIDs.cpp clang/lib/Basic/Warnings.cpp 
clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/ASTUnit.cpp 
clang/lib/Frontend/CompilerInstance.cpp 
clang/lib/Frontend/CompilerInvocation.cpp 
clang/lib/Frontend/PrecompiledPreamble.cpp 
clang/lib/Interpreter/CodeCompletion.cpp clang/lib/Serialization/ASTReader.cpp 
clang/tools/driver/cc1gen_reproducer_main.cpp clang/tools/driver/driver.cpp 
clang/unittests/Basic/DiagnosticTest.cpp 
clang/unittests/Frontend/CompilerInvocationTest.cpp 
llvm/include/llvm/Support/SpecialCaseList.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp
index 1047980b84..c074d719a7 100644
--- a/clang/lib/Basic/Warnings.cpp
+++ b/clang/lib/Basic/Warnings.cpp
@@ -98,7 +98,7 @@ public:
 if (Section == DiagToSection.end())
   return false;
 auto SrcEntries = Section->second->Entries.find("src");
-if(SrcEntries == Section->second->Entries.end())
+if (SrcEntries == Section->second->Entries.end())
   return false;
 // Find the longest glob pattern that matches FilePath. A positive match
 // implies D should be suppressed for FilePath.
@@ -119,7 +119,7 @@ public:
   }
 
 private:
-  llvm::DenseMap DiagToSection;
+  llvm::DenseMap DiagToSection;
 };
 
 void parseSuppressionMappings(const llvm::MemoryBuffer &MB,
@@ -141,7 +141,7 @@ void parseSuppressionMappings(const llvm::MemoryBuffer &MB,
 
 void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
   const DiagnosticOptions &Opts,
-  llvm::vfs::FileSystem& VFS,
+  llvm::vfs::FileSystem &VFS,
   bool ReportDiags) {
   Diags.setSuppressSystemWarnings(true);  // Default to -Wno-system-headers
   Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 464ed8090a..5739eeca4d 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1702,7 +1702,8 @@ bool ASTUnit::LoadFromCompilerInvocation(
   Invocation->getPreprocessorOpts().RetainRemappedFileBuffers = true;
   Invocation->getFrontendOpts().DisableFree = false;
   getDiagnostics().Reset();
-  ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(), 
*VFS);
+  ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(),
+*VFS);
 
   std::unique_ptr OverrideMainBuffer;
   if (PrecompilePreambleAfterNParses > 0) {
@@ -1710,7 +1711,8 @@ bool ASTUnit::LoadFromCompilerInvocation(
 OverrideMainBuffer =
 getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, 
VFS);
 getDiagnostics().Reset();
-ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(), 
*VFS);
+ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(),
+  *VFS);
   }
 
   SimpleTimer ParsingTimer(WantTiming);
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp 
b/clang/unittests/Basic/DiagnosticTest.cpp
index 1be446d864..cffe9d32a6 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -190,7 +190,7 @@ protected:
 private:
   class CaptureDiagnosticConsumer : public DiagnosticConsumer {
   public:
-   std::vector StoredDiags;
+std::vector StoredDiags;
 
 void HandleDiagnostic(DiagnosticsEngine::Level level,
   const Diagnostic &Info) override {

``




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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -2568,12 +2580,59 @@ defm CASPA  : CompareAndSwapPair<1, 0, "a">;
 defm CASPL  : CompareAndSwapPair<0, 1, "l">;
 defm CASPAL : CompareAndSwapPair<1, 1, "al">;
 
+// v9.6-a atomic CAST

CarolineConcatto wrote:

I believe that these CAS and CASP have alias too

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


[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

I also bisected errors on Windows, down to this commit.

The errors show up when running the compiler-rt testsuite, like this: 
https://github.com/mstorsjo/llvm-mingw/actions/runs/1135672/job/31598676534
A number of tests fail, where `llvm-cov` errors out with `profile uses zlib 
compression but the profile reader was built without zlib support`.

This can be reproduced with something as small as `llvm-cov show 
coverage_comments.cpp.exe -instr-profile coverage_comments.cpp.tmp.profdata`. 
Binaries of `llvm-cov` from before this change work fine, while binaries from 
after it produce this error.

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


[clang] [clang] LazyOffsetPtr: Use native pointer width (PR #111995)

2024-10-16 Thread John Paul Adrian Glaubitz via cfe-commits

glaubitz wrote:

Btw, if you submit a fix, it would be great if it could be backported to the 18 
and 19 branches.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-16 Thread via cfe-commits

https://github.com/zmodem updated 
https://github.com/llvm/llvm-project/pull/112378

>From f44ba22a8e5232b3f1e4a680565acd5604a7016c Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 15 Oct 2024 17:18:45 +0200
Subject: [PATCH 1/3] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG
 for C++23

---
 clang/include/clang/Driver/Options.td   | 2 +-
 clang/lib/Basic/Targets/OSTargets.cpp   | 3 +--
 clang/lib/Driver/ToolChains/Clang.cpp   | 1 +
 clang/test/Driver/cl-options.c  | 3 +++
 clang/test/Preprocessor/predefined-win-macros.c | 2 +-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6491e9ac73ce99..3390367173a29d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8526,7 +8526,7 @@ def _SLASH_execution_charset : 
CLCompileJoined<"execution-charset:">,
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
+  HelpText<"Set language version 
(c++14,c++17,c++20,c++23preview,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..ff4d2df163e613 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");
   else if (Opts.CPlusPlus20)
 Builder.defineMacro("_MSVC_LANG", "202002L");
   else if (Opts.CPlusPlus17)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9d2f7a8960b45f..ca8f10c337e1e9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7217,6 +7217,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  .Case("c++17", "-std=c++17")
  .Case("c++20", "-std=c++20")
  // TODO add c++23 and c++26 when MSVC supports it.
+ .Case("c++23preview", "-std=c++23")
  .Case("c++latest", "-std=c++26")
  .Default("");
   if (LanguageStandard.empty())
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 48d281bcd447e7..8191fda97788c1 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -605,6 +605,9 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX20 %s
 // STDCXX20: -std=c++20
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++23preview -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX23PREVIEW %s
+// STDCXX23PREVIEW: -std=c++23
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXXLATEST %s
 // STDCXXLATEST: -std=c++26
 
diff --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 7d29e45c7d5ac6..e7988501afa689 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -56,7 +56,7 @@
 // RUN: %clang_cc1 %s -x c++ -E -dM -triple i686-pc-win32 -fms-extensions 
-fms-compatibility \
 // RUN: -fms-compatibility-version=19.00 -std=c++23 -o - | FileCheck 
-match-full-lines %s --check-prefix=CHECK-MS-CPP2B
 // CHECK-MS-CPP2B: #define _MSC_VER 1900
-// CHECK-MS-CPP2B: #define _MSVC_LANG 202004L
+// CHECK-MS-CPP2B: #define _MSVC_LANG 202302L
 
 // RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN

>From ec1149f694d706e3e550e543bb2e150f73711ce9 Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 15 Oct 2024 19:21:10 +0200
Subject: [PATCH 2/3] set _MSVC_LANG for c++26

---
 clang/lib/Basic/Targets/OSTargets.cpp   | 5 -
 clang/test/Preprocessor/predefined-win-macros.c | 5 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index ff4d2df163e613..88c054150ab224 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -214,7 +214,10 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
   Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
 
 if (Opts.isCom

[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-16 Thread via cfe-commits

zmodem wrote:

> LGTM! Can you also add a release note to clang/docs/ReleaseNotes.rst so users 
> know about the new flag?

Sure, will do.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-16 Thread via cfe-commits

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


[clang] 4ddea29 - [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (#112378)

2024-10-16 Thread via cfe-commits

Author: Hans
Date: 2024-10-16T10:06:43+02:00
New Revision: 4ddea298e60c31d0995c06189a592895d2ad512b

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

LOG: [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (#112378)

As discussed in
https://discourse.llvm.org/t/clang-cl-adding-std-c-23preview/82553

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Preprocessor/predefined-win-macros.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..33eb9a2b5804a0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -605,6 +605,8 @@ Android Support
 Windows Support
 ^^^
 
+- clang-cl now supports ``/std:c++23preview`` which enables C++23 features.
+
 - Clang no longer allows references inside a union when emulating MSVC 1900+ 
even if `fms-extensions` is enabled.
   Starting with VS2015, MSVC 1900, this Microsoft extension is no longer 
allowed and always results in an error.
   Clang now follows the MSVC behavior in this scenario.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2072ae45d55414..379e75b197cf96 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8531,7 +8531,7 @@ def _SLASH_execution_charset : 
CLCompileJoined<"execution-charset:">,
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
+  HelpText<"Set language version 
(c++14,c++17,c++20,c++23preview,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,

diff  --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..88c054150ab224 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -214,9 +214,11 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
   Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
-  if (Opts.CPlusPlus23)
+  if (Opts.CPlusPlus26)
 // TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202400L");
+  else if (Opts.CPlusPlus23)
+Builder.defineMacro("_MSVC_LANG", "202302L");
   else if (Opts.CPlusPlus20)
 Builder.defineMacro("_MSVC_LANG", "202002L");
   else if (Opts.CPlusPlus17)

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c132fa35098ae4..3fc39296f44281 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7225,6 +7225,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  .Case("c++17", "-std=c++17")
  .Case("c++20", "-std=c++20")
  // TODO add c++23 and c++26 when MSVC supports it.
+ .Case("c++23preview", "-std=c++23")
  .Case("c++latest", "-std=c++26")
  .Default("");
   if (LanguageStandard.empty())

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 48d281bcd447e7..8191fda97788c1 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -605,6 +605,9 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX20 %s
 // STDCXX20: -std=c++20
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++23preview -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX23PREVIEW %s
+// STDCXX23PREVIEW: -std=c++23
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXXLATEST %s
 // STDCXXLATEST: -std=c++26
 

diff  --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 7d29e45c7d5ac6..8e539a2a1faf83 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -56,7 +56,12 @@
 // RUN: %clang_cc1 %s -x c++ -E -dM -triple i686-pc-win32 -fms-extensions 
-fms-compatibility \
 // RUN: -fms-compatibility-version=19.00 -std=c++23 -o - | FileCheck 
-match-full-lines %s --check-prefix=CHECK-MS-CPP2B
 // CHECK-MS-CPP2B: #define _M

[clang] [clang] When checking for covariant return types, make sure the pointers or references are to *classes* (PR #111856)

2024-10-16 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov approved this pull request.

LGTM

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


[clang] 1549291 - [clang] Implement constexpr __builtin_bit_cast for complex types (#109981)

2024-10-16 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-10-16T10:47:12+02:00
New Revision: 154929169ab460b6b135103208e7fecd3cfa58f0

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

LOG: [clang] Implement constexpr __builtin_bit_cast for complex types (#109981)

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 52a7f5778ce6d2..8544052d5e4924 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7237,6 +7237,7 @@ class APValueToBufferConverter {
 
 case APValue::ComplexInt:
 case APValue::ComplexFloat:
+  return visitComplex(Val, Ty, Offset);
 case APValue::FixedPoint:
   // FIXME: We should support these.
 
@@ -7323,6 +7324,31 @@ class APValueToBufferConverter {
 return true;
   }
 
+  bool visitComplex(const APValue &Val, QualType Ty, CharUnits Offset) {
+const ComplexType *ComplexTy = Ty->castAs();
+QualType EltTy = ComplexTy->getElementType();
+CharUnits EltSizeChars = Info.Ctx.getTypeSizeInChars(EltTy);
+bool IsInt = Val.isComplexInt();
+
+if (IsInt) {
+  if (!visitInt(Val.getComplexIntReal(), EltTy,
+Offset + (0 * EltSizeChars)))
+return false;
+  if (!visitInt(Val.getComplexIntImag(), EltTy,
+Offset + (1 * EltSizeChars)))
+return false;
+} else {
+  if (!visitFloat(Val.getComplexFloatReal(), EltTy,
+  Offset + (0 * EltSizeChars)))
+return false;
+  if (!visitFloat(Val.getComplexFloatImag(), EltTy,
+  Offset + (1 * EltSizeChars)))
+return false;
+}
+
+return true;
+  }
+
   bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
 const VectorType *VTy = Ty->castAs();
 QualType EltTy = VTy->getElementType();
@@ -7595,6 +7621,23 @@ class BufferToAPValueConverter {
 return ArrayValue;
   }
 
+  std::optional visit(const ComplexType *Ty, CharUnits Offset) {
+QualType ElementType = Ty->getElementType();
+CharUnits ElementWidth = Info.Ctx.getTypeSizeInChars(ElementType);
+bool IsInt = ElementType->isIntegerType();
+
+std::optional Values[2];
+for (unsigned I = 0; I != 2; ++I) {
+  Values[I] = visitType(Ty->getElementType(), Offset + I * ElementWidth);
+  if (!Values[I])
+return std::nullopt;
+}
+
+if (IsInt)
+  return APValue(Values[0]->getInt(), Values[1]->getInt());
+return APValue(Values[0]->getFloat(), Values[1]->getFloat());
+  }
+
   std::optional visit(const VectorType *VTy, CharUnits Offset) {
 QualType EltTy = VTy->getElementType();
 unsigned NElts = VTy->getNumElements();

diff  --git a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp 
b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
index 7520b43a194aba..5ddb77b35ff145 100644
--- a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
+++ b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
@@ -511,3 +511,19 @@ constexpr bool9 bad_short_to_bool9 = 
__builtin_bit_cast(bool9, static_cast(0xCAFEBABE0C05FEFEULL), "");
+  static_assert(bit_cast(test_int_complex) == (LITTLE_END
+   ? 
0xCAFEBABE0C05FEFE
+   : 
0x0C05FEFECAFEBABE), "");
+  static_assert(sizeof(double) == 2 * sizeof(float));
+  struct TwoFloats { float A; float B; };
+  constexpr _Complex float test_float_complex = {1.0f, 2.0f};
+  constexpr TwoFloats TF = __builtin_bit_cast(TwoFloats, test_float_complex);
+  static_assert(TF.A == 1.0f && TF.B == 2.0f);
+
+  constexpr double D = __builtin_bit_cast(double, test_float_complex);
+  constexpr int M = __builtin_bit_cast(int, test_int_complex); // 
expected-error {{__builtin_bit_cast source size does not equal destination 
size}}
+}



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


[clang] [clang] Implement constexpr __builtin_bit_cast for complex types (PR #109981)

2024-10-16 Thread Timm Baeder via cfe-commits

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


[clang] [Modules][NFC] Rewrite friend-definition-2.cpp with split-file (PR #112380)

2024-10-16 Thread Dmitry Polukhin via cfe-commits


@@ -1,32 +1,53 @@
-// RUN: %clang_cc1 -std=c++14 -fmodules %s -verify
-// RUN: %clang_cc1 -std=c++14 -fmodules %s -verify -triple i686-windows
-// expected-no-diagnostics
-#pragma clang module build A
-module A {}
-#pragma clang module contents
-#pragma clang module begin A
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=A -emit-module 
%t/a.modulemap -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=B -emit-module 
%t/b.modulemap -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules 
-fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm \
+// RUN:   %t/use.cc -verify
+
+// RUN: rm -f %t/*.pcm
+
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=A -emit-module 
%t/a.modulemap -o %t/a.pcm -triple i686-windows
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=B -emit-module 
%t/b.modulemap -o %t/b.pcm -triple i686-windows
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules 
-fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm \
+// RUN:   %t/use.cc -verify -triple i686-windows
+
+//--- a.modulemap
+module A {
+  header "a.h"
+}
+
+//--- a.h
+#ifndef A_H
+#define A_H
+template struct ct { friend auto operator-(ct, ct) { struct X {}; 
return X(); } void x(); };
+#endif
+
+//--- b.modulemap
+module B {
+  header "b.h"
+}
+
+//--- b.h
+#ifndef B_H
+#define B_H
 template struct ct { friend auto operator-(ct, ct) { struct X {}; 
return X(); } void x(); };

dmpolukhin wrote:

I think in this particular case it doesn't change semantic because you don't 
pass `a.modulemap` when compiling `b.cpm` so it is textual inclusion. To be 
100% compatible you can create a new header without modules map and textually 
include it in both headers (just having code duplication is not a good idea and 
also doesn't match what happens in reality) but I'm OK with keeping it as-is.

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


[clang] [clang] Support `#pragma clang loop pipeline(enable)` (PR #112501)

2024-10-16 Thread Ryotaro Kasuga via cfe-commits

https://github.com/kasuga-fj created 
https://github.com/llvm/llvm-project/pull/112501

Previously `#pragma clang loop pipeline` only accepted `disable`. This patch 
adds `enable` as a valid argument for this pragma. This allows Software 
Pipelining optimization to be applied to some loops instead of all loops.

This is clang part of the fix.

>From 04f0f22178272dbf2ebe8a74569245f97a2f644b Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga 
Date: Thu, 10 Oct 2024 09:08:00 +
Subject: [PATCH] [clang] Support `#pragma clang loop pipeline(enable)`

Previously `#pragma clang loop pipeline` only accepted `disable`. This
patch adds `enable` as a valid argument for this pragma. This allows
Software Pipelining optimization to be applied to some loops instead of
all loops.

This is clang part of the fix.
---
 clang/include/clang/Basic/Attr.td |  6 ++--
 clang/include/clang/Basic/AttrDocs.td | 12 ++-
 .../clang/Basic/DiagnosticParseKinds.td   |  2 --
 clang/lib/CodeGen/CGLoopInfo.cpp  | 36 ---
 clang/lib/CodeGen/CGLoopInfo.h| 11 +++---
 clang/lib/Parse/ParsePragma.cpp   | 34 --
 clang/lib/Sema/SemaStmtAttr.cpp   |  8 ++---
 clang/test/CodeGenCXX/pragma-pipeline.cpp | 12 +++
 clang/test/Parser/pragma-loop.cpp |  2 +-
 clang/test/Parser/pragma-pipeline.cpp |  8 +++--
 10 files changed, 82 insertions(+), 49 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index ec3d6e0079f630..3d5d5f6ca99f1e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4190,7 +4190,7 @@ def LoopHint : Attr {
   /// unroll_and_jam: attempt to unroll and jam loop if State == Enable.
   /// unroll_and_jam_count: unroll and jams loop 'Value' times.
   /// distribute: attempt to distribute loop if State == Enable.
-  /// pipeline: disable pipelining loop if State == Disable.
+  /// pipeline: enable pipelining loop if State == Enable.
   /// pipeline_initiation_interval: create loop schedule with initiation 
interval equal to 'Value'.
 
   /// #pragma unroll  directive
@@ -4210,7 +4210,7 @@ def LoopHint : Attr {
"vectorize_predicate"],
   ["Vectorize", "VectorizeWidth", "Interleave", 
"InterleaveCount",
"Unroll", "UnrollCount", "UnrollAndJam", 
"UnrollAndJamCount",
-   "PipelineDisabled", "PipelineInitiationInterval", 
"Distribute",
+   "Pipeline", "PipelineInitiationInterval", 
"Distribute",
"VectorizePredicate"]>,
   EnumArgument<"State", "LoopHintState", /*is_string=*/false,
["enable", "disable", "numeric", "fixed_width",
@@ -4230,7 +4230,7 @@ def LoopHint : Attr {
 case UnrollCount: return "unroll_count";
 case UnrollAndJam: return "unroll_and_jam";
 case UnrollAndJamCount: return "unroll_and_jam_count";
-case PipelineDisabled: return "pipeline";
+case Pipeline: return "pipeline";
 case PipelineInitiationInterval: return "pipeline_initiation_interval";
 case Distribute: return "distribute";
 case VectorizePredicate: return "vectorize_predicate";
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b1512e22ee2dd4..e2591c7be7905a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3968,8 +3968,18 @@ def PipelineHintDocs : Documentation {
   placed immediately before a for, while, do-while, or a C++11 range-based for
   loop.
 
+  Using ``#pragma clang loop pipeline(enable)`` applies the software pipelining
+  optimization if possible:
+
+  .. code-block:: c++
+
+  #pragma clang loop pipeline(enable)
+  for (...) {
+...
+  }
+
   Using ``#pragma clang loop pipeline(disable)`` avoids the software pipelining
-  optimization. The disable state can only be specified:
+  optimization:
 
   .. code-block:: c++
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 78510e61a639fa..1bf82923aa26bd 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1676,8 +1676,6 @@ def err_pragma_fp_invalid_argument : Error<
 
 def err_pragma_invalid_keyword : Error<
   "invalid argument; expected 'enable'%select{|, 'full'}0%select{|, 
'assume_safety'}1 or 'disable'">;
-def err_pragma_pipeline_invalid_keyword : Error<
-"invalid argument; expected 'disable'">;
 
 // API notes.
 def err_type_unparsed : Error<"unparsed tokens following type">;
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 6b886bd6b6d2cf..04b229da2013e3 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -39,9 +39,10 @@ MDNode *LoopInfo::createPipeliningM

[clang] [clang] When checking for covariant return types, make sure the pointers or references are to *classes* (PR #111856)

2024-10-16 Thread Boaz Brickner via cfe-commits

https://github.com/bricknerb updated 
https://github.com/llvm/llvm-project/pull/111856

>From 786d31e2657964e578cd1fdf2006b0fb3b19fab6 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Thu, 10 Oct 2024 15:15:23 +
Subject: [PATCH 1/5] [clang] When checking for covariant return types, make
 sure the pointers or references are to *classes*.

https://eel.is/c++draft/class.virtual#8.1

This prevents overriding methods with non class return types that have less 
cv-qualification.
---
 clang/lib/Sema/SemaDeclCXX.cpp  |  4 ++--
 clang/test/SemaCXX/virtual-override.cpp | 10 ++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9cb2ed02a3f764..6195b62b8afa16 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -18273,7 +18273,7 @@ bool Sema::CheckOverridingFunctionReturnType(const 
CXXMethodDecl *New,
   }
 
   // The return types aren't either both pointers or references to a class 
type.
-  if (NewClassTy.isNull()) {
+  if (NewClassTy.isNull() || !NewClassTy->isStructureOrClassType()) {
 Diag(New->getLocation(),
  diag::err_different_return_type_for_overriding_virtual_function)
 << New->getDeclName() << NewTy << OldTy
@@ -18296,7 +18296,7 @@ bool Sema::CheckOverridingFunctionReturnType(const 
CXXMethodDecl *New,
   diag::err_covariant_return_incomplete,
   New->getDeclName()))
 return true;
-}
+  }
 
 // Check if the new class derives from the old class.
 if (!IsDerivedFrom(New->getLocation(), NewClassTy, OldClassTy)) {
diff --git a/clang/test/SemaCXX/virtual-override.cpp 
b/clang/test/SemaCXX/virtual-override.cpp
index 72abfc3cf51e1f..6008b8ed063f20 100644
--- a/clang/test/SemaCXX/virtual-override.cpp
+++ b/clang/test/SemaCXX/virtual-override.cpp
@@ -289,3 +289,13 @@ namespace PR8168 {
 static void foo() {} // expected-error{{'static' member function 'foo' 
overrides a virtual function}}
   };
 }
+
+namespace T13 {
+  struct A {
+virtual const int *f() const; // expected-note{{overridden virtual 
function is here}}
+  };
+
+  struct B : A {
+int *f() const override; // expected-error{{virtual function 'f' has a 
different return type ('int *') than the function it overrides (which has 
return type 'const int *')}}
+  };
+}

>From 027a985f2ca2bbe007db751af4fdbb5d8f12959d Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Fri, 11 Oct 2024 05:29:05 +
Subject: [PATCH 2/5] Fix indentation.

---
 clang/lib/Sema/SemaDeclCXX.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 6195b62b8afa16..75d010dc4e04d8 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -18296,7 +18296,7 @@ bool Sema::CheckOverridingFunctionReturnType(const 
CXXMethodDecl *New,
   diag::err_covariant_return_incomplete,
   New->getDeclName()))
 return true;
-  }
+}
 
 // Check if the new class derives from the old class.
 if (!IsDerivedFrom(New->getLocation(), NewClassTy, OldClassTy)) {

>From 0b0452f3b7206fdea595aff684c329fd4563f631 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Fri, 11 Oct 2024 12:27:00 +
Subject: [PATCH 3/5] [clang] Add the breaking change to more correctly check
 covariance when return type doesn't point to a class to release notes.

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index df165b91252505..55ca61955c5b01 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -99,6 +99,19 @@ C++ Specific Potentially Breaking Changes
 // Was error, now evaluates to false.
 constexpr bool b = f() == g();
 
+- Clang will now correctly not consider pointers to non classes for covariance.
+
+  .. code-block:: c++
+
+  struct A {
+virtual const int *f() const;
+  };
+  struct B : A {
+// Return type has less cv-qualification but doesn't point to a class.
+// Error will be generated.
+int *f() const override;
+  };
+
 ABI Changes in This Version
 ---
 

>From d5cf39d317ea2474477382f6dfa3a116c7db67f8 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Fri, 11 Oct 2024 13:38:39 +
Subject: [PATCH 4/5] [clang] Fix code indentation in release notes for fixing
 how we handle pointers to non classes when calculating covariance.

---
 clang/docs/ReleaseNotes.rst | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 55ca61955c5b01..3ae716859fdcdf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -103,14 +103,14 @@ C++ Specific Potentially Breaking Changes
 
   .. code-block:: c++
 
-  struct 

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits


@@ -115,20 +115,20 @@ void usage() {
   S('A'); // expected-warning {{ignoring temporary created by a constructor 
declared with 'nodiscard' attribute: Don't let that S-Char go!}}
   S(1);
   S(2.2);
-  Y(); // expected-warning {{ignoring temporary created by a constructor 
declared with 'nodiscard' attribute: Don't throw me away either!}}
+  Y(); // expected-warning {{ignoring temporary of type 'Y' declared with 
'nodiscard' attribute: Don't throw me away either!}}
   S s;
-  ConvertTo{}; // expected-warning {{ignoring return value of function 
declared with 'nodiscard' attribute: Don't throw me away!}}
+  ConvertTo{}; // expected-warning {{ignoring return value of type 'ConvertTo' 
declared with 'nodiscard' attribute: Don't throw me away!}}

Mick235711 wrote:

BTW, isn't this supposed to be a constructor call? Why is `ConvertTo{}` 
different compared to `Y()` above?

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


[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -3767,28 +3764,26 @@ void 
ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst,
   continue;
 }
 
-ProgramStateRef state = Pred->getState();
-SVal V = state->getSVal(Ex, Pred->getLocationContext());
+ProgramStateRef State = Pred->getState();
+SVal V = State->getSVal(Ex, Pred->getLocationContext());
 std::optional SEV = V.getAs();
 if (SEV && SEV->isExpression()) {
-  const std::pair &tags =
-geteagerlyAssumeBinOpBifurcationTags();
+  auto [TrueTag, FalseTag] = getEagerlyAssumeBifurcationTags();
 
-  ProgramStateRef StateTrue, StateFalse;
-  std::tie(StateTrue, StateFalse) = state->assume(*SEV);
+  auto [StateTrue, StateFalse] = State->assume(*SEV);
 
   // First assume that the condition is true.
   if (StateTrue) {
 SVal Val = svalBuilder.makeIntVal(1U, Ex->getType());
 StateTrue = StateTrue->BindExpr(Ex, Pred->getLocationContext(), Val);
-Bldr.generateNode(Ex, Pred, StateTrue, tags.first);
+Bldr.generateNode(Ex, Pred, StateTrue, TrueTag);
   }
 
   // Next, assume that the condition is false.
   if (StateFalse) {
 SVal Val = svalBuilder.makeIntVal(0U, Ex->getType());
 StateFalse = StateFalse->BindExpr(Ex, Pred->getLocationContext(), Val);
-Bldr.generateNode(Ex, Pred, StateFalse, tags.second);
+Bldr.generateNode(Ex, Pred, StateFalse, FalseTag);

steakhal wrote:

I'd be fine with having a different tag there. Actually, that would be really 
useful at times - e.g. with tooling around egraphs that is not present 
upstream. So having a tag is not an issue. Having a tag that lies about that we 
took an eager decision here is the problem. I agree that this shouldn't be done 
part of this PR. And I'm also fine leaving this alone in the future. I just 
wanted to raise this never the less.

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


[clang] [clang][OpenCL][CodeGen][AMDGPU] Do not use `private` as the default AS for when `generic` is available (PR #112442)

2024-10-16 Thread Matt Arsenault via cfe-commits


@@ -5903,7 +5904,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   auto Call = RValue::get(
   EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
   if (TmpSize)
-EmitLifetimeEnd(TmpSize, TmpPtr);
+EmitLifetimeEnd(TmpSize, TmpPtr->stripPointerCasts());

arsenm wrote:

Can still just do the stripPointerCasts once above 

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


[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -299,13 +299,12 @@ ANALYZER_OPTION(
 
 ANALYZER_OPTION(
 bool, ShouldEagerlyAssume, "eagerly-assume",
-"Whether we should eagerly assume evaluations of conditionals, thus, "
-"bifurcating the path. This indicates how the engine should handle "
-"expressions such as: 'x = (y != 0)'. When this is true then the "
-"subexpression 'y != 0' will be eagerly assumed to be true or false, thus "
-"evaluating it to the integers 0 or 1 respectively. The upside is that "
-"this can increase analysis precision until we have a better way to lazily 
"
-"evaluate such logic. The downside is that it eagerly bifurcates paths.",
+"If this is enabled (the default behavior), when the analyzer encounters "
+"a comparison operator or logical negation, it immediately splits the "

steakhal wrote:

I don't get your response here. I thought we want to update the doc comments 
here to reflect what the function does. I raised that I think implicit 
conversions also trigger this code path (and do eager splits). Consequently, I 
figured that this behavior should be also mentioned here and now.

If bool conversions don't trigger this function, then of course my suggestion 
is void.
I didn't mean to suggest function changes by my comment.

About the TODO notes: I wish we had some lightweight list of things that we as 
maintainers agree that is easy to do, we have a clear NFC or semantic change in 
mind but nobody has the time doing it. I have in mind a lot of NFC refactors, 
API cleanups where I never get to, but I wish would be done.

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


[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy 
Message-ID:
In-Reply-To: 


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

LGTM, modulo single inline unresolved comment thread.

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


[clang] [clang][bytecode] Implement the constexpr built-in abs function. (PR #112459)

2024-10-16 Thread via cfe-commits

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -833,8 +841,8 @@ def HasV9_5aOps : Architecture64<9, 5, "a", "v9.5a",
   [HasV9_4aOps, FeatureCPA],
   !listconcat(HasV9_4aOps.DefaultExts, [FeatureCPA,  FeatureLUT, 
FeatureFAMINMAX])>;
 def HasV9_6aOps : Architecture64<9, 6, "a", "v9.6a",
-  [HasV9_5aOps],
-  !listconcat(HasV9_5aOps.DefaultExts, [])>;
+  [HasV9_5aOps, FeatureLSUI, FeatureOCCMO],
+  !listconcat(HasV9_5aOps.DefaultExts, [FeatureLSUI, FeatureOCCMO])>;

SpencerAbson wrote:

I don't believe `FEAT_PCDPHINT` is a mandatory ArmV9.6 extension.

https://developer.arm.com/documentation/109697/2024_09/Feature-descriptions/The-Armv9-6-architecture-extension

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


[clang] [clang][bytecode] Implement the constexpr built-in abs function. (PR #112459)

2024-10-16 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/112459

>From dfa1585af3f080987cbd15830c45c34bfecc1fca Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 16 Oct 2024 01:18:13 +
Subject: [PATCH 1/6] implement constexpr builtin {l}abs

---
 clang/include/clang/Basic/Builtins.td |  1 +
 clang/lib/AST/ExprConstant.cpp| 11 +++
 clang/test/AST/ByteCode/builtin-functions.cpp |  9 +
 3 files changed, 21 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index bda8a48be92bda..e1b4d5b1fdc0a5 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -2714,6 +2714,7 @@ def Abs : IntMathTemplate, LibBuiltin<"stdlib.h"> {
   let Attributes = [NoThrow, Const];
   let Prototype = "T(T)";
   let AddBuiltinPrefixedAlias = 1;
+  let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
 }
 
 def Calloc : LibBuiltin<"stdlib.h"> {
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 52a7f5778ce6d2..69539a7f03feba 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13055,6 +13055,17 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.popcount() % 2, E);
   }
 
+  case Builtin::BI__builtin_abs:
+  case Builtin::BI__builtin_labs:
+  case Builtin::BI__builtin_llabs: {
+APSInt Val;
+if (!EvaluateInteger(E->getArg(0), Val, Info))
+  return false;
+if (Val.isNegative())
+  Val.negate();
+return Success(Val, E);
+  }
+
   case Builtin::BI__builtin_popcount:
   case Builtin::BI__builtin_popcountl:
   case Builtin::BI__builtin_popcountll:
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 450ff5671314db..46e5b0579bd575 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -265,6 +265,15 @@ namespace fpclassify {
   char classify_subnorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1.0e-38f)];
 }
 
+namespace abs {
+static_assert(__builtin_abs(14) == 14, "");
+static_assert(__builtin_labs(14L) == 14L, "");
+static_assert(__builtin_llabs(14LL) == 14LL, "");
+static_assert(__builtin_abs(-14) == 14, "");
+static_assert(__builtin_labs(-14L) == 14L, "");
+static_assert(__builtin_llabs(-14LL) == 14LL, "");
+} // namespace abs
+
 namespace fabs {
   static_assert(__builtin_fabs(-14.0) == 14.0, "");
 }

>From 52e1d070b392ea4651acf5f7f984a1defb035459 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 16 Oct 2024 12:32:37 +0800
Subject: [PATCH 2/6] Update InterpBuiltin.cpp

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 65c7b4e5306d72..1e1a75e5514aec 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -563,6 +563,17 @@ static bool interp__builtin_fabs(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_abs(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *Func,
+const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  if (Val.isNegative())
+Val.negate();
+  pushInteger(S, Val, Call->getType());
+  return true;
+}
+
 static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
  const InterpFrame *Frame,
  const Function *Func,
@@ -1808,6 +1819,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_abs:
+  case Builtin::BI__builtin_labs:
+  case Builtin::BI__builtin_llabs:
+  if (!interp__builtin_abs(S, OpPC, Frame, F, Call))
+return false;
+  break;
+
   case Builtin::BI__builtin_popcount:
   case Builtin::BI__builtin_popcountl:
   case Builtin::BI__builtin_popcountll:

>From 227193529178a1c1484c0da42a06289a26c75114 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 16 Oct 2024 12:33:29 +0800
Subject: [PATCH 3/6] Update ExprConstant.cpp

---
 clang/lib/AST/ExprConstant.cpp | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 69539a7f03feba..52a7f5778ce6d2 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13055,17 +13055,6 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.popcount() % 2, E);
   }
 
-  case Builtin::BI__builtin_abs:
-  case Builtin::BI__builtin_labs:
-  case Builtin::BI__builtin_llabs: {
-APSInt Val;
-if (!EvaluateInteger(E->getArg(0), Val, Info))
-  return false;
-if (Val.isNegative())
-  Val.nega

[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jack Styles via cfe-commits


@@ -833,8 +841,8 @@ def HasV9_5aOps : Architecture64<9, 5, "a", "v9.5a",
   [HasV9_4aOps, FeatureCPA],
   !listconcat(HasV9_4aOps.DefaultExts, [FeatureCPA,  FeatureLUT, 
FeatureFAMINMAX])>;
 def HasV9_6aOps : Architecture64<9, 6, "a", "v9.6a",
-  [HasV9_5aOps],
-  !listconcat(HasV9_5aOps.DefaultExts, [])>;
+  [HasV9_5aOps, FeatureLSUI, FeatureOCCMO],
+  !listconcat(HasV9_5aOps.DefaultExts, [FeatureLSUI, FeatureOCCMO])>;

Stylie777 wrote:

I would agree that it is an optional feature, so should not be included here.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -4660,6 +4746,21 @@ let Predicates = [HasLOR] in {
   def STLLRH0 : InstAlias<"stllrh\t$Rt, [$Rn, #0]",  (STLLRH   GPR32: $Rt, 
GPR64sp:$Rn)>;
 }
 
+// v9.6-a Unprivileged load store operations
+let Predicates = [HasLSUI] in {
+defm LDTXRW : LoadUnprivilegedLSUI<0b10, GPR32, "ldtxr">;
+defm LDTXRX : LoadUnprivilegedLSUI<0b11, GPR64, "ldtxr">;

CarolineConcatto wrote:

These instructions need an alias for ldrx for 32 and 64 bits.

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


[clang] [clang][bytecode] Start implementing __builtin_bit_cast (PR #112126)

2024-10-16 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Victory!

 1) Iterate composite fields backwards for big-endian targets
 2) Fix `BitcatBuffer::data()` pointing to the wrong byte if the number of 
bytes in the buffer is not a multiple of `sizeof(uint64_t)` (which is what 
`llvm::BitBuffer` uses internally) and we're on a big-endian host.
 3) Validate that all of this works on little-endian and big-endian hosts, with 
asan and ubsan enabled.



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


[clang] [clang][bytecode] Start implementing __builtin_bit_cast (PR #112126)

2024-10-16 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Also, I've removed the logic for tracking uninitialized/indeterminate bits for 
now since it can be added later.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -4660,6 +4746,21 @@ let Predicates = [HasLOR] in {
   def STLLRH0 : InstAlias<"stllrh\t$Rt, [$Rn, #0]",  (STLLRH   GPR32: $Rt, 
GPR64sp:$Rn)>;
 }
 
+// v9.6-a Unprivileged load store operations
+let Predicates = [HasLSUI] in {
+defm LDTXRW : LoadUnprivilegedLSUI<0b10, GPR32, "ldtxr">;
+defm LDTXRX : LoadUnprivilegedLSUI<0b11, GPR64, "ldtxr">;
+
+def LDATXRW : LoadExclusiveLSUI <0b10, 1, 1, GPR32, "ldatxr">;

CarolineConcatto wrote:

These instructions need an alias for ldaxr for 32 and 64 bits.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -4660,6 +4746,21 @@ let Predicates = [HasLOR] in {
   def STLLRH0 : InstAlias<"stllrh\t$Rt, [$Rn, #0]",  (STLLRH   GPR32: $Rt, 
GPR64sp:$Rn)>;
 }
 
+// v9.6-a Unprivileged load store operations
+let Predicates = [HasLSUI] in {
+defm LDTXRW : LoadUnprivilegedLSUI<0b10, GPR32, "ldtxr">;
+defm LDTXRX : LoadUnprivilegedLSUI<0b11, GPR64, "ldtxr">;
+
+def LDATXRW : LoadExclusiveLSUI <0b10, 1, 1, GPR32, "ldatxr">;
+def LDATXRX : LoadExclusiveLSUI <0b11, 1, 1, GPR64, "ldatxr">;
+
+defm STTXRW : StoreUnprivilegedLSUI<0b10, GPR32, "sttxr">;

CarolineConcatto wrote:

These instructions need an alias for STXR for 32 and 64 bits

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


[clang] [lldb] [llvm] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)

2024-10-16 Thread Nikita Popov via cfe-commits

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

>From 96795194fc79359363bac0423516da2a06733047 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Thu, 19 Sep 2024 17:27:13 +0200
Subject: [PATCH 1/5] apint only

---
 clang/lib/AST/ByteCode/IntegralAP.h   |  6 ++--
 clang/lib/CodeGen/CGVTT.cpp   |  5 +--
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  5 +--
 clang/lib/Parse/ParseInit.cpp |  4 ++-
 clang/lib/Sema/SemaExpr.cpp   |  7 ++--
 clang/lib/Sema/SemaOpenMP.cpp |  4 ++-
 lldb/source/Expression/DWARFExpression.cpp|  7 ++--
 llvm/include/llvm/ADT/APFixedPoint.h  |  4 ++-
 llvm/lib/Analysis/ConstantFolding.cpp |  3 +-
 llvm/lib/Analysis/Loads.cpp   |  6 ++--
 llvm/lib/Analysis/MemoryBuiltins.cpp  |  2 ++
 llvm/lib/Analysis/ScalarEvolution.cpp |  2 +-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |  3 +-
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp |  5 ++-
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  3 +-
 .../CodeGen/SelectionDAG/SelectionDAGISel.cpp |  8 +++--
 .../CodeGen/SelectionDAG/TargetLowering.cpp   |  8 +++--
 llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp  |  2 +-
 llvm/lib/IR/Constants.cpp |  4 ++-
 .../Target/AArch64/AArch64ISelLowering.cpp| 32 +--
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp|  3 +-
 .../Target/AMDGPU/SIShrinkInstructions.cpp|  4 +--
 .../lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  4 ++-
 .../Hexagon/HexagonConstPropagation.cpp   |  3 +-
 llvm/lib/Target/Hexagon/HexagonGenExtract.cpp |  2 +-
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |  4 ++-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  6 ++--
 llvm/lib/Transforms/IPO/ArgumentPromotion.cpp |  3 +-
 llvm/lib/Transforms/Utils/SimplifyCFG.cpp |  2 +-
 llvm/unittests/ADT/APFixedPointTest.cpp   |  9 +++---
 30 files changed, 99 insertions(+), 61 deletions(-)

diff --git a/clang/lib/AST/ByteCode/IntegralAP.h 
b/clang/lib/AST/ByteCode/IntegralAP.h
index a4d656433344b7..6ab3d09ec85d5b 100644
--- a/clang/lib/AST/ByteCode/IntegralAP.h
+++ b/clang/lib/AST/ByteCode/IntegralAP.h
@@ -61,7 +61,7 @@ template  class IntegralAP final {
 
   IntegralAP(APInt V) : V(V) {}
   /// Arbitrary value for uninitialized variables.
-  IntegralAP() : IntegralAP(-1, 3) {}
+  IntegralAP() : IntegralAP(Signed ? -1 : 7, 3) {}
 
   IntegralAP operator-() const { return IntegralAP(-V); }
   IntegralAP operator-(const IntegralAP &Other) const {
@@ -112,7 +112,9 @@ template  class IntegralAP final {
 
   template 
   static IntegralAP from(Integral I, unsigned BitWidth) {
-APInt Copy = APInt(BitWidth, static_cast(I), InputSigned);
+// TODO: Avoid implicit trunc?
+APInt Copy = APInt(BitWidth, static_cast(I), InputSigned,
+   /*implicitTrunc=*/true);
 
 return IntegralAP(Copy);
   }
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index 20bd2c2fc2c642..989a07d09d50ee 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -85,8 +85,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
  cast(VTable->getValueType())
  ->getElementType(AddressPoint.VTableIndex));
  unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex;
- llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true),
- llvm::APInt(32, VTableSize - Offset, true));
+ llvm::ConstantRange InRange(
+ llvm::APInt(32, (int)-Offset, true),
+ llvm::APInt(32, (int)(VTableSize - Offset), true));
  llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
  VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange);
 
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 75dab596e1b2c4..5bb0765cb0249c 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2099,8 +2099,9 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   unsigned VTableSize =
   ComponentSize * Layout.getVTableSize(AddressPoint.VTableIndex);
   unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex;
-  llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true),
-  llvm::APInt(32, VTableSize - Offset, true));
+  llvm::ConstantRange InRange(
+  llvm::APInt(32, (int)-Offset, true),
+  llvm::APInt(32, (int)(VTableSize - Offset), true));
   return llvm::ConstantExpr::getGetElementPtr(
   VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
 }
diff --git a/clang/lib/Parse/ParseInit.cpp b/clang/lib/Parse/ParseInit.cpp
index 0a9a359cdaf979..e7c8d79ac3 100644
--- a/clang/lib/Parse/ParseInit.cpp
+++ b/clang/lib/Parse/ParseInit.cpp
@@ -437,7 +437,9 @@ ExprResult Parser::createEmbedExpr() {
   SourceLocation StartLoc = ConsumeAnnotationToken();
   if (Data->BinaryDa

[clang] [lldb] [llvm] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)

2024-10-16 Thread Nikita Popov via cfe-commits


@@ -3600,8 +3600,11 @@ ExprResult Sema::ActOnCharacterConstant(const Token 
&Tok, Scope *UDLScope) {
 
 ExprResult Sema::ActOnIntegerConstant(SourceLocation Loc, uint64_t Val) {
   unsigned IntSize = Context.getTargetInfo().getIntWidth();
-  return IntegerLiteral::Create(Context, llvm::APInt(IntSize, Val),
-Context.IntTy, Loc);
+  // TODO: Avoid implicit trunc?
+  return IntegerLiteral::Create(
+  Context,
+  llvm::APInt(IntSize, Val, /*isSigned=*/false, /*implicitTrunc=*/true),

nikic wrote:

I've changed this to set isSigned=true and updated the signature to use int64_t 
instead of uint64_t to clarify that a signed value is expected.

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


[clang] [lldb] [llvm] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)

2024-10-16 Thread Nikita Popov via cfe-commits


@@ -437,7 +437,9 @@ ExprResult Parser::createEmbedExpr() {
   SourceLocation StartLoc = ConsumeAnnotationToken();
   if (Data->BinaryData.size() == 1) {
 Res = IntegerLiteral::Create(Context,
- llvm::APInt(CHAR_BIT, 
Data->BinaryData.back()),
+ llvm::APInt(CHAR_BIT, Data->BinaryData.back(),

nikic wrote:

Done, though I used `(unsigned char)` to match `CHAR_BIT` more closely.

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


[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)

2024-10-16 Thread via cfe-commits


@@ -446,8 +474,10 @@ define amdgpu_kernel void @add_i32_uniform(ptr 
addrspace(1) %out, ptr addrspace(
 ; GFX11W64-NEXT:; implicit-def: $vgpr1
 ; GFX11W64-NEXT:s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | 
instid1(VALU_DEP_1)
 ; GFX11W64-NEXT:v_mbcnt_hi_u32_b32 v0, s5, v0
-; GFX11W64-NEXT:v_cmpx_eq_u32_e32 0, v0
-; GFX11W64-NEXT:s_cbranch_execz .LBB1_2
+; GFX11W64-NEXT:v_cmp_eq_u32_e32 vcc, 0, v0
+; GFX11W64-NEXT:s_cmp_lg_u64 vcc, 0
+; GFX11W64-NEXT:s_cmov_b64 exec, vcc
+; GFX11W64-NEXT:s_cbranch_scc0 .LBB1_2

alex-t wrote:

No, we cannot.   S_AND_SAVEEXEC changes the EXEC unconditionally.
The idea is that we only change the exec if we are going to execute "Then" 
block but leave it unchanged for Flow block. All further lowering is based on 
this assumption.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread via cfe-commits


@@ -4660,6 +4746,21 @@ let Predicates = [HasLOR] in {
   def STLLRH0 : InstAlias<"stllrh\t$Rt, [$Rn, #0]",  (STLLRH   GPR32: $Rt, 
GPR64sp:$Rn)>;
 }
 
+// v9.6-a Unprivileged load store operations
+let Predicates = [HasLSUI] in {
+defm LDTXRW : LoadUnprivilegedLSUI<0b10, GPR32, "ldtxr">;
+defm LDTXRX : LoadUnprivilegedLSUI<0b11, GPR64, "ldtxr">;
+
+def LDATXRW : LoadExclusiveLSUI <0b10, 1, 1, GPR32, "ldatxr">;
+def LDATXRX : LoadExclusiveLSUI <0b11, 1, 1, GPR64, "ldatxr">;
+
+defm STTXRW : StoreUnprivilegedLSUI<0b10, GPR32, "sttxr">;
+defm STTXRX : StoreUnprivilegedLSUI<0b11, GPR64, "sttxr">;
+
+def STLTXRW : StoreExclusiveLSUI<0b10, 0, 1, GPR32, "stltxr">;

CarolineConcatto wrote:

These instructions need for STLXR, 32 and 64 bits

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


[clang] [llvm] [NFC] Replace more DenseMaps with SmallDenseMaps (PR #111836)

2024-10-16 Thread Nikita Popov via cfe-commits


@@ -268,7 +268,7 @@ struct UniqueVirtualMethod {
 /// subobject in which that virtual function occurs).
 class OverridingMethods {
   using ValuesT = SmallVector;
-  using MapType = llvm::MapVector;
+  using MapType = llvm::SmallMapVector;

nikic wrote:

It looks like this is nested inside another MapVector. I'd drop this one if it 
doesn't have significant effect.

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


[clang] [llvm] [NFC] Replace more DenseMaps with SmallDenseMaps (PR #111836)

2024-10-16 Thread Nikita Popov via cfe-commits


@@ -51,7 +51,7 @@ class ConstraintSystem {
 
   /// A map of variables (IR values) to their corresponding index in the
   /// constraint system.
-  DenseMap Value2Index;
+  SmallDenseMap Value2Index;

nikic wrote:

I'd add a using/typedef for this one, especially as it needs to be synchronized 
with ConstraintElimination.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jonathan Thackray via cfe-commits


@@ -0,0 +1,14 @@
+# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
+// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=+occmo 
-mattr=+mte < %s | FileCheck %s

jthackray wrote:

I think these tests should also check instructions are rejected with 
`-mattr=+nooccmo`

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Jonathan Thackray via cfe-commits


@@ -0,0 +1,12 @@
+# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
+// RUN: llvm-mc -triple aarch64 -show-encoding -mattr=+pcdphint %s | FileCheck 
%s

jthackray wrote:

I think these tests should also check the instructions are rejected with 
`-mattr=+nopcdphint`

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


[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)

2024-10-16 Thread via cfe-commits


@@ -936,19 +978,20 @@ define amdgpu_kernel void @add_i32_varying_vdata(ptr 
addrspace(1) %out, ptr addr
 ; GFX12W32-NEXT:s_cbranch_scc1 .LBB2_1
 ; GFX12W32-NEXT:  ; %bb.2: ; %ComputeEnd
 ; GFX12W32-NEXT:v_mbcnt_lo_u32_b32 v1, exec_lo, 0
-; GFX12W32-NEXT:s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | 
instid1(SALU_CYCLE_1)
+; GFX12W32-NEXT:s_delay_alu instid0(VALU_DEP_1)
 ; GFX12W32-NEXT:v_cmp_eq_u32_e32 vcc_lo, 0, v1
 ; GFX12W32-NEXT:; implicit-def: $vgpr1
-; GFX12W32-NEXT:s_and_saveexec_b32 s1, vcc_lo
-; GFX12W32-NEXT:s_xor_b32 s1, exec_lo, s1
-; GFX12W32-NEXT:s_cbranch_execz .LBB2_4
+; GFX12W32-NEXT:s_xor_b32 s1, vcc_lo, exec_lo
+; GFX12W32-NEXT:s_cmp_lg_u32 vcc_lo, 0
+; GFX12W32-NEXT:s_cmov_b32 exec_lo, vcc_lo
+; GFX12W32-NEXT:s_cbranch_scc0 .LBB2_4

alex-t wrote:

Won't work for same reason as above :(

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


[clang] [OpenCL] Restore addrspacecast for pipe builtins and update test (PR #112514)

2024-10-16 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh created 
https://github.com/llvm/llvm-project/pull/112514

Commit 84ee629bc515 ("clang: Remove some pointer bitcasts (#112324)", 
2024-10-15) triggered some "Call parameter type does not match function 
signature!" errors when using the OpenCL pipe builtin functions under the spir 
triple, due to a missing addrspacecast.

This would have been caught by the pipe_builtin.cl test if that had used the 
`spir-unknown-unknown` triple, so upgrade the test to use that triple.

>From a9a0d65b3fe220781dcba9dd2f124587c1aeb20f Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Wed, 16 Oct 2024 11:20:17 +0100
Subject: [PATCH] [OpenCL] Restore addrspacecast for pipe builtins and update
 test

Commit 84ee629bc515 ("clang: Remove some pointer bitcasts (#112324)",
2024-10-15) triggered some "Call parameter type does not match
function signature!" errors when using the OpenCL pipe builtin
functions under the spir triple, due to a missing addrspacecast.

This would have been caught by the pipe_builtin.cl test if that had
used the `spir-unknown-unknown` triple, so upgrade the test to use
that triple.
---
 clang/lib/CodeGen/CGBuiltin.cpp  |  3 +-
 clang/test/CodeGenOpenCL/pipe_builtin.cl | 44 +++-
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 12f99d9f1178a9..f6d7db2c204c12 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5657,13 +5657,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 *Arg3 = EmitScalarExpr(E->getArg(3));
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
+  Value *ACast = Builder.CreateAddrSpaceCast(Arg3, I8PTy);
   // We know the third argument is an integer type, but we may need to cast
   // it to i32.
   if (Arg2->getType() != Int32Ty)
 Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty);
   return RValue::get(
   EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name),
-  {Arg0, Arg1, Arg2, Arg3, PacketSize, PacketAlign}));
+  {Arg0, Arg1, Arg2, ACast, PacketSize, PacketAlign}));
 }
   }
   // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write
diff --git a/clang/test/CodeGenOpenCL/pipe_builtin.cl 
b/clang/test/CodeGenOpenCL/pipe_builtin.cl
index c59f63bab6a458..4e39661f3a3e12 100644
--- a/clang/test/CodeGenOpenCL/pipe_builtin.cl
+++ b/clang/test/CodeGenOpenCL/pipe_builtin.cl
@@ -1,69 +1,67 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
-// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple
-// above to support OpenCL in the MS C++ ABI.
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
 
 void test1(read_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__read_pipe_2(ptr %{{.*}}, ptr %{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__read_pipe_2(target("spirv.Pipe", 0) %{{.*}}, 
ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   read_pipe(p, ptr);
-  // CHECK: call ptr @__reserve_read_pipe(ptr %{{.*}}, i32 {{.*}}, i32 4, i32 
4)
+  // CHECK: call spir_func target("spirv.ReserveId") 
@__reserve_read_pipe(target("spirv.Pipe", 0) %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_read_pipe(p, 2);
-  // CHECK: call i32 @__read_pipe_4(ptr %{{.*}}, ptr %{{.*}}, i32 {{.*}}, ptr 
%{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__read_pipe_4(target("spirv.Pipe", 0) %{{.*}}, 
ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   read_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_read_pipe(ptr %{{.*}}, ptr %{{.*}}, i32 4, i32 
4)
+  // CHECK: call spir_func void @__commit_read_pipe(target("spirv.Pipe", 0) 
%{{.*}}, target("spirv.ReserveId") %{{.*}}, i32 4, i32 4)
   commit_read_pipe(p, rid);
 }
 
 void test2(write_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__write_pipe_2(ptr %{{.*}}, ptr %{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__write_pipe_2(target("spirv.Pipe", 1) 
%{{.*}}, ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   write_pipe(p, ptr);
-  // CHECK: call ptr @__reserve_write_pipe(ptr %{{.*}}, i32 {{.*}}, i32 4, i32 
4)
+  // CHECK: call spir_func target("spirv.ReserveId") 
@__reserve_write_pipe(target("spirv.Pipe", 1) %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_write_pipe(p, 2);
-  // CHECK: call i32 @__write_pipe_4(ptr %{{.*}}, ptr %{{.*}}, i32 {{.*}}, ptr 
%{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__write_pipe_4(target("spirv.Pipe", 1) 
%{{.*}}, ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   write_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_write_pipe(ptr %{{.*}}, ptr %{{.*}}, i32 4, 

[clang] [OpenCL] Restore addrspacecast for pipe builtins and update test (PR #112514)

2024-10-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Sven van Haastregt (svenvh)


Changes

Commit 84ee629bc515 ("clang: Remove some pointer bitcasts (#112324)", 
2024-10-15) triggered some "Call parameter type does not match function 
signature!" errors when using the OpenCL pipe builtin functions under the spir 
triple, due to a missing addrspacecast.

This would have been caught by the pipe_builtin.cl test if that had used the 
`spir-unknown-unknown` triple, so upgrade the test to use that triple.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2-1) 
- (modified) clang/test/CodeGenOpenCL/pipe_builtin.cl (+21-23) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 12f99d9f1178a9..f6d7db2c204c12 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5657,13 +5657,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 *Arg3 = EmitScalarExpr(E->getArg(3));
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
+  Value *ACast = Builder.CreateAddrSpaceCast(Arg3, I8PTy);
   // We know the third argument is an integer type, but we may need to cast
   // it to i32.
   if (Arg2->getType() != Int32Ty)
 Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty);
   return RValue::get(
   EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name),
-  {Arg0, Arg1, Arg2, Arg3, PacketSize, PacketAlign}));
+  {Arg0, Arg1, Arg2, ACast, PacketSize, PacketAlign}));
 }
   }
   // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write
diff --git a/clang/test/CodeGenOpenCL/pipe_builtin.cl 
b/clang/test/CodeGenOpenCL/pipe_builtin.cl
index c59f63bab6a458..4e39661f3a3e12 100644
--- a/clang/test/CodeGenOpenCL/pipe_builtin.cl
+++ b/clang/test/CodeGenOpenCL/pipe_builtin.cl
@@ -1,69 +1,67 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
-// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple
-// above to support OpenCL in the MS C++ ABI.
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
 
 void test1(read_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__read_pipe_2(ptr %{{.*}}, ptr %{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__read_pipe_2(target("spirv.Pipe", 0) %{{.*}}, 
ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   read_pipe(p, ptr);
-  // CHECK: call ptr @__reserve_read_pipe(ptr %{{.*}}, i32 {{.*}}, i32 4, i32 
4)
+  // CHECK: call spir_func target("spirv.ReserveId") 
@__reserve_read_pipe(target("spirv.Pipe", 0) %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_read_pipe(p, 2);
-  // CHECK: call i32 @__read_pipe_4(ptr %{{.*}}, ptr %{{.*}}, i32 {{.*}}, ptr 
%{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__read_pipe_4(target("spirv.Pipe", 0) %{{.*}}, 
ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   read_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_read_pipe(ptr %{{.*}}, ptr %{{.*}}, i32 4, i32 
4)
+  // CHECK: call spir_func void @__commit_read_pipe(target("spirv.Pipe", 0) 
%{{.*}}, target("spirv.ReserveId") %{{.*}}, i32 4, i32 4)
   commit_read_pipe(p, rid);
 }
 
 void test2(write_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__write_pipe_2(ptr %{{.*}}, ptr %{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__write_pipe_2(target("spirv.Pipe", 1) 
%{{.*}}, ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   write_pipe(p, ptr);
-  // CHECK: call ptr @__reserve_write_pipe(ptr %{{.*}}, i32 {{.*}}, i32 4, i32 
4)
+  // CHECK: call spir_func target("spirv.ReserveId") 
@__reserve_write_pipe(target("spirv.Pipe", 1) %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_write_pipe(p, 2);
-  // CHECK: call i32 @__write_pipe_4(ptr %{{.*}}, ptr %{{.*}}, i32 {{.*}}, ptr 
%{{.*}}, i32 4, i32 4)
+  // CHECK: call spir_func i32 @__write_pipe_4(target("spirv.Pipe", 1) 
%{{.*}}, ptr addrspace(4) %{{.*}}, i32 4, i32 4)
   write_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_write_pipe(ptr %{{.*}}, ptr %{{.*}}, i32 4, 
i32 4)
+  // CHECK: call spir_func void @__commit_write_pipe(target("spirv.Pipe", 1) 
%{{.*}}, target("spirv.ReserveId") %{{.*}}, i32 4, i32 4)
   commit_write_pipe(p, rid);
 }
 
 void test3(read_only pipe int p, global int *ptr) {
-  // CHECK: call ptr @__work_group_reserve_read_pipe(ptr %{{.*}}, i32 {{.*}}, 
i32 4, i32 4)
+  // CHECK: call spir_func target("spirv.ReserveId") 
@__work_group_reserve_read_pipe(target("spirv.Pipe", 0) %{{.*}}, i32 {{.*}}, 
i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_read_pipe(p, 2);
-  // CHEC

[clang] [clang][bytecode] Implement the constexpr built-in abs function. (PR #112459)

2024-10-16 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/112459

>From dfa1585af3f080987cbd15830c45c34bfecc1fca Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 16 Oct 2024 01:18:13 +
Subject: [PATCH 1/7] implement constexpr builtin {l}abs

---
 clang/include/clang/Basic/Builtins.td |  1 +
 clang/lib/AST/ExprConstant.cpp| 11 +++
 clang/test/AST/ByteCode/builtin-functions.cpp |  9 +
 3 files changed, 21 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index bda8a48be92bda..e1b4d5b1fdc0a5 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -2714,6 +2714,7 @@ def Abs : IntMathTemplate, LibBuiltin<"stdlib.h"> {
   let Attributes = [NoThrow, Const];
   let Prototype = "T(T)";
   let AddBuiltinPrefixedAlias = 1;
+  let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
 }
 
 def Calloc : LibBuiltin<"stdlib.h"> {
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 52a7f5778ce6d2..69539a7f03feba 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13055,6 +13055,17 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.popcount() % 2, E);
   }
 
+  case Builtin::BI__builtin_abs:
+  case Builtin::BI__builtin_labs:
+  case Builtin::BI__builtin_llabs: {
+APSInt Val;
+if (!EvaluateInteger(E->getArg(0), Val, Info))
+  return false;
+if (Val.isNegative())
+  Val.negate();
+return Success(Val, E);
+  }
+
   case Builtin::BI__builtin_popcount:
   case Builtin::BI__builtin_popcountl:
   case Builtin::BI__builtin_popcountll:
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 450ff5671314db..46e5b0579bd575 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -265,6 +265,15 @@ namespace fpclassify {
   char classify_subnorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1.0e-38f)];
 }
 
+namespace abs {
+static_assert(__builtin_abs(14) == 14, "");
+static_assert(__builtin_labs(14L) == 14L, "");
+static_assert(__builtin_llabs(14LL) == 14LL, "");
+static_assert(__builtin_abs(-14) == 14, "");
+static_assert(__builtin_labs(-14L) == 14L, "");
+static_assert(__builtin_llabs(-14LL) == 14LL, "");
+} // namespace abs
+
 namespace fabs {
   static_assert(__builtin_fabs(-14.0) == 14.0, "");
 }

>From 52e1d070b392ea4651acf5f7f984a1defb035459 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 16 Oct 2024 12:32:37 +0800
Subject: [PATCH 2/7] Update InterpBuiltin.cpp

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 65c7b4e5306d72..1e1a75e5514aec 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -563,6 +563,17 @@ static bool interp__builtin_fabs(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_abs(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *Func,
+const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  if (Val.isNegative())
+Val.negate();
+  pushInteger(S, Val, Call->getType());
+  return true;
+}
+
 static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
  const InterpFrame *Frame,
  const Function *Func,
@@ -1808,6 +1819,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_abs:
+  case Builtin::BI__builtin_labs:
+  case Builtin::BI__builtin_llabs:
+  if (!interp__builtin_abs(S, OpPC, Frame, F, Call))
+return false;
+  break;
+
   case Builtin::BI__builtin_popcount:
   case Builtin::BI__builtin_popcountl:
   case Builtin::BI__builtin_popcountll:

>From 227193529178a1c1484c0da42a06289a26c75114 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 16 Oct 2024 12:33:29 +0800
Subject: [PATCH 3/7] Update ExprConstant.cpp

---
 clang/lib/AST/ExprConstant.cpp | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 69539a7f03feba..52a7f5778ce6d2 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13055,17 +13055,6 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.popcount() % 2, E);
   }
 
-  case Builtin::BI__builtin_abs:
-  case Builtin::BI__builtin_labs:
-  case Builtin::BI__builtin_llabs: {
-APSInt Val;
-if (!EvaluateInteger(E->getArg(0), Val, Info))
-  return false;
-if (Val.isNegative())
-  Val.nega

[clang] [OpenCL] Restore addrspacecast for pipe builtins and update test (PR #112514)

2024-10-16 Thread Matt Arsenault via cfe-commits


@@ -1,69 +1,67 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
-// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple

arsenm wrote:

Test both run lines?

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


[clang] [lldb] [llvm] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)

2024-10-16 Thread Nikita Popov via cfe-commits

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

>From 96795194fc79359363bac0423516da2a06733047 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Thu, 19 Sep 2024 17:27:13 +0200
Subject: [PATCH 1/6] apint only

---
 clang/lib/AST/ByteCode/IntegralAP.h   |  6 ++--
 clang/lib/CodeGen/CGVTT.cpp   |  5 +--
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  5 +--
 clang/lib/Parse/ParseInit.cpp |  4 ++-
 clang/lib/Sema/SemaExpr.cpp   |  7 ++--
 clang/lib/Sema/SemaOpenMP.cpp |  4 ++-
 lldb/source/Expression/DWARFExpression.cpp|  7 ++--
 llvm/include/llvm/ADT/APFixedPoint.h  |  4 ++-
 llvm/lib/Analysis/ConstantFolding.cpp |  3 +-
 llvm/lib/Analysis/Loads.cpp   |  6 ++--
 llvm/lib/Analysis/MemoryBuiltins.cpp  |  2 ++
 llvm/lib/Analysis/ScalarEvolution.cpp |  2 +-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |  3 +-
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp |  5 ++-
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  3 +-
 .../CodeGen/SelectionDAG/SelectionDAGISel.cpp |  8 +++--
 .../CodeGen/SelectionDAG/TargetLowering.cpp   |  8 +++--
 llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp  |  2 +-
 llvm/lib/IR/Constants.cpp |  4 ++-
 .../Target/AArch64/AArch64ISelLowering.cpp| 32 +--
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp|  3 +-
 .../Target/AMDGPU/SIShrinkInstructions.cpp|  4 +--
 .../lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  4 ++-
 .../Hexagon/HexagonConstPropagation.cpp   |  3 +-
 llvm/lib/Target/Hexagon/HexagonGenExtract.cpp |  2 +-
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |  4 ++-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  6 ++--
 llvm/lib/Transforms/IPO/ArgumentPromotion.cpp |  3 +-
 llvm/lib/Transforms/Utils/SimplifyCFG.cpp |  2 +-
 llvm/unittests/ADT/APFixedPointTest.cpp   |  9 +++---
 30 files changed, 99 insertions(+), 61 deletions(-)

diff --git a/clang/lib/AST/ByteCode/IntegralAP.h 
b/clang/lib/AST/ByteCode/IntegralAP.h
index a4d656433344b7..6ab3d09ec85d5b 100644
--- a/clang/lib/AST/ByteCode/IntegralAP.h
+++ b/clang/lib/AST/ByteCode/IntegralAP.h
@@ -61,7 +61,7 @@ template  class IntegralAP final {
 
   IntegralAP(APInt V) : V(V) {}
   /// Arbitrary value for uninitialized variables.
-  IntegralAP() : IntegralAP(-1, 3) {}
+  IntegralAP() : IntegralAP(Signed ? -1 : 7, 3) {}
 
   IntegralAP operator-() const { return IntegralAP(-V); }
   IntegralAP operator-(const IntegralAP &Other) const {
@@ -112,7 +112,9 @@ template  class IntegralAP final {
 
   template 
   static IntegralAP from(Integral I, unsigned BitWidth) {
-APInt Copy = APInt(BitWidth, static_cast(I), InputSigned);
+// TODO: Avoid implicit trunc?
+APInt Copy = APInt(BitWidth, static_cast(I), InputSigned,
+   /*implicitTrunc=*/true);
 
 return IntegralAP(Copy);
   }
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index 20bd2c2fc2c642..989a07d09d50ee 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -85,8 +85,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
  cast(VTable->getValueType())
  ->getElementType(AddressPoint.VTableIndex));
  unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex;
- llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true),
- llvm::APInt(32, VTableSize - Offset, true));
+ llvm::ConstantRange InRange(
+ llvm::APInt(32, (int)-Offset, true),
+ llvm::APInt(32, (int)(VTableSize - Offset), true));
  llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
  VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange);
 
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 75dab596e1b2c4..5bb0765cb0249c 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2099,8 +2099,9 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   unsigned VTableSize =
   ComponentSize * Layout.getVTableSize(AddressPoint.VTableIndex);
   unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex;
-  llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true),
-  llvm::APInt(32, VTableSize - Offset, true));
+  llvm::ConstantRange InRange(
+  llvm::APInt(32, (int)-Offset, true),
+  llvm::APInt(32, (int)(VTableSize - Offset), true));
   return llvm::ConstantExpr::getGetElementPtr(
   VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
 }
diff --git a/clang/lib/Parse/ParseInit.cpp b/clang/lib/Parse/ParseInit.cpp
index 0a9a359cdaf979..e7c8d79ac3 100644
--- a/clang/lib/Parse/ParseInit.cpp
+++ b/clang/lib/Parse/ParseInit.cpp
@@ -437,7 +437,9 @@ ExprResult Parser::createEmbedExpr() {
   SourceLocation StartLoc = ConsumeAnnotationToken();
   if (Data->BinaryDa

[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)

2024-10-16 Thread via cfe-commits

alex-t wrote:

> > Although, revisiting this now, I still don't understand why they decided to 
> > include ALL spill opcodes in the prologue, but not only the SGPR spills? 
> > Clearly, none of the VGPR reloads really belong to the prologue.
> > At a first glance, changing the isSpill(opcode) to isSGPRSpill(opcode) in 
> > the snippet below would solve the initial case. ` return 
> > IsNullOrVectorRegister && (isSpill(Opcode) || (!MI.isTerminator() && Opcode 
> > != AMDGPU::COPY && MI.modifiesRegister(AMDGPU::EXEC, &RI))); }`
> > I need to look at this a bit more. I am sure they would have done this if 
> > such a simple change had solved the problem.
> 
> I like this change - it fixes the problem I reported in #109294.

It fixes the problem but requires us to consider WWM reloads as prologue 
instructions. Any VGPR reload starts a new live range and possibly introduces 
interference. CD's reply here 
(https://github.com/llvm/llvm-project/pull/111496#issuecomment-2411434387) made 
me hope that it would work. However, I would like to see the corresponding MIR 
test as proof.  

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


[clang] [OpenCL] Restore addrspacecast for pipe builtins and update test (PR #112514)

2024-10-16 Thread Sven van Haastregt via cfe-commits


@@ -1,69 +1,67 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
-// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple

svenvh wrote:

Surely I can add the old run line back, but would that bring any value?  
Preservation of the pipe access qualifiers is not tested with the old run line 
for example.

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features memtag and memtag2. (PR #112511)

2024-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Alexandros Lamprineas (labrinea)


Changes

If we split these features in the compiler (see relevant pull request 
https://github.com/llvm/llvm-project/pull/109299), we would only be able to 
hand-write a 'memtag2' version using inline assembly since the compiler cannot 
generate the instructions that become available with FEAT_MTE2. However these 
instructions only work at Exception Level 1, so they would be unusable since 
FMV is a user space facility. I am therefore unifying them.

Approved in ACLE as https://github.com/ARM-software/acle/pull/351

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


12 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+1-1) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+1-1) 
- (modified) clang/test/CodeGen/aarch64-cpu-supports-target.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-cpu-supports.c (+10-5) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+3-6) 
- (modified) clang/test/CodeGen/attr-target-clones-aarch64.c (+10-10) 
- (modified) clang/test/CodeGen/attr-target-version.c (+8-8) 
- (modified) clang/test/Sema/attr-target-clones-aarch64.c (+1-1) 
- (modified) compiler-rt/lib/builtins/cpu_model/AArch64CPUFeatures.inc (+1-1) 
- (modified) compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc (+1-3) 
- (modified) llvm/include/llvm/TargetParser/AArch64CPUFeatures.inc (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-2) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b1512e22ee2dd4..ee8126cadae232 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2669,7 +2669,7 @@ sign. For example:
 
   .. code-block:: c++
 
-__attribute__((target_clones("sha2+memtag2", "fcma+sve2-pmull128")))
+__attribute__((target_clones("sha2+memtag", "fcma+sve2-pmull128")))
 void foo() {}
 
 For every multiversioned function a ``default`` (fallback) implementation
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index b96fab978a3fcb..3dbba2b4d25bd6 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -784,7 +784,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("sme-fa64", HasSMEFA64)
   .Case("sme-f16f16", HasSMEF16F16)
   .Case("sme-b16b16", HasSMEB16B16)
-  .Cases("memtag", "memtag2", HasMTE)
+  .Case("memtag", HasMTE)
   .Case("sb", HasSB)
   .Case("predres", HasPredRes)
   .Cases("ssbs", "ssbs2", HasSSBS)
diff --git a/clang/test/CodeGen/aarch64-cpu-supports-target.c 
b/clang/test/CodeGen/aarch64-cpu-supports-target.c
index 28187bcf745331..5186cab92a921d 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports-target.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports-target.c
@@ -17,7 +17,7 @@ int check_all_feature() {
 return 7;
   else if (__builtin_cpu_supports("sve2-bitperm+sve2-sha3+sve2-sm4"))
 return 8;
-  else if (__builtin_cpu_supports("sme+memtag+memtag2+memtag3+sb"))
+  else if (__builtin_cpu_supports("sme+memtag+memtag3+sb"))
 return 9;
   else if (__builtin_cpu_supports("predres+ssbs+ssbs2+bti+ls64+ls64_v"))
 return 10;
diff --git a/clang/test/CodeGen/aarch64-cpu-supports.c 
b/clang/test/CodeGen/aarch64-cpu-supports.c
index 823bf369df6fcc..dc96c929fdf4cb 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports.c
@@ -1,9 +1,10 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --version 2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --global-value-regex ".*"
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 
+//.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK-LABEL: define dso_local i32 @main
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+//.
+// CHECK-LABEL: @main(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i32 0, ptr [[RETVAL]], align 4
@@ -17,8 +18,8 @@
 // CHECK-NEXT:br label [[RETURN:%.*]]
 // CHECK:   if.end:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 9070970929152
-// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 9070970929152
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 17867063951360
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17867063951360
 // CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
 // CHECK-NEXT:br i1 [[TMP7]], label [[IF_THEN1:%.*]], label [[IF_END2:%.*]]
 // CHECK:   if.then1:
@@ -60,3 +61,7 @@ int main(void) {
 
   return 0;
 }
+//.
+// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}c

[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features memtag and memtag2. (PR #112511)

2024-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexandros Lamprineas (labrinea)


Changes

If we split these features in the compiler (see relevant pull request 
https://github.com/llvm/llvm-project/pull/109299), we would only be able to 
hand-write a 'memtag2' version using inline assembly since the compiler cannot 
generate the instructions that become available with FEAT_MTE2. However these 
instructions only work at Exception Level 1, so they would be unusable since 
FMV is a user space facility. I am therefore unifying them.

Approved in ACLE as https://github.com/ARM-software/acle/pull/351

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


12 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+1-1) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+1-1) 
- (modified) clang/test/CodeGen/aarch64-cpu-supports-target.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-cpu-supports.c (+10-5) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+3-6) 
- (modified) clang/test/CodeGen/attr-target-clones-aarch64.c (+10-10) 
- (modified) clang/test/CodeGen/attr-target-version.c (+8-8) 
- (modified) clang/test/Sema/attr-target-clones-aarch64.c (+1-1) 
- (modified) compiler-rt/lib/builtins/cpu_model/AArch64CPUFeatures.inc (+1-1) 
- (modified) compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc (+1-3) 
- (modified) llvm/include/llvm/TargetParser/AArch64CPUFeatures.inc (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-2) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b1512e22ee2dd4..ee8126cadae232 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2669,7 +2669,7 @@ sign. For example:
 
   .. code-block:: c++
 
-__attribute__((target_clones("sha2+memtag2", "fcma+sve2-pmull128")))
+__attribute__((target_clones("sha2+memtag", "fcma+sve2-pmull128")))
 void foo() {}
 
 For every multiversioned function a ``default`` (fallback) implementation
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index b96fab978a3fcb..3dbba2b4d25bd6 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -784,7 +784,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("sme-fa64", HasSMEFA64)
   .Case("sme-f16f16", HasSMEF16F16)
   .Case("sme-b16b16", HasSMEB16B16)
-  .Cases("memtag", "memtag2", HasMTE)
+  .Case("memtag", HasMTE)
   .Case("sb", HasSB)
   .Case("predres", HasPredRes)
   .Cases("ssbs", "ssbs2", HasSSBS)
diff --git a/clang/test/CodeGen/aarch64-cpu-supports-target.c 
b/clang/test/CodeGen/aarch64-cpu-supports-target.c
index 28187bcf745331..5186cab92a921d 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports-target.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports-target.c
@@ -17,7 +17,7 @@ int check_all_feature() {
 return 7;
   else if (__builtin_cpu_supports("sve2-bitperm+sve2-sha3+sve2-sm4"))
 return 8;
-  else if (__builtin_cpu_supports("sme+memtag+memtag2+memtag3+sb"))
+  else if (__builtin_cpu_supports("sme+memtag+memtag3+sb"))
 return 9;
   else if (__builtin_cpu_supports("predres+ssbs+ssbs2+bti+ls64+ls64_v"))
 return 10;
diff --git a/clang/test/CodeGen/aarch64-cpu-supports.c 
b/clang/test/CodeGen/aarch64-cpu-supports.c
index 823bf369df6fcc..dc96c929fdf4cb 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports.c
@@ -1,9 +1,10 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --version 2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --global-value-regex ".*"
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 
+//.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK-LABEL: define dso_local i32 @main
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+//.
+// CHECK-LABEL: @main(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i32 0, ptr [[RETVAL]], align 4
@@ -17,8 +18,8 @@
 // CHECK-NEXT:br label [[RETURN:%.*]]
 // CHECK:   if.end:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 9070970929152
-// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 9070970929152
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 17867063951360
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17867063951360
 // CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
 // CHECK-NEXT:br i1 [[TMP7]], label [[IF_THEN1:%.*]], label [[IF_END2:%.*]]
 // CHECK:   if.then1:
@@ -60,3 +61,7 @@ int main(void) {
 
   return 0;
 }
+//.
+// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang versi

[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features memtag and memtag2. (PR #112511)

2024-10-16 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/112511

If we split these features in the compiler (see relevant pull request 
https://github.com/llvm/llvm-project/pull/109299), we would only be able to 
hand-write a 'memtag2' version using inline assembly since the compiler cannot 
generate the instructions that become available with FEAT_MTE2. However these 
instructions only work at Exception Level 1, so they would be unusable since 
FMV is a user space facility. I am therefore unifying them.

Approved in ACLE as https://github.com/ARM-software/acle/pull/351

>From ae0d1f894f15d0af299210bb617dbaf905797a39 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 15 Oct 2024 17:43:25 +0100
Subject: [PATCH] [FMV][AArch64] Unify features memtag and memtag2.

If we split these features in the compiler (see relevant pull request
https://github.com/llvm/llvm-project/pull/109299), we would only be able
to hand-write a 'memtag2' version using inline assembly since the compiler
cannot generate the instructions that become available with FEAT_MTE2.
However these instructions only work at Exception Level 1, so they would
be unusable since FMV is a user space facility. I am therefore unifying
them.

Approved in ACLE as https://github.com/ARM-software/acle/pull/351
---
 clang/include/clang/Basic/AttrDocs.td |  2 +-
 clang/lib/Basic/Targets/AArch64.cpp   |  2 +-
 .../CodeGen/aarch64-cpu-supports-target.c |  2 +-
 clang/test/CodeGen/aarch64-cpu-supports.c | 15 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  9 +++--
 .../test/CodeGen/attr-target-clones-aarch64.c | 20 +--
 clang/test/CodeGen/attr-target-version.c  | 16 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 .../builtins/cpu_model/AArch64CPUFeatures.inc |  2 +-
 .../builtins/cpu_model/aarch64/fmv/mrs.inc|  4 +---
 .../llvm/TargetParser/AArch64CPUFeatures.inc  |  2 +-
 llvm/lib/Target/AArch64/AArch64FMV.td |  3 +--
 12 files changed, 39 insertions(+), 40 deletions(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b1512e22ee2dd4..ee8126cadae232 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2669,7 +2669,7 @@ sign. For example:
 
   .. code-block:: c++
 
-__attribute__((target_clones("sha2+memtag2", "fcma+sve2-pmull128")))
+__attribute__((target_clones("sha2+memtag", "fcma+sve2-pmull128")))
 void foo() {}
 
 For every multiversioned function a ``default`` (fallback) implementation
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index b96fab978a3fcb..3dbba2b4d25bd6 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -784,7 +784,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("sme-fa64", HasSMEFA64)
   .Case("sme-f16f16", HasSMEF16F16)
   .Case("sme-b16b16", HasSMEB16B16)
-  .Cases("memtag", "memtag2", HasMTE)
+  .Case("memtag", HasMTE)
   .Case("sb", HasSB)
   .Case("predres", HasPredRes)
   .Cases("ssbs", "ssbs2", HasSSBS)
diff --git a/clang/test/CodeGen/aarch64-cpu-supports-target.c 
b/clang/test/CodeGen/aarch64-cpu-supports-target.c
index 28187bcf745331..5186cab92a921d 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports-target.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports-target.c
@@ -17,7 +17,7 @@ int check_all_feature() {
 return 7;
   else if (__builtin_cpu_supports("sve2-bitperm+sve2-sha3+sve2-sm4"))
 return 8;
-  else if (__builtin_cpu_supports("sme+memtag+memtag2+memtag3+sb"))
+  else if (__builtin_cpu_supports("sme+memtag+memtag3+sb"))
 return 9;
   else if (__builtin_cpu_supports("predres+ssbs+ssbs2+bti+ls64+ls64_v"))
 return 10;
diff --git a/clang/test/CodeGen/aarch64-cpu-supports.c 
b/clang/test/CodeGen/aarch64-cpu-supports.c
index 823bf369df6fcc..dc96c929fdf4cb 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports.c
@@ -1,9 +1,10 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --version 2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --global-value-regex ".*"
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 
+//.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK-LABEL: define dso_local i32 @main
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+//.
+// CHECK-LABEL: @main(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i32 0, ptr [[RETVAL]], align 4
@@ -17,8 +18,8 @@
 // CHECK-NEXT:br label [[RETURN:%.*]]
 // CHECK:   if.end:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]],

[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-16 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/30/builds/8330


Here is the relevant piece of the build log for the reference

```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
sanitizer/kernel_crash_async.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=CHECK
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/op

[clang-tools-extra] [clang-tidy] Do not emit file path for anonymous enums in `readability-enum-initial-value` check (PR #112496)

2024-10-16 Thread via cfe-commits

llvmbot wrote:




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

Author: Discookie (Discookie)


Changes

Previously the name of anonymous enums in the check were `enum 'enum (unnamed 
at /full/path/to/file.c:1:1)'`, which breaks reproducibility of clang-tidy 
reports when the analyzed project is in a different folder.

We should think about removing emitted file paths globally from clang-tidy as 
well, if appropriate. Or at least removing the file paths from all locations 
where the warning/note tag already points to the declaration.

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
(+16-6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c 
(+11-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index 1cb95c2b2347b7..5a48b103b9d602 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -123,6 +123,13 @@ AST_MATCHER(EnumDecl, hasSequentialInitialValues) {
   return !AllEnumeratorsArePowersOfTwo;
 }
 
+std::string getName(const EnumDecl *Decl) {
+  if (!Decl->getDeclName())
+return "";
+
+  return Decl->getQualifiedNameAsString();
+}
+
 } // namespace
 
 EnumInitialValueCheck::EnumInitialValueCheck(StringRef Name,
@@ -158,12 +165,15 @@ void EnumInitialValueCheck::registerMatchers(MatchFinder 
*Finder) {
 }
 
 void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
+  PrintingPolicy PP = Result.Context->getPrintingPolicy();
+  PP.AnonymousTagLocations = false;
+
   if (const auto *Enum = Result.Nodes.getNodeAs("inconsistent")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "initial values in enum %0 are not consistent, consider explicit "
+ "initial values in enum '%0' are not consistent, consider 
explicit "
  "initialization of all, none or only the first enumerator")
-<< Enum;
+<< getName(Enum);
 for (const EnumConstantDecl *ECD : Enum->enumerators())
   if (ECD->getInitExpr() == nullptr) {
 const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
@@ -183,16 +193,16 @@ void EnumInitialValueCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (Loc.isInvalid() || Loc.isMacroID())
   return;
 DiagnosticBuilder Diag = diag(Loc, "zero initial value for the first "
-   "enumerator in %0 can be disregarded")
- << Enum;
+   "enumerator in '%0' can be disregarded")
+ << getName(Enum);
 cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
 return;
   }
   if (const auto *Enum = Result.Nodes.getNodeAs("sequential")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "sequential initial value in %0 can be ignored")
-<< Enum;
+ "sequential initial value in '%0' can be ignored")
+<< getName(Enum);
 for (const EnumConstantDecl *ECD : llvm::drop_begin(Enum->enumerators()))
   cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
 return;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 95be0a89cd6c93..a4427ac222b475 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,7 +232,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-enum-initial-value
   ` check by only issuing
-  diagnostics for the definition of an ``enum``, and by fixing a typo in the
+  diagnostics for the definition of an ``enum``, by not emitting a redundant
+  file path for anonymous enums in the diagnostic, and by fixing a typo in the
   diagnostic.
 
 - Improved :doc:`readability-implicit-bool-conversion
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
index b9a34d0683d7f3..54108585f030f8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
@@ -53,6 +53,17 @@ enum EMacro2 {
   // CHECK-FIXES: EMacro2_c = 3,
 };
 
+
+enum {
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 
'' are not consistent
+  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 
'' are not consistent
+  EAnonymous_a = 1,
+  EAnonymous_b,
+  // CHECK-FIXES: EAnonymous_b = 2,
+  EAnonymous_c = 3,
+};
+
+
 enum EnumZeroFirstInitialValue {
   EnumZeroFirstInitialValue_0 = 0,
   // CHECK-MESSAGES-ENA

[clang-tools-extra] [clang-tidy] Do not emit file path for anonymous enums in `readability-enum-initial-value` check (PR #112496)

2024-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Discookie (Discookie)


Changes

Previously the name of anonymous enums in the check were `enum 'enum (unnamed 
at /full/path/to/file.c:1:1)'`, which breaks reproducibility of clang-tidy 
reports when the analyzed project is in a different folder.

We should think about removing emitted file paths globally from clang-tidy as 
well, if appropriate. Or at least removing the file paths from all locations 
where the warning/note tag already points to the declaration.

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
(+16-6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c 
(+11-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index 1cb95c2b2347b7..5a48b103b9d602 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -123,6 +123,13 @@ AST_MATCHER(EnumDecl, hasSequentialInitialValues) {
   return !AllEnumeratorsArePowersOfTwo;
 }
 
+std::string getName(const EnumDecl *Decl) {
+  if (!Decl->getDeclName())
+return "";
+
+  return Decl->getQualifiedNameAsString();
+}
+
 } // namespace
 
 EnumInitialValueCheck::EnumInitialValueCheck(StringRef Name,
@@ -158,12 +165,15 @@ void EnumInitialValueCheck::registerMatchers(MatchFinder 
*Finder) {
 }
 
 void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
+  PrintingPolicy PP = Result.Context->getPrintingPolicy();
+  PP.AnonymousTagLocations = false;
+
   if (const auto *Enum = Result.Nodes.getNodeAs("inconsistent")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "initial values in enum %0 are not consistent, consider explicit "
+ "initial values in enum '%0' are not consistent, consider 
explicit "
  "initialization of all, none or only the first enumerator")
-<< Enum;
+<< getName(Enum);
 for (const EnumConstantDecl *ECD : Enum->enumerators())
   if (ECD->getInitExpr() == nullptr) {
 const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
@@ -183,16 +193,16 @@ void EnumInitialValueCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (Loc.isInvalid() || Loc.isMacroID())
   return;
 DiagnosticBuilder Diag = diag(Loc, "zero initial value for the first "
-   "enumerator in %0 can be disregarded")
- << Enum;
+   "enumerator in '%0' can be disregarded")
+ << getName(Enum);
 cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
 return;
   }
   if (const auto *Enum = Result.Nodes.getNodeAs("sequential")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "sequential initial value in %0 can be ignored")
-<< Enum;
+ "sequential initial value in '%0' can be ignored")
+<< getName(Enum);
 for (const EnumConstantDecl *ECD : llvm::drop_begin(Enum->enumerators()))
   cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
 return;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 95be0a89cd6c93..a4427ac222b475 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,7 +232,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-enum-initial-value
   ` check by only issuing
-  diagnostics for the definition of an ``enum``, and by fixing a typo in the
+  diagnostics for the definition of an ``enum``, by not emitting a redundant
+  file path for anonymous enums in the diagnostic, and by fixing a typo in the
   diagnostic.
 
 - Improved :doc:`readability-implicit-bool-conversion
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
index b9a34d0683d7f3..54108585f030f8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
@@ -53,6 +53,17 @@ enum EMacro2 {
   // CHECK-FIXES: EMacro2_c = 3,
 };
 
+
+enum {
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 
'' are not consistent
+  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 
'' are not consistent
+  EAnonymous_a = 1,
+  EAnonymous_b,
+  // CHECK-FIXES: EAnonymous_b = 2,
+  EAnonymous_c = 3,
+};
+
+
 enum EnumZeroFirstInitialValue {
   EnumZeroFirstInitialValue_0 = 0,
   // CHECK-MESSAGES-ENABLE: :[

[clang-tools-extra] [clang-tidy] Do not emit file path for anonymous enums in `readability-enum-initial-value` check (PR #112496)

2024-10-16 Thread via cfe-commits

https://github.com/Discookie created 
https://github.com/llvm/llvm-project/pull/112496

Previously the name of anonymous enums in the check were `enum 'enum (unnamed 
at /full/path/to/file.c:1:1)'`, which breaks reproducibility of clang-tidy 
reports when the analyzed project is in a different folder.

We should think about removing emitted file paths globally from clang-tidy as 
well, if appropriate. Or at least removing the file paths from all locations 
where the warning/note tag already points to the declaration.

>From be0bee7948a8a6394ba93df619d76048847c1ca8 Mon Sep 17 00:00:00 2001
From: Viktor 
Date: Wed, 16 Oct 2024 08:07:19 +
Subject: [PATCH] [clang-tidy] Do not emit file path for anonymous enums in
 `readability-enum-initial-value` check

---
 .../readability/EnumInitialValueCheck.cpp | 22 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++-
 .../checkers/readability/enum-initial-value.c | 12 +-
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index 1cb95c2b2347b7..5a48b103b9d602 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -123,6 +123,13 @@ AST_MATCHER(EnumDecl, hasSequentialInitialValues) {
   return !AllEnumeratorsArePowersOfTwo;
 }
 
+std::string getName(const EnumDecl *Decl) {
+  if (!Decl->getDeclName())
+return "";
+
+  return Decl->getQualifiedNameAsString();
+}
+
 } // namespace
 
 EnumInitialValueCheck::EnumInitialValueCheck(StringRef Name,
@@ -158,12 +165,15 @@ void EnumInitialValueCheck::registerMatchers(MatchFinder 
*Finder) {
 }
 
 void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
+  PrintingPolicy PP = Result.Context->getPrintingPolicy();
+  PP.AnonymousTagLocations = false;
+
   if (const auto *Enum = Result.Nodes.getNodeAs("inconsistent")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "initial values in enum %0 are not consistent, consider explicit "
+ "initial values in enum '%0' are not consistent, consider 
explicit "
  "initialization of all, none or only the first enumerator")
-<< Enum;
+<< getName(Enum);
 for (const EnumConstantDecl *ECD : Enum->enumerators())
   if (ECD->getInitExpr() == nullptr) {
 const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
@@ -183,16 +193,16 @@ void EnumInitialValueCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (Loc.isInvalid() || Loc.isMacroID())
   return;
 DiagnosticBuilder Diag = diag(Loc, "zero initial value for the first "
-   "enumerator in %0 can be disregarded")
- << Enum;
+   "enumerator in '%0' can be disregarded")
+ << getName(Enum);
 cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
 return;
   }
   if (const auto *Enum = Result.Nodes.getNodeAs("sequential")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "sequential initial value in %0 can be ignored")
-<< Enum;
+ "sequential initial value in '%0' can be ignored")
+<< getName(Enum);
 for (const EnumConstantDecl *ECD : llvm::drop_begin(Enum->enumerators()))
   cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
 return;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 95be0a89cd6c93..a4427ac222b475 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,7 +232,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-enum-initial-value
   ` check by only issuing
-  diagnostics for the definition of an ``enum``, and by fixing a typo in the
+  diagnostics for the definition of an ``enum``, by not emitting a redundant
+  file path for anonymous enums in the diagnostic, and by fixing a typo in the
   diagnostic.
 
 - Improved :doc:`readability-implicit-bool-conversion
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
index b9a34d0683d7f3..54108585f030f8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
@@ -53,6 +53,17 @@ enum EMacro2 {
   // CHECK-FIXES: EMacro2_c = 3,
 };
 
+
+enum {
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 
'' are not consistent
+  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 
'' are not consistent
+  EAnonymous_a = 1,
+  EAnonymous_b,
+  // CHECK-FIXES: EAnonymous_b = 2,
+  EAn

[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-16 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 7d8b69eeb92c87d4aff4cbcd8c0f432d37c2b1e3 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 222 -
 clang/test/Sema/attr-format-missing.c | 228 ++
 clang/test/Sema/attr-format-missing.cpp   | 189 +++
 9 files changed, 654 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..03a64b9238e2bc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -403,6 +403,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses missing format attributes for non-template functions and 
class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 8273701e7b0963..417f2dbdc6a68a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -529,7 +529,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e78acc8dc8c57b..ef4e296a3a5ea9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1051,6 +1051,10 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
+def note_format_function : Note<"%0 format function">;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0faa5aed4eec3b..44e52c6d81c7c2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4576,6 +4576,8 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..e69ffe8f729fde 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16034,6 +16034,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 6759aae37afac1..a

[clang] 9df8d8d - [clang][analyzer] Improve test and documentation in cstring NotNullTerminated checker (#112019)

2024-10-16 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-10-16T10:17:34+02:00
New Revision: 9df8d8d05c2650b51bd4233e1759206d163f3133

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

LOG: [clang][analyzer] Improve test and documentation in cstring 
NotNullTerminated checker (#112019)

CStringChecker has a sub-checker alpha.unix.cstring.NotNullTerminated
which checks for invalid objects passed to string functions. The checker
and its name are not exact and more functions could be checked, this
change only adds some tests and improves documentation.

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/test/Analysis/string.c
clang/test/Analysis/string.cpp

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 81264428c72ed1..58dbd686a6dc9f 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3371,12 +3371,23 @@ Checks for overlap in two buffer arguments. Applies to: 
 ``memcpy, mempcpy, wmem
 
 alpha.unix.cstring.NotNullTerminated (C)
 
-Check for arguments which are not null-terminated strings; applies to: 
``strlen, strnlen, strcpy, strncpy, strcat, strncat, wcslen, wcsnlen``.
+Check for arguments which are not null-terminated strings;
+applies to the ``strlen``, ``strcpy``, ``strcat``, ``strcmp`` family of 
functions.
+
+Only very fundamental cases are detected where the passed memory block is
+absolutely 
diff erent from a null-terminated string. This checker does not
+find if a memory buffer is passed where the terminating zero character
+is missing.
 
 .. code-block:: c
 
- void test() {
-   int y = strlen((char *)&test); // warn
+ void test1() {
+   int l = strlen((char *)&test); // warn
+ }
+
+ void test2() {
+ label:
+   int l = strlen((char *)&&label); // warn
  }
 
 .. _alpha-unix-cstring-OutOfBounds:

diff  --git a/clang/test/Analysis/string.c b/clang/test/Analysis/string.c
index 79b4877eedbd9c..2e0a49d083b0b0 100644
--- a/clang/test/Analysis/string.c
+++ b/clang/test/Analysis/string.c
@@ -361,6 +361,10 @@ void strcpy_fn_const(char *x) {
   strcpy(x, (const char*)&strcpy_fn); // expected-warning{{Argument to string 
copy function is the address of the function 'strcpy_fn', which is not a 
null-terminated string}}
 }
 
+void strcpy_fn_dst(const char *x) {
+  strcpy((char*)&strcpy_fn, x); // expected-warning{{Argument to string copy 
function is the address of the function 'strcpy_fn', which is not a 
null-terminated string}}
+}
+
 extern int globalInt;
 void strcpy_effects(char *x, char *y) {
   char a = x[0];
@@ -469,8 +473,22 @@ void strcat_null_src(char *x) {
   strcat(x, NULL); // expected-warning{{Null pointer passed as 2nd argument to 
string concatenation function}}
 }
 
-void strcat_fn(char *x) {
-  strcat(x, (char*)&strcat_fn); // expected-warning{{Argument to string 
concatenation function is the address of the function 'strcat_fn', which is not 
a null-terminated string}}
+void strcat_fn_dst(const char *x) {
+  strcat((char*)&strcat_fn_dst, x); // expected-warning{{Argument to string 
concatenation function is the address of the function 'strcat_fn_dst', which is 
not a null-terminated string}}
+}
+
+void strcat_fn_src(char *x) {
+  strcat(x, (char*)&strcat_fn_src); // expected-warning{{Argument to string 
concatenation function is the address of the function 'strcat_fn_src', which is 
not a null-terminated string}}
+}
+
+void strcat_label_dst(const char *x) {
+label:
+  strcat((char*)&&label, x); // expected-warning{{Argument to string 
concatenation function is the address of the label 'label', which is not a 
null-terminated string}}
+}
+
+void strcat_label_src(char *x) {
+label:
+  strcat(x, (char*)&&label); // expected-warning{{Argument to string 
concatenation function is the address of the label 'label', which is not a 
null-terminated string}}
 }
 
 void strcat_effects(char *y) {
@@ -568,8 +586,12 @@ void strncpy_null_src(char *x) {
   strncpy(x, NULL, 5); // expected-warning{{Null pointer passed as 2nd 
argument to string copy function}}
 }
 
-void strncpy_fn(char *x) {
-  strncpy(x, (char*)&strcpy_fn, 5); // expected-warning{{Argument to string 
copy function is the address of the function 'strcpy_fn', which is not a 
null-terminated string}}
+void strncpy_fn_src(char *x) {
+  strncpy(x, (char*)&strncpy_fn_src, 5); // expected-warning{{Argument to 
string copy function is the address of the function 'strncpy_fn_src', which is 
not a null-terminated string}}
+}
+
+void strncpy_fn_dst(const char *x) {
+  strncpy((char*)&strncpy_fn_dst, x, 5); // expected-warning{{Argument to 
string copy function is the address of the function 'strncpy_fn_dst', which is 
not a null-terminated string}}
 }
 
 void strncpy_effects(char *x, char *y) {
@@ -680

[clang] [clang][analyzer] Improve test and documentation in cstring NotNullTerminated checker (PR #112019)

2024-10-16 Thread Balázs Kéri via cfe-commits

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


[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-16 Thread Budimir Aranđelović via cfe-commits


@@ -0,0 +1,251 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c_diagnostics 
-Wmissing-format-attribute %s
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-format-attribute 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -x c++ -verify=expected,cpp_diagnostics 
-Wmissing-format-attribute %s
+// RUN: %clang_cc1 -fsyntax-only -x c++ -verify=expected,cpp_diagnostics 
-std=c++2b -Wmissing-format-attribute %s
+// RUN: %clang_cc1 -fsyntax-only -x c++ -verify=expected,cpp_diagnostics 
-std=c++23 -Wmissing-format-attribute %s
+// RUN: %clang_cc1 -fsyntax-only -x c++ -Wmissing-format-attribute 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+#ifndef __cplusplus
+typedef __CHAR16_TYPE__ char16_t;
+typedef __CHAR32_TYPE__ char32_t;
+typedef __WCHAR_TYPE__ wchar_t;
+#endif
+
+typedef __SIZE_TYPE__ size_t;
+typedef __builtin_va_list va_list;
+
+__attribute__((__format__(__printf__, 1, 2)))
+int printf(const char *, ...); // #printf
+
+__attribute__((__format__(__scanf__, 1, 2)))
+int scanf(const char *, ...); // #scanf
+
+__attribute__((__format__(__printf__, 1, 0)))
+int vprintf(const char *, va_list); // #vprintf
+
+__attribute__((__format__(__scanf__, 1, 0)))
+int vscanf(const char *, va_list); // #vscanf
+
+__attribute__((__format__(__printf__, 2, 0)))
+int vsprintf(char *, const char *, va_list); // #vsprintf
+
+__attribute__((__format__(__printf__, 3, 0)))
+int vsnprintf(char *ch, size_t, const char *, va_list); // #vsnprintf
+
+#ifndef __cplusplus
+int vwscanf(const wchar_t *, va_list); // #vwscanf
+#endif
+
+__attribute__((__format__(__scanf__, 1, 4)))
+void f1(char *out, const size_t len, const char *format, ... /* args */) // #f1
+{
+va_list args;
+vsnprintf(out, len, format, args); // expected-no-warning@#f1
+}
+
+__attribute__((__format__(__printf__, 1, 4)))
+void f2(char *out, const size_t len, const char *format, ... /* args */) // #f2
+{
+va_list args;
+vsnprintf(out, len, format, args); // expected-warning@#f2 {{diagnostic 
behavior may be improved by adding the 'printf' format attribute to the 
declaration of 'f2'}}

budimirarandjelovichtec wrote:

Yes, warning is emitted on the declaration. I've just added a note to the call 
that trigerred it.

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


[clang-tools-extra] [clang-tidy] Do not emit file path for anonymous enums in `readability-enum-initial-value` check (PR #112496)

2024-10-16 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 4ddea298e60c31d0995c06189a592895d2ad512b 
be0bee7948a8a6394ba93df619d76048847c1ca8 --extensions c,cpp -- 
clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index 5a48b103b9..9c000df132 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -170,9 +170,10 @@ void EnumInitialValueCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   if (const auto *Enum = Result.Nodes.getNodeAs("inconsistent")) {
 DiagnosticBuilder Diag =
-diag(Enum->getBeginLoc(),
- "initial values in enum '%0' are not consistent, consider 
explicit "
- "initialization of all, none or only the first enumerator")
+diag(
+Enum->getBeginLoc(),
+"initial values in enum '%0' are not consistent, consider explicit 
"
+"initialization of all, none or only the first enumerator")
 << getName(Enum);
 for (const EnumConstantDecl *ECD : Enum->enumerators())
   if (ECD->getInitExpr() == nullptr) {

``




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


[clang] [Modules][NFC] Rewrite friend-definition-2.cpp with split-file (PR #112380)

2024-10-16 Thread Ilya Biryukov via cfe-commits


@@ -1,32 +1,53 @@
-// RUN: %clang_cc1 -std=c++14 -fmodules %s -verify
-// RUN: %clang_cc1 -std=c++14 -fmodules %s -verify -triple i686-windows
-// expected-no-diagnostics
-#pragma clang module build A
-module A {}
-#pragma clang module contents
-#pragma clang module begin A
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=A -emit-module 
%t/a.modulemap -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=B -emit-module 
%t/b.modulemap -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules 
-fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm \
+// RUN:   %t/use.cc -verify
+
+// RUN: rm -f %t/*.pcm
+
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=A -emit-module 
%t/a.modulemap -o %t/a.pcm -triple i686-windows
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=B -emit-module 
%t/b.modulemap -o %t/b.pcm -triple i686-windows
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules 
-fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm \
+// RUN:   %t/use.cc -verify -triple i686-windows
+
+//--- a.modulemap
+module A {
+  header "a.h"
+}
+
+//--- a.h
+#ifndef A_H
+#define A_H
+template struct ct { friend auto operator-(ct, ct) { struct X {}; 
return X(); } void x(); };
+#endif
+
+//--- b.modulemap
+module B {
+  header "b.h"
+}
+
+//--- b.h
+#ifndef B_H
+#define B_H
 template struct ct { friend auto operator-(ct, ct) { struct X {}; 
return X(); } void x(); };

ilya-biryukov wrote:

Yeah, that's correct, I somehow thought you meant also passing the module map. 
Using the same header as modular and non-modular in the same test is quite hard 
to follow, so I didn't want to go for it. Introducing a new textual header 
totally works.

Sharing the same header would've been an option, but since the file is small, 
hopefully it doesn't matter much.

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


[clang] [Sema] Fix warning in SemaOpenACC.cpp (PR #112481)

2024-10-16 Thread via cfe-commits

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

LGTM

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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

2024-10-16 Thread Ilya Biryukov via cfe-commits


@@ -1183,7 +1181,7 @@ class Sema final : public SemaBase {
   std::optional> CachedDarwinSDKInfo;
   bool WarnedDarwinSDKInfoMissing = false;
 
-  bool WarnedStackExhausted = false;
+  SingleWarningStackAwareExecutor StackAwareExecutor;

ilya-biryukov wrote:

Should we share the state between Sema and CodeGen?
It's not unusual for deeply nested ASTs to cause the limits to be hit in both 
and it would make sense to only diagnose once globally.

I am not sure which class would be a good fit to hold that state as CodeGen 
does not have a reference to Sema and vice versa, so maybe it needs too much 
plumbing and isn't worth it. But I wanted to throw this idea out and hear what 
people think.

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


[clang] [clang] Support `#pragma clang loop pipeline(enable)` (PR #112501)

2024-10-16 Thread Ryotaro Kasuga via cfe-commits

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


[clang] Different info in docs in AST methods (PR #112190)

2024-10-16 Thread Mikhnenko Sasha via cfe-commits

4JustMe4 wrote:

The suggestions have been applied. The document re-generation script has been 
launched.

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


[clang] [clang][bytecode] Start implementing __builtin_bit_cast (PR #112126)

2024-10-16 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 1cf8a3bd76adfd5595c000e2ad86fb1db5b96a8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 13 Oct 2024 08:57:48 +0200
Subject: [PATCH 1/2] [clang][bytecode] Start implementing __builtin_bit_cast

---
 clang/lib/AST/ByteCode/Boolean.h  |  10 +
 clang/lib/AST/ByteCode/Compiler.cpp   |  64 
 clang/lib/AST/ByteCode/Compiler.h |   1 +
 clang/lib/AST/ByteCode/Floating.h |   5 +
 clang/lib/AST/ByteCode/Integral.h |  12 +
 clang/lib/AST/ByteCode/IntegralAP.h   |   6 +
 clang/lib/AST/ByteCode/Interp.cpp |  17 +
 clang/lib/AST/ByteCode/Interp.h   |  28 ++
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 353 +
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  26 ++
 clang/lib/AST/ByteCode/Opcodes.td |  10 +
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 359 ++
 14 files changed, 893 insertions(+)
 create mode 100644 clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
 create mode 100644 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast.cpp

diff --git a/clang/lib/AST/ByteCode/Boolean.h b/clang/lib/AST/ByteCode/Boolean.h
index c568b557574e2b..78d75e75c7531a 100644
--- a/clang/lib/AST/ByteCode/Boolean.h
+++ b/clang/lib/AST/ByteCode/Boolean.h
@@ -81,6 +81,16 @@ class Boolean final {
 
   Boolean truncate(unsigned TruncBits) const { return *this; }
 
+  static Boolean bitcastFromMemory(const std::byte *Buff, unsigned BitWidth) {
+// Boolean width is currently always 8 for all supported targets. If this
+// changes we need to get the bool width from the target info.
+assert(BitWidth == 8);
+bool Val = static_cast(*Buff);
+return Boolean(Val);
+  }
+
+  void bitcastToMemory(std::byte *Buff) { std::memcpy(Buff, &V, sizeof(V)); }
+
   void print(llvm::raw_ostream &OS) const { OS << (V ? "true" : "false"); }
   std::string toDiagnosticString(const ASTContext &Ctx) const {
 std::string NameStr;
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 8ca63bf64aa0ef..84cbbd8426eed2 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -470,6 +470,9 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 return this->emitDecayPtr(*FromT, *ToT, CE);
   }
 
+  case CK_LValueToRValueBitCast:
+return this->emitBuiltinBitCast(CE);
+
   case CK_IntegralToBoolean:
   case CK_FixedPointToBoolean:
   case CK_BooleanToSignedIntegral:
@@ -6409,6 +6412,67 @@ bool Compiler::emitDestruction(const Descriptor 
*Desc,
   return this->emitRecordDestruction(Desc->ElemRecord, Loc);
 }
 
+//  This function is constexpr if and only if To, From, and the types of
+//  all subobjects of To and From are types T such that...
+//  (3.1) - is_union_v is false;
+//  (3.2) - is_pointer_v is false;
+//  (3.3) - is_member_pointer_v is false;
+//  (3.4) - is_volatile_v is false; and
+//  (3.5) - T has no non-static data members of reference type
+template 
+bool Compiler::emitBuiltinBitCast(const CastExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
+  QualType FromType = SubExpr->getType();
+  QualType ToType = E->getType();
+  std::optional ToT = classify(ToType);
+
+  assert(!DiscardResult && "Implement DiscardResult mode for bitcasts.");
+
+  if (ToType->isNullPtrType()) {
+if (!this->discard(SubExpr))
+  return false;
+
+return this->emitNullPtr(nullptr, E);
+  }
+
+  if (FromType->isNullPtrType() && ToT) {
+if (!this->discard(SubExpr))
+  return false;
+
+return visitZeroInitializer(*ToT, ToType, E);
+  }
+  assert(!ToType->isReferenceType());
+
+  // Get a pointer to the value-to-cast on the stack.
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!ToT || ToT == PT_Ptr) {
+// Conversion to an array or record type.
+assert(false && "Implement bitcast to pointers.");
+  }
+  assert(ToT);
+
+  const llvm::fltSemantics *TargetSemantics = nullptr;
+  if (ToT == PT_Float)
+TargetSemantics = &Ctx.getFloatSemantics(ToType);
+
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  bool ToTypeIsUChar = (ToType->isSpecificBuiltinType(BuiltinType::UChar) ||
+ToType->isSpecificBuiltinType(BuiltinType::Char_U));
+  uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
+
+  if (!this->emitBitCast(*ToT, ToTypeIsUChar || ToType->isStdByteType(),
+ ResultBitWidth, TargetSemantics, E))
+return false;
+
+  if (DiscardResult)
+return this->emitPop(*ToT, E);
+
+  return true;
+}
+
 namespace clang {
 namespace interp {
 
diff --git a/clang/lib/AST/B

[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-16 Thread Budimir Aranđelović via cfe-commits


@@ -5335,6 +5335,217 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
 }
 
+// This function is called only if function call is not inside template body.
+// TODO: Add call for function calls inside template body.
+// Emit warnings if parent function misses format attributes.
+void Sema::DiagnoseMissingFormatAttributes(Stmt *Body,
+   const FunctionDecl *FDecl) {
+  assert(FDecl);
+
+  // If there are no function body, exit.
+  if (!Body)
+return;
+
+  // Get missing format attributes
+  std::vector MissingFormatAttributes =
+  GetMissingFormatAttributes(Body, FDecl);
+  if (MissingFormatAttributes.empty())
+return;
+
+  // Check if there are more than one format type found. In that case do not
+  // emit diagnostic.
+  const clang::IdentifierInfo *AttrType = 
MissingFormatAttributes[0]->getType();
+  if (llvm::any_of(MissingFormatAttributes, [&](const FormatAttr *Attr) {
+return AttrType != Attr->getType();
+  }))
+return;
+
+  for (const FormatAttr *FA : MissingFormatAttributes) {
+// If format index and first-to-check argument index are negative, it means
+// that this attribute is only saved for multiple format types checking.
+if (FA->getFormatIdx() < 0 || FA->getFirstArg() < 0)
+  continue;
+
+// Emit diagnostic
+SourceLocation Loc = FDecl->getLocation();
+Diag(Loc, diag::warn_missing_format_attribute)
+<< FA->getType() << FDecl
+<< FixItHint::CreateInsertion(Loc,
+  (llvm::Twine("__attribute__((format(") +
+   FA->getType()->getName() + ", " +
+   llvm::Twine(FA->getFormatIdx()) + ", " +
+   llvm::Twine(FA->getFirstArg()) + ")))")
+  .str());
+  }
+}
+
+// Returns vector of format attributes. There are no two attributes with same
+// arguments in returning vector. There can be attributes that effectivelly 
only
+// store information about format type.
+std::vector
+Sema::GetMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl) {
+  unsigned int FunctionFormatArgumentIndexOffset =
+  checkIfMethodHasImplicitObjectParameter(FDecl) ? 2 : 1;
+
+  std::vector MissingAttributes;
+
+  // Iterate over body statements.
+  for (auto *Child : Body->children()) {
+// If child statement is compound statement, recursively get missing
+// attributes.
+if (dyn_cast_or_null(Child)) {
+  std::vector CompoundStmtMissingAttributes =
+  GetMissingFormatAttributes(Child, FDecl);
+
+  // If there are already missing attributes with same arguments, do not 
add
+  // duplicates.
+  for (FormatAttr *FA : CompoundStmtMissingAttributes) {
+if (!llvm::any_of(MissingAttributes, [&](const FormatAttr *Attr) {
+  return FA->getType() == Attr->getType() &&
+ FA->getFormatIdx() == Attr->getFormatIdx() &&
+ FA->getFirstArg() == Attr->getFirstArg();
+}))
+  MissingAttributes.push_back(FA);
+  }
+
+  continue;
+}
+
+ValueStmt *VS = dyn_cast_or_null(Child);
+if (!VS)
+  continue;
+Expr *TheExpr = VS->getExprStmt();
+if (!TheExpr)
+  continue;
+CallExpr *TheCall = dyn_cast_or_null(TheExpr);
+if (!TheCall)
+  continue;
+const FunctionDecl *ChildFunction =
+dyn_cast_or_null(TheCall->getCalleeDecl());
+if (!ChildFunction || !ChildFunction->hasAttr())
+  continue;
+
+Expr **Args = TheCall->getArgs();
+unsigned int NumArgs = TheCall->getNumArgs();
+
+// If child expression is function, check if it is format function.
+// If it is, check if parent function misses format attributes.
+
+unsigned int ChildFunctionFormatArgumentIndexOffset =
+checkIfMethodHasImplicitObjectParameter(ChildFunction) ? 2 : 1;
+
+// If child function is format function and format arguments are not
+// relevant to emit diagnostic, save only information about format type
+// (format index and first-to-check argument index are set to -1).
+// Information about format type is later used to determine if there are
+// more than one format type found.
+
+// Check if function has format attribute with forwarded format string.
+IdentifierInfo *AttrType;
+const ParmVarDecl *FormatArg;
+if (!llvm::any_of(ChildFunction->specific_attrs(),
+  [&](const FormatAttr *Attr) {
+AttrType = Attr->getType();
+
+int OffsetFormatIndex =
+Attr->getFormatIdx() -
+ChildFunctionFormatArgumentIndexOffset;
+if (OffsetFormatIndex < 0 ||
+(unsigned)OffsetFor

[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

2024-10-16 Thread Boaz Brickner via cfe-commits


@@ -1183,7 +1181,7 @@ class Sema final : public SemaBase {
   std::optional> CachedDarwinSDKInfo;
   bool WarnedDarwinSDKInfoMissing = false;
 
-  bool WarnedStackExhausted = false;
+  SingleWarningStackAwareExecutor StackAwareExecutor;

bricknerb wrote:

Yes, I considered that and it seems somewhat to add some complexity.
Assuming the same code might hit this in both Sema and CodeGen, I don't see a 
reason the user should see this warning twice.
If Sema and CodeGen would typically be hitting different use cases, it might 
make sense, but I don't think that's the case.
It's anyways beyond the scope of this change, and we could consider it as a 
future improvement, though I doubt it should be high priority.

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


[clang] [Sema] Fix warning in SemaOpenACC.cpp (PR #112481)

2024-10-16 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] 7c5d5c0 - [Sema] Fix warning in SemaOpenACC.cpp (#112481)

2024-10-16 Thread via cfe-commits

Author: Karl-Johan Karlsson
Date: 2024-10-16T11:01:33+02:00
New Revision: 7c5d5c08181f399858d918d6910c021af4ec36c0

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

LOG: [Sema] Fix warning in SemaOpenACC.cpp (#112481)

Fix gcc warning:

clang/lib/Sema/SemaOpenACC.cpp:2208:5: warning: this statement may fall
through [-Wimplicit-fallthrough=]

Added: 


Modified: 
clang/lib/Sema/SemaOpenACC.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 22aedbc70df8cc..d33b0d0c1c3018 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -2216,7 +2216,7 @@ ExprResult SemaOpenACC::CheckGangExpr(OpenACCGangKind GK, 
Expr *E) {
 case OpenACCGangKind::Static:
   return CheckGangStaticExpr(*this, E);
 }
-  }
+  } break;
   default:
 llvm_unreachable("Non compute construct in active compute construct?");
   }



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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

2024-10-16 Thread Ilya Biryukov via cfe-commits


@@ -16,6 +16,8 @@
 
 #include 
 
+#include "clang/Basic/Diagnostic.h"

ilya-biryukov wrote:

This dependency seems unnecessary in this file, the other functions are 
lower-level (don't depend on SourceLocations, etc).

There are a few files that depend on it for things like `noteBottomOfStack()`.

In the interest of keeping the dependencies minimal, I'd suggest moving this to 
a new file that depends on `Stack.h` and source locations + diagnostics engine. 

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


[clang] [llvm] [Clang] Fix argument extensions in CGBlocks.cpp (PR #111740)

2024-10-16 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

gentle ping... @efriedma-quic @nikic 

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


[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

@steakhal May I merge this commit?

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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

2024-10-16 Thread Ilya Biryukov via cfe-commits


@@ -1183,7 +1181,7 @@ class Sema final : public SemaBase {
   std::optional> CachedDarwinSDKInfo;
   bool WarnedDarwinSDKInfoMissing = false;
 
-  bool WarnedStackExhausted = false;
+  SingleWarningStackAwareExecutor StackAwareExecutor;

ilya-biryukov wrote:

Makes sense to keep this as an action for the future. Sharing the logic makes 
sense, though.

Should we file an issue on GitHub and/or add a FIXME to the code that we might 
want to share a single instance Sema and CodeGen in the future?

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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

2024-10-16 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

Adding @ChuanqiXu9 to get another pair of eyes on it (for naming, code 
structure, etc). I believe he was involved in reviewing some changes touching 
`runWithSufficientStackSpace` I've previously sent.

Please give him a chance to review this.

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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

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

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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

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

https://github.com/ChuanqiXu9 commented:

Took a pretty quick scanning and this looks good to me.

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


[clang] [clang] Deduplicate the logic that only warns once when stack is almost full (PR #112371)

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


@@ -1183,7 +1181,7 @@ class Sema final : public SemaBase {
   std::optional> CachedDarwinSDKInfo;
   bool WarnedDarwinSDKInfoMissing = false;
 
-  bool WarnedStackExhausted = false;
+  SingleWarningStackAwareExecutor StackAwareExecutor;

ChuanqiXu9 wrote:

Abstractly, we can generate codes without constructing a Sema by loading the 
AST file by ASTUnit and generate it. So I'd like to make them seperate.

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


[clang] [clang][bytecode] Start implementing __builtin_bit_cast (PR #112126)

2024-10-16 Thread Timm Baeder via cfe-commits

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

>From 1cf8a3bd76adfd5595c000e2ad86fb1db5b96a8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 13 Oct 2024 08:57:48 +0200
Subject: [PATCH] [clang][bytecode] Start implementing __builtin_bit_cast

---
 clang/lib/AST/ByteCode/Boolean.h  |  10 +
 clang/lib/AST/ByteCode/Compiler.cpp   |  64 
 clang/lib/AST/ByteCode/Compiler.h |   1 +
 clang/lib/AST/ByteCode/Floating.h |   5 +
 clang/lib/AST/ByteCode/Integral.h |  12 +
 clang/lib/AST/ByteCode/IntegralAP.h   |   6 +
 clang/lib/AST/ByteCode/Interp.cpp |  17 +
 clang/lib/AST/ByteCode/Interp.h   |  28 ++
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 353 +
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  26 ++
 clang/lib/AST/ByteCode/Opcodes.td |  10 +
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 359 ++
 14 files changed, 893 insertions(+)
 create mode 100644 clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
 create mode 100644 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast.cpp

diff --git a/clang/lib/AST/ByteCode/Boolean.h b/clang/lib/AST/ByteCode/Boolean.h
index c568b557574e2b..78d75e75c7531a 100644
--- a/clang/lib/AST/ByteCode/Boolean.h
+++ b/clang/lib/AST/ByteCode/Boolean.h
@@ -81,6 +81,16 @@ class Boolean final {
 
   Boolean truncate(unsigned TruncBits) const { return *this; }
 
+  static Boolean bitcastFromMemory(const std::byte *Buff, unsigned BitWidth) {
+// Boolean width is currently always 8 for all supported targets. If this
+// changes we need to get the bool width from the target info.
+assert(BitWidth == 8);
+bool Val = static_cast(*Buff);
+return Boolean(Val);
+  }
+
+  void bitcastToMemory(std::byte *Buff) { std::memcpy(Buff, &V, sizeof(V)); }
+
   void print(llvm::raw_ostream &OS) const { OS << (V ? "true" : "false"); }
   std::string toDiagnosticString(const ASTContext &Ctx) const {
 std::string NameStr;
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 8ca63bf64aa0ef..84cbbd8426eed2 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -470,6 +470,9 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 return this->emitDecayPtr(*FromT, *ToT, CE);
   }
 
+  case CK_LValueToRValueBitCast:
+return this->emitBuiltinBitCast(CE);
+
   case CK_IntegralToBoolean:
   case CK_FixedPointToBoolean:
   case CK_BooleanToSignedIntegral:
@@ -6409,6 +6412,67 @@ bool Compiler::emitDestruction(const Descriptor 
*Desc,
   return this->emitRecordDestruction(Desc->ElemRecord, Loc);
 }
 
+//  This function is constexpr if and only if To, From, and the types of
+//  all subobjects of To and From are types T such that...
+//  (3.1) - is_union_v is false;
+//  (3.2) - is_pointer_v is false;
+//  (3.3) - is_member_pointer_v is false;
+//  (3.4) - is_volatile_v is false; and
+//  (3.5) - T has no non-static data members of reference type
+template 
+bool Compiler::emitBuiltinBitCast(const CastExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
+  QualType FromType = SubExpr->getType();
+  QualType ToType = E->getType();
+  std::optional ToT = classify(ToType);
+
+  assert(!DiscardResult && "Implement DiscardResult mode for bitcasts.");
+
+  if (ToType->isNullPtrType()) {
+if (!this->discard(SubExpr))
+  return false;
+
+return this->emitNullPtr(nullptr, E);
+  }
+
+  if (FromType->isNullPtrType() && ToT) {
+if (!this->discard(SubExpr))
+  return false;
+
+return visitZeroInitializer(*ToT, ToType, E);
+  }
+  assert(!ToType->isReferenceType());
+
+  // Get a pointer to the value-to-cast on the stack.
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!ToT || ToT == PT_Ptr) {
+// Conversion to an array or record type.
+assert(false && "Implement bitcast to pointers.");
+  }
+  assert(ToT);
+
+  const llvm::fltSemantics *TargetSemantics = nullptr;
+  if (ToT == PT_Float)
+TargetSemantics = &Ctx.getFloatSemantics(ToType);
+
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  bool ToTypeIsUChar = (ToType->isSpecificBuiltinType(BuiltinType::UChar) ||
+ToType->isSpecificBuiltinType(BuiltinType::Char_U));
+  uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
+
+  if (!this->emitBitCast(*ToT, ToTypeIsUChar || ToType->isStdByteType(),
+ ResultBitWidth, TargetSemantics, E))
+return false;
+
+  if (DiscardResult)
+return this->emitPop(*ToT, E);
+
+  return true;
+}
+
 namespace clang {
 namespace interp {
 
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h

[clang] [clang][bytecode] Start implementing __builtin_bit_cast (PR #112126)

2024-10-16 Thread Timm Baeder via cfe-commits

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


[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-16 Thread Budimir Aranđelović via cfe-commits


@@ -5335,6 +5335,217 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
 }
 
+// This function is called only if function call is not inside template body.
+// TODO: Add call for function calls inside template body.
+// Emit warnings if parent function misses format attributes.
+void Sema::DiagnoseMissingFormatAttributes(Stmt *Body,
+   const FunctionDecl *FDecl) {
+  assert(FDecl);
+
+  // If there are no function body, exit.
+  if (!Body)
+return;
+
+  // Get missing format attributes
+  std::vector MissingFormatAttributes =
+  GetMissingFormatAttributes(Body, FDecl);
+  if (MissingFormatAttributes.empty())
+return;
+
+  // Check if there are more than one format type found. In that case do not
+  // emit diagnostic.
+  const clang::IdentifierInfo *AttrType = 
MissingFormatAttributes[0]->getType();
+  if (llvm::any_of(MissingFormatAttributes, [&](const FormatAttr *Attr) {
+return AttrType != Attr->getType();
+  }))
+return;
+
+  for (const FormatAttr *FA : MissingFormatAttributes) {
+// If format index and first-to-check argument index are negative, it means
+// that this attribute is only saved for multiple format types checking.
+if (FA->getFormatIdx() < 0 || FA->getFirstArg() < 0)
+  continue;
+
+// Emit diagnostic
+SourceLocation Loc = FDecl->getLocation();
+Diag(Loc, diag::warn_missing_format_attribute)
+<< FA->getType() << FDecl
+<< FixItHint::CreateInsertion(Loc,
+  (llvm::Twine("__attribute__((format(") +
+   FA->getType()->getName() + ", " +
+   llvm::Twine(FA->getFormatIdx()) + ", " +
+   llvm::Twine(FA->getFirstArg()) + ")))")
+  .str());
+  }
+}
+
+// Returns vector of format attributes. There are no two attributes with same
+// arguments in returning vector. There can be attributes that effectivelly 
only
+// store information about format type.
+std::vector
+Sema::GetMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl) {
+  unsigned int FunctionFormatArgumentIndexOffset =
+  checkIfMethodHasImplicitObjectParameter(FDecl) ? 2 : 1;
+
+  std::vector MissingAttributes;
+
+  // Iterate over body statements.
+  for (auto *Child : Body->children()) {
+// If child statement is compound statement, recursively get missing
+// attributes.
+if (dyn_cast_or_null(Child)) {

budimirarandjelovichtec wrote:

Yes, I meant braces instead of branches. This snippet does not produce warning, 
so I'm working to fix it.

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


[clang] [clang] Implement constexpr __builtin_bit_cast for complex types (PR #109981)

2024-10-16 Thread Timm Baeder via cfe-commits

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

>From 8a987510829abcba7bdb3572db418f71f33bbd69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 25 Sep 2024 15:45:06 +0200
Subject: [PATCH] [clang] Implement constexpr __builtin_bit_cast for complex
 types

Fixes https://github.com/llvm/llvm-project/issues/94620
---
 clang/lib/AST/ExprConstant.cpp| 43 +++
 .../SemaCXX/constexpr-builtin-bit-cast.cpp| 16 +++
 2 files changed, 59 insertions(+)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 51956c631786b53..4557297e0dd1499 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7237,6 +7237,7 @@ class APValueToBufferConverter {
 
 case APValue::ComplexInt:
 case APValue::ComplexFloat:
+  return visitComplex(Val, Ty, Offset);
 case APValue::FixedPoint:
   // FIXME: We should support these.
 
@@ -7323,6 +7324,31 @@ class APValueToBufferConverter {
 return true;
   }
 
+  bool visitComplex(const APValue &Val, QualType Ty, CharUnits Offset) {
+const ComplexType *ComplexTy = Ty->castAs();
+QualType EltTy = ComplexTy->getElementType();
+CharUnits EltSizeChars = Info.Ctx.getTypeSizeInChars(EltTy);
+bool IsInt = Val.isComplexInt();
+
+if (IsInt) {
+  if (!visitInt(Val.getComplexIntReal(), EltTy,
+Offset + (0 * EltSizeChars)))
+return false;
+  if (!visitInt(Val.getComplexIntImag(), EltTy,
+Offset + (1 * EltSizeChars)))
+return false;
+} else {
+  if (!visitFloat(Val.getComplexFloatReal(), EltTy,
+  Offset + (0 * EltSizeChars)))
+return false;
+  if (!visitFloat(Val.getComplexFloatImag(), EltTy,
+  Offset + (1 * EltSizeChars)))
+return false;
+}
+
+return true;
+  }
+
   bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
 const VectorType *VTy = Ty->castAs();
 QualType EltTy = VTy->getElementType();
@@ -7595,6 +7621,23 @@ class BufferToAPValueConverter {
 return ArrayValue;
   }
 
+  std::optional visit(const ComplexType *Ty, CharUnits Offset) {
+QualType ElementType = Ty->getElementType();
+CharUnits ElementWidth = Info.Ctx.getTypeSizeInChars(ElementType);
+bool IsInt = ElementType->isIntegerType();
+
+std::optional Values[2];
+for (unsigned I = 0; I != 2; ++I) {
+  Values[I] = visitType(Ty->getElementType(), Offset + I * ElementWidth);
+  if (!Values[I])
+return std::nullopt;
+}
+
+if (IsInt)
+  return APValue(Values[0]->getInt(), Values[1]->getInt());
+return APValue(Values[0]->getFloat(), Values[1]->getFloat());
+  }
+
   std::optional visit(const VectorType *VTy, CharUnits Offset) {
 QualType EltTy = VTy->getElementType();
 unsigned NElts = VTy->getNumElements();
diff --git a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp 
b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
index 7520b43a194aba6..5ddb77b35ff145e 100644
--- a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
+++ b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
@@ -511,3 +511,19 @@ constexpr bool9 bad_short_to_bool9 = 
__builtin_bit_cast(bool9, static_cast(0xCAFEBABE0C05FEFEULL), "");
+  static_assert(bit_cast(test_int_complex) == (LITTLE_END
+   ? 
0xCAFEBABE0C05FEFE
+   : 
0x0C05FEFECAFEBABE), "");
+  static_assert(sizeof(double) == 2 * sizeof(float));
+  struct TwoFloats { float A; float B; };
+  constexpr _Complex float test_float_complex = {1.0f, 2.0f};
+  constexpr TwoFloats TF = __builtin_bit_cast(TwoFloats, test_float_complex);
+  static_assert(TF.A == 1.0f && TF.B == 2.0f);
+
+  constexpr double D = __builtin_bit_cast(double, test_float_complex);
+  constexpr int M = __builtin_bit_cast(int, test_int_complex); // 
expected-error {{__builtin_bit_cast source size does not equal destination 
size}}
+}

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-16 Thread Nashe Mncube via cfe-commits


@@ -4769,6 +4843,109 @@ class LoadExclusivePair sz, bit o2, bit L, bit 
o1, bit o0,
   let PostEncoderMethod = "fixLoadStoreExclusive<0,1>";
 }
 
+// Armv9.6-a load-store exclusive instructions
+let hasSideEffects = 1, mayLoad = 1, mayStore = 1 in
+class BaseLoadStoreExclusiveLSUI sz, bit L, bit o0,
+ dag oops, dag iops, string asm, string operands>
+: I {
+  let Inst{31-30} = sz;
+  let Inst{29-23} = 0b0010010;
+  let Inst{22}= L;
+  let Inst{15}= o0;
+}
+
+
+// Neither Rs nor Rt2 operands.
+
+class LoadExclusiveLSUI sz, bit L, bit o0,
+RegisterClass regtype, string asm>
+: BaseLoadStoreExclusiveLSUI,
+  Sched<[WriteLD]>
+{
+  bits<5> Rt;
+  bits<5> Rn;
+  let Inst{20-16} = 0b1;
+  let Unpredictable{20-16} = 0b1;
+  let Inst{14-10} = 0b1;
+  let Unpredictable{14-10} = 0b1;
+  let Inst{9-5} = Rn;
+  let Inst{4-0} = Rt;
+
+  let PostEncoderMethod = "fixLoadStoreExclusive<0,0>";
+}
+
+ class StoreExclusiveLSUI sz, bit L, bit o0,
+  RegisterClass regtype, string asm>
+ : BaseLoadStoreExclusiveLSUI,
+   Sched<[WriteSTX]> {
+   bits<5> Ws;
+   bits<5> Rt;
+   bits<5> Rn;
+   let Inst{20-16} = Ws;
+   let Inst{15} = o0;
+   let Inst{14-10} = 0b1;
+   let Unpredictable{14-10} = 0b1;
+   let Inst{9-5} = Rn;
+   let Inst{4-0} = Rt;
+
+   let Constraints = "@earlyclobber $Ws";
+   let PostEncoderMethod = "fixLoadStoreExclusive<1,0>";
+ }
+
+// Armv9.6-a load-store unprivileged instructions
+class BaseLoadUnprivilegedLSUI sz, dag oops, dag iops, string asm>
+: I {
+   bits<5> Rt;
+   bits<5> Rn;
+   let Inst{31-30} = sz;
+   let Inst{29-23} = 0b0010010;
+   let Inst{22}  = 0b1;
+   let Inst{21} = 0b0;
+   let Inst{20-16} = 0b1;
+   let Unpredictable{20-16} = 0b1;
+   let Inst{15} = 0b0;
+   let Inst{14-10} = 0b1;
+   let Unpredictable{14-10} = 0b1;
+   let Inst{9-5} = Rn;
+   let Inst{4-0} = Rt;
+   let PostEncoderMethod = "fixLoadStoreExclusive<0,0>";
+}
+
+multiclass LoadUnprivilegedLSUI sz, RegisterClass regtype, string asm> 
{
+  def i : BaseLoadUnprivilegedLSUIhttps://github.com/llvm/llvm-project/pull/112341
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-16 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 3f46179ecdb0097313c0249c1f4ff0c33eb21772 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 222 -
 clang/test/Sema/attr-format-missing.c | 228 ++
 clang/test/Sema/attr-format-missing.cpp   | 189 +++
 9 files changed, 654 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dc5564b6db119f..b0631ac9e78e02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -416,6 +416,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses missing format attributes for non-template functions and 
class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 8273701e7b0963..417f2dbdc6a68a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -529,7 +529,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c458a62d9be48c..72885b86176755 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1051,6 +1051,10 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
+def note_format_function : Note<"%0 format function">;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0faa5aed4eec3b..44e52c6d81c7c2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4576,6 +4576,8 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..e69ffe8f729fde 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16034,6 +16034,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 6759aae37afac1..a

[clang] [llvm] [RISCV] Inline Assembly: RVC constraint and N modifier (PR #112561)

2024-10-16 Thread Sam Elliott via cfe-commits

https://github.com/lenary created 
https://github.com/llvm/llvm-project/pull/112561

This change implements support for the `cr` and `cf` register constraints 
(which allocate a RVC GPR or RVC FPR respectively), and the `N` modifier (which 
prints the raw encoding of a register rather than the name).

The intention behind these additions is to make it easier to use inline 
assembly when assembling raw instructions that are not supported by the 
compiler, for instance when experimenting with new instructions or when 
supporting proprietary extensions outside the toolchain.

These implement part of my proposal in riscv-non-isa/riscv-c-api-doc#92

As part of the implementation, I felt there was not enough coverage of inline 
assembly and the "in X" floating-point extensions, so I have added more 
regression tests around these configurations.

>From 6d60f09f20d9e8436af95f601256dd9301912028 Mon Sep 17 00:00:00 2001
From: Sam Elliott 
Date: Wed, 16 Oct 2024 05:04:45 -0700
Subject: [PATCH] [RISCV] Inline Assembly: RVC constraint and N modifier

This change implements support for the `cr` and `cf` register
constraints (which allocate a RVC GPR or RVC FPR respectively), and the
`N` modifier (which prints the raw encoding of a register rather than the
name).

The intention behind these additions is to make it easier to use inline
assembly when assembling raw instructions that are not supported by the
compiler, for instance when experimenting with new instructions or when
supporting proprietary extensions outside the toolchain.

These implement part of my proposal in riscv-non-isa/riscv-c-api-doc#92

As part of the implementation, I felt there was not enough coverage of
inline assembly and the "in X" floating-point extensions, so I have
added more regression tests around these configurations.
---
 clang/lib/Basic/Targets/RISCV.cpp |  10 ++
 clang/test/CodeGen/RISCV/riscv-inline-asm.c   |  40 -
 llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp |   9 +
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |  18 ++
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|  19 ++-
 .../RISCV/inline-asm-d-constraint-f.ll|  33 
 .../CodeGen/RISCV/inline-asm-d-modifier-N.ll  | 109 
 .../RISCV/inline-asm-f-constraint-f.ll|  28 +++-
 .../CodeGen/RISCV/inline-asm-f-modifier-N.ll  |  96 +++
 llvm/test/CodeGen/RISCV/inline-asm-invalid.ll |  20 +++
 .../RISCV/inline-asm-zdinx-constraint-r.ll|  92 ++
 .../RISCV/inline-asm-zfh-constraint-f.ll  |  41 +
 .../RISCV/inline-asm-zfh-modifier-N.ll| 157 +
 .../RISCV/inline-asm-zfinx-constraint-r.ll|  89 ++
 .../RISCV/inline-asm-zhinx-constraint-r.ll| 158 ++
 llvm/test/CodeGen/RISCV/inline-asm.ll |  66 
 .../CodeGen/RISCV/zdinx-asm-constraint.ll |  61 +++
 17 files changed, 1041 insertions(+), 5 deletions(-)
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-d-modifier-N.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-f-modifier-N.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zdinx-constraint-r.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zfh-modifier-N.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zfinx-constraint-r.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zhinx-constraint-r.ll

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 870f0f38bc3057..eaaba7642bd7b2 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -100,6 +100,14 @@ bool RISCVTargetInfo::validateAsmConstraint(
   case 'S': // A symbol or label reference with a constant offset
 Info.setAllowsRegister();
 return true;
+  case 'c':
+// A RVC register - GPR or FPR
+if (Name[1] == 'r' || Name[1] == 'f') {
+  Info.setAllowsRegister();
+  Name += 1;
+  return true;
+}
+return false;
   case 'v':
 // A vector register.
 if (Name[1] == 'r' || Name[1] == 'd' || Name[1] == 'm') {
@@ -114,6 +122,8 @@ bool RISCVTargetInfo::validateAsmConstraint(
 std::string RISCVTargetInfo::convertConstraint(const char *&Constraint) const {
   std::string R;
   switch (*Constraint) {
+  // c* and v* are two-letter constraints on RISC-V.
+  case 'c':
   case 'v':
 R = std::string("^") + std::string(Constraint, 2);
 Constraint += 1;
diff --git a/clang/test/CodeGen/RISCV/riscv-inline-asm.c 
b/clang/test/CodeGen/RISCV/riscv-inline-asm.c
index fa0bf6aa6aa471..75b91d3c497c50 100644
--- a/clang/test/CodeGen/RISCV/riscv-inline-asm.c
+++ b/clang/test/CodeGen/RISCV/riscv-inline-asm.c
@@ -3,7 +3,35 @@
 // RUN: %clang_cc1 -triple riscv64 -O2 -emit-llvm %s -o - \
 // RUN: | FileCheck %s
 
-// Test RISC-V specific inline assembly constraints.
+// Test RISC-V specific inline assembly constraints and modifiers.
+
+long test_r(long x) {
+// CHECK-LABEL: define{{.*}} {{i64|i32}} @test_r(
+// CHECK: call {{i64|i32}} asm sideeffect "", "=r,r"(

  1   2   3   4   5   >