[clang] [RISCV] Handle empty structs/unions passing in C++ (PR #97315)

2024-07-08 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> What about the case I have mentioned in https://godbolt.org/z/vdhGbvj6W ?

That test doesn't really prove anything useful.  The zeroing of a0 doesn't have 
any ABI significance: "struct s12" doesn't have any data in it, so the caller 
can't use the value in a0 for anything.  At most, it's a hint about how gcc's 
internal logic works.

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


[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits

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

LGTM, though please let others to take a look too.

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


[clang] [llvm] [RISCV] Remove experimental for bf16 extensions (PR #97996)

2024-07-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jianjian Guan (jacquesguan)


Changes

They are already ratified now.

---

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


307 Files Affected:

- (modified) clang/lib/Sema/SemaRISCV.cpp (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vcreate.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vget.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vle16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vle16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlmul_ext_v.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlmul_trunc_v.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg2ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg3ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg4ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg5ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg6ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg7ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg8ei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlse16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg2e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg2e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg3e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg3e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg4e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg4e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg5e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg5e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg6e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg6e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg7e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg7e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg8e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg8e16ff.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg2e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg3e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg4e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg5e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg6e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg7e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg8e16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxei16.c
 (+2-2) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-aut

[clang] [llvm] [RISCV] Remove experimental for bf16 extensions (PR #97996)

2024-07-08 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 aa9e4f0bc93fc735e83ea8b5269e699f31fb9d28 
26ec7e54f0cfa6bae524c6a6994758f74ecd9c85 -- clang/lib/Sema/SemaRISCV.cpp 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vcreate.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vget.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vle16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vle16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlmul_ext_v.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlmul_trunc_v.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg2ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg3ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg4ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg5ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg6ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg7ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg8ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlse16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg2e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg2e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg3e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg3e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg4e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg4e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg5e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg5e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg6e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg6e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg7e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg7e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg8e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg8e16ff.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg2e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg3e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg4e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg5e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg6e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg7e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg8e16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg2ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg3ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg4ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg5ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg6ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg7ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vluxseg8ei16.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat1

[clang] [llvm] [RISCV] Remove experimental for bf16 extensions (PR #97996)

2024-07-08 Thread Pengcheng Wang via cfe-commits


@@ -271,7 +271,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zalasr``
   LLVM implements the `0.0.5 draft specification 
`__.
 
-``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
+``zfbfmin``, ``zvfbfmin``, ``zvfbfwma``

wangpc-pp wrote:

We should not just remove the `experimental` prefix, these extensions still 
belong to `Experimental Extensions` section.

https://github.com/llvm/llvm-project/pull/97996
___
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 warn on const variables in misc-use-internal-linkage (PR #97969)

2024-07-08 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks! Btw is the check intended to be used in C code as well? (I do not see C 
tests for it). If not, then i can move the logic to the matcher to keep it a 
bit cleaner, and restrict the check to C++ code. 

The warning text mentions anonymous namespaces which would not be applicable in 
C.

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


[clang] [llvm] [SanitizerBinaryMetadata] Fix multi-version sanitizer metadata (PR #97848)

2024-07-08 Thread Fangrui Song via cfe-commits

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


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


[clang] [NFC][clang] Add a release note for `#embed` (PR #97997)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/97997

None

>From 65fbdb7bfc69640b4c9e43ced21eeeb6d3f44c5f Mon Sep 17 00:00:00 2001
From: Mariya Podchishchaeva 
Date: Mon, 8 Jul 2024 09:32:12 +0200
Subject: [PATCH] [NFC][clang] Add a release note for `#embed`

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 838cb69f647ee..69c2ad8be7919 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,9 @@ C23 Feature Support
   but C23 added them to  in
   `WG14 N2848 `_.
 
+- Clang now supports `N3017 
`_
+  ``#embed`` - a scannable, tooling-friendly binary resource inclusion 
mechanism.
+
 Non-comprehensive list of changes in this release
 -
 

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


[clang] [NFC][clang] Add a release note for `#embed` (PR #97997)

2024-07-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes



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


1 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 838cb69f647ee..69c2ad8be7919 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,9 @@ C23 Feature Support
   but C23 added them to  in
   `WG14 N2848 `_.
 
+- Clang now supports `N3017 
`_
+  ``#embed`` - a scannable, tooling-friendly binary resource inclusion 
mechanism.
+
 Non-comprehensive list of changes in this release
 -
 

``




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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/97274

>From 4d5008fcf3ac37fa213c8f2cf42c3cce6369c83d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Thu, 20 Jun 2024 06:04:07 -0700
Subject: [PATCH] [clang] Inject tokens containing #embed back into token
 stream

Instead of playing "whack a mole" with places where #embed should be
expanded as comma-separated list, just inject each byte as a token back
into the stream, separated by commas.
---
 clang/include/clang/Basic/TokenKinds.def|  3 ++
 clang/include/clang/Basic/TokenKinds.h  |  2 +-
 clang/include/clang/Lex/Preprocessor.h  |  5 +-
 clang/include/clang/Parse/Parser.h  |  3 +-
 clang/lib/Parse/ParseExpr.cpp   | 53 ++---
 clang/lib/Parse/ParseTemplate.cpp   | 41 +---
 clang/lib/Sema/SemaExpr.cpp |  6 ++-
 clang/test/Preprocessor/embed_codegen.cpp   |  3 +-
 clang/test/Preprocessor/embed_constexpr.cpp |  3 +-
 clang/test/Preprocessor/embed_weird.cpp | 21 
 10 files changed, 63 insertions(+), 77 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 37d570ca5e75b5..1bc9c59576f336 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -165,6 +165,9 @@ TOK(raw_identifier)  // Used only in raw lexing mode.
 // C99 6.4.4.2: Floating Constants
 TOK(numeric_constant)// 0x123
 
+// Directly holds numerical value. Used to process C23 #embed.
+TOK(binary_data)
+
 // C99 6.4.4: Character Constants
 TOK(char_constant)   // 'a'
 TOK(wide_char_constant)  // L'b'
diff --git a/clang/include/clang/Basic/TokenKinds.h 
b/clang/include/clang/Basic/TokenKinds.h
index e5183a27d2bc5f..1b133dde895876 100644
--- a/clang/include/clang/Basic/TokenKinds.h
+++ b/clang/include/clang/Basic/TokenKinds.h
@@ -98,7 +98,7 @@ inline bool isLiteral(TokenKind K) {
   return K == tok::numeric_constant || K == tok::char_constant ||
  K == tok::wide_char_constant || K == tok::utf8_char_constant ||
  K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
- isStringLiteral(K) || K == tok::header_name;
+ isStringLiteral(K) || K == tok::header_name || K == tok::binary_data;
 }
 
 /// Return true if this is any of tok::annot_* kinds.
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index be3334b9807463..8e30756da2a01b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2123,8 +2123,9 @@ class Preprocessor {
   char
   getSpellingOfSingleCharacterNumericConstant(const Token &Tok,
   bool *Invalid = nullptr) const {
-assert(Tok.is(tok::numeric_constant) &&
-   Tok.getLength() == 1 && "Called on unsupported token");
+assert((Tok.is(tok::numeric_constant) || Tok.is(tok::binary_data)) &&
+Tok.getLength() == 1 &&
+"Called on unsupported token");
 assert(!Tok.needsCleaning() && "Token can't need cleaning with length 1");
 
 // If the token is carrying a literal data pointer, just use it.
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6880fa4bb0b03a..7bc2280764c5bf 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2123,7 +2123,7 @@ class Parser : public CodeCompletionHandler {
   };
   ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
   ExprResult createEmbedExpr();
-  void ExpandEmbedDirective(SmallVectorImpl &Exprs);
+  void injectEmbedTokens();
 
   
//======//
   // clang Expressions
@@ -3830,7 +3830,6 @@ class Parser : public CodeCompletionHandler {
   AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
 ImplicitTypenameContext AllowImplicitTypename,
 bool IsClassName = false);
-  void ExpandEmbedIntoTemplateArgList(TemplateArgList &TemplateArgs);
   bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
  TemplateTy Template, SourceLocation OpenLoc);
   ParsedTemplateArgument ParseTemplateTemplateArgument();
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 9fc3cd73f73a0f..a3b800a35b55ea 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1018,6 +1018,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 
 // primary-expression
   case tok::numeric_constant:
+  case tok::binary_data:
 // constant: integer-constant
 // constant: floating-constant
 
@@ -1067,18 +1068,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   }
 
   case tok::annot_embed: {
-// 

[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits


@@ -43,8 +43,9 @@ a
 };
 
 // CHECK: store i32 107, ptr %b, align 4
-int b =
+int b = (
 #embed
+)

Fznamznon wrote:

In fact, they fix several bugs.

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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

It's been a week. Are we good to go? @cor3ntin 

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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/97274

>From 4d5008fcf3ac37fa213c8f2cf42c3cce6369c83d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Thu, 20 Jun 2024 06:04:07 -0700
Subject: [PATCH 1/2] [clang] Inject tokens containing #embed back into token
 stream

Instead of playing "whack a mole" with places where #embed should be
expanded as comma-separated list, just inject each byte as a token back
into the stream, separated by commas.
---
 clang/include/clang/Basic/TokenKinds.def|  3 ++
 clang/include/clang/Basic/TokenKinds.h  |  2 +-
 clang/include/clang/Lex/Preprocessor.h  |  5 +-
 clang/include/clang/Parse/Parser.h  |  3 +-
 clang/lib/Parse/ParseExpr.cpp   | 53 ++---
 clang/lib/Parse/ParseTemplate.cpp   | 41 +---
 clang/lib/Sema/SemaExpr.cpp |  6 ++-
 clang/test/Preprocessor/embed_codegen.cpp   |  3 +-
 clang/test/Preprocessor/embed_constexpr.cpp |  3 +-
 clang/test/Preprocessor/embed_weird.cpp | 21 
 10 files changed, 63 insertions(+), 77 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 37d570ca5e75b..1bc9c59576f33 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -165,6 +165,9 @@ TOK(raw_identifier)  // Used only in raw lexing mode.
 // C99 6.4.4.2: Floating Constants
 TOK(numeric_constant)// 0x123
 
+// Directly holds numerical value. Used to process C23 #embed.
+TOK(binary_data)
+
 // C99 6.4.4: Character Constants
 TOK(char_constant)   // 'a'
 TOK(wide_char_constant)  // L'b'
diff --git a/clang/include/clang/Basic/TokenKinds.h 
b/clang/include/clang/Basic/TokenKinds.h
index e5183a27d2bc5..1b133dde89587 100644
--- a/clang/include/clang/Basic/TokenKinds.h
+++ b/clang/include/clang/Basic/TokenKinds.h
@@ -98,7 +98,7 @@ inline bool isLiteral(TokenKind K) {
   return K == tok::numeric_constant || K == tok::char_constant ||
  K == tok::wide_char_constant || K == tok::utf8_char_constant ||
  K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
- isStringLiteral(K) || K == tok::header_name;
+ isStringLiteral(K) || K == tok::header_name || K == tok::binary_data;
 }
 
 /// Return true if this is any of tok::annot_* kinds.
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index be3334b980746..8e30756da2a01 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2123,8 +2123,9 @@ class Preprocessor {
   char
   getSpellingOfSingleCharacterNumericConstant(const Token &Tok,
   bool *Invalid = nullptr) const {
-assert(Tok.is(tok::numeric_constant) &&
-   Tok.getLength() == 1 && "Called on unsupported token");
+assert((Tok.is(tok::numeric_constant) || Tok.is(tok::binary_data)) &&
+Tok.getLength() == 1 &&
+"Called on unsupported token");
 assert(!Tok.needsCleaning() && "Token can't need cleaning with length 1");
 
 // If the token is carrying a literal data pointer, just use it.
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6880fa4bb0b03..7bc2280764c5b 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2123,7 +2123,7 @@ class Parser : public CodeCompletionHandler {
   };
   ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
   ExprResult createEmbedExpr();
-  void ExpandEmbedDirective(SmallVectorImpl &Exprs);
+  void injectEmbedTokens();
 
   
//======//
   // clang Expressions
@@ -3830,7 +3830,6 @@ class Parser : public CodeCompletionHandler {
   AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
 ImplicitTypenameContext AllowImplicitTypename,
 bool IsClassName = false);
-  void ExpandEmbedIntoTemplateArgList(TemplateArgList &TemplateArgs);
   bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
  TemplateTy Template, SourceLocation OpenLoc);
   ParsedTemplateArgument ParseTemplateTemplateArgument();
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 9fc3cd73f73a0..a3b800a35b55e 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1018,6 +1018,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 
 // primary-expression
   case tok::numeric_constant:
+  case tok::binary_data:
 // constant: integer-constant
 // constant: floating-constant
 
@@ -1067,18 +1068,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   }
 
   case tok::annot_embed: {
-// We've 

[clang] [llvm] [AIX] Add -msave-reg-params to save arguments to stack (PR #97524)

2024-07-08 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/97524

>From 654cf7753023302c367340872e889856f8738169 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Wed, 3 Jul 2024 14:17:01 +0800
Subject: [PATCH 1/2] [AIX] Add -msave-reg-params to save arguments to stack

In PowerPC ABI, a few initial arguments are passed through registers,
but their places in parameter save area are reserved, arguments passed
by memory goes after the reserved location.

For debugging purpose, we may want to save copy of the pass-by-reg
arguments into correct places on stack. The new option achieves by
adding new function level attribute and make argument lowering part
aware of it.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   3 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/CGCall.cpp  |   3 +
 clang/lib/Driver/ToolChains/AIX.cpp   |   3 +
 clang/test/CodeGen/PowerPC/save-reg-params.c  |  12 +
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp |  20 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  29 +
 .../Target/PowerPC/PPCMachineFunctionInfo.h   |   6 +
 llvm/test/CodeGen/PowerPC/save-reg-params.ll  | 816 ++
 9 files changed, 888 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/save-reg-params.c
 create mode 100644 llvm/test/CodeGen/PowerPC/save-reg-params.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index e3f6da4a84f694..fcf15aa9c400ac 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -425,6 +425,9 @@ CODEGENOPT(ForceAAPCSBitfieldLoad, 1, 0)
 /// Assume that by-value parameters do not alias any other values.
 CODEGENOPT(PassByValueIsNoAlias, 1, 0)
 
+/// Whether to store register parameters to stack.
+CODEGENOPT(SaveRegParams, 1, 0)
+
 /// Whether to not follow the AAPCS that enforces volatile bit-field access 
width to be
 /// according to the field declaring type width.
 CODEGENOPT(AAPCSBitfieldWidth, 1, 1)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1c2b8cfeef6ce6..4135f0db604509 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5040,6 +5040,10 @@ def mspe : Flag<["-"], "mspe">, 
Group;
 def mno_spe : Flag<["-"], "mno-spe">, Group;
 def mefpu2 : Flag<["-"], "mefpu2">, Group;
 } // let Flags = [TargetSpecific]
+def msave_reg_params : Flag<["-"], "msave-reg-params">, Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Save arguments passed by registers to stack">,
+  MarshallingInfoFlag>;
 def mabi_EQ_quadword_atomics : Flag<["-"], "mabi=quadword-atomics">,
   Group, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable quadword atomics ABI on AIX (AIX PPC64 only). Uses 
lqarx/stqcx. instructions.">,
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 2b301130ef7b70..8269755cdbf89d 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1931,6 +1931,9 @@ static void getTrivialDefaultFunctionAttributes(
 if (CodeGenOpts.NullPointerIsValid)
   FuncAttrs.addAttribute(llvm::Attribute::NullPointerIsValid);
 
+if (CodeGenOpts.SaveRegParams)
+  FuncAttrs.addAttribute("save-reg-params");
+
 if (LangOpts.getDefaultExceptionMode() == LangOptions::FPE_Ignore)
   FuncAttrs.addAttribute("no-trapping-math", "true");
 
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index b04502a57a9f7a..c2de7328c25c5d 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -548,6 +548,9 @@ void AIX::addClangTargetOptions(
   options::OPT_mtocdata))
 addTocDataOptions(Args, CC1Args, getDriver());
 
+  if (Args.hasArg(options::OPT_msave_reg_params))
+CC1Args.push_back("-msave-reg-params");
+
   if (Args.hasFlag(options::OPT_fxl_pragma_pack,
options::OPT_fno_xl_pragma_pack, true))
 CC1Args.push_back("-fxl-pragma-pack");
diff --git a/clang/test/CodeGen/PowerPC/save-reg-params.c 
b/clang/test/CodeGen/PowerPC/save-reg-params.c
new file mode 100644
index 00..6599310afa41a3
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/save-reg-params.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s 
-msave-reg-params | FileCheck -check-prefix=SAVE %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -o - %s 
-msave-reg-params | FileCheck -check-prefix=SAVE %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm -o - %s 
-msave-reg-params | FileCheck -check-prefix=SAVE %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck -check-prefix=NOSAVE %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -o - %s | FileCheck 
-check-prefix=NOSAVE %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm -o - %

[clang-tools-extra] Allow unnecessary-value-param to match templated functions including lambdas with auto. (PR #97767)

2024-07-08 Thread Vitaly Goldshteyn via cfe-commits

https://github.com/goldvitaly updated 
https://github.com/llvm/llvm-project/pull/97767

>From 1cf4340d7302e075a8785f23fd383db29cedd590 Mon Sep 17 00:00:00 2001
From: %username% <%userna...@google.com>
Date: Thu, 4 Jul 2024 22:32:19 +0200
Subject: [PATCH 1/5] Allow unnecessary-value-param to match templated
 functions including lambdas with auto.

Clang-Tidy unnecessary-value-param value param will be triggered for
templated functions if at least one instantiontion with expensive to
copy type is present in translation unit.

It is relatively common mistake to write lambda functions with auto
arguments for expensive to copy types.

Example:
Copy of the vectors will happen on every comparison.

void SortBySize(std::vector>& a) {
  std::sort(
  a.begin(), a.end(),
  [](auto x, auto y) { return a.size() < b.size()});
}
---
 .../unnecessary-value-param-templates.cpp | 92 +++
 1 file changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp
new file mode 100644
index 00..4e6ec401f17c81
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy  -std=c++14-or-later %s 
performance-unnecessary-value-param %t
+
+struct ExpensiveToCopyType {
+  virtual ~ExpensiveToCopyType();
+};
+
+template  void templateWithNonTemplatizedParameter(const 
ExpensiveToCopyType S, T V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
+  // CHECK-MESSAGES: [[@LINE-2]]:95: warning: the parameter 'V'
+  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, const T& V) {
+}
+
+void instantiatedWithExpensiveValue() {
+  templateWithNonTemplatizedParameter(
+  ExpensiveToCopyType(), ExpensiveToCopyType());
+  templateWithNonTemplatizedParameter(ExpensiveToCopyType(), 5);
+}
+
+template  void 
templateWithNonTemplatizedParameterCheapTemplate(const ExpensiveToCopyType S, T 
V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:103: warning: the const qualified parameter 
'S'
+  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameterCheapTemplate(const ExpensiveToCopyType& S, 
T V) {
+}
+
+void instantiatedWithCheapValue() {
+  templateWithNonTemplatizedParameterCheapTemplate(ExpensiveToCopyType(), 5);
+}
+
+template  void nonInstantiatedTemplateWithConstValue(const T S) {}
+template  void nonInstantiatedTemplateWithNonConstValue(T S) {}
+
+template  void instantiatedTemplateSpecialization(T NoSpecS) {}
+template <>
+void instantiatedTemplateSpecialization(
+ExpensiveToCopyType SpecS) {
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: the parameter 'SpecS'
+  // CHECK-FIXES: const T& NoSpecS
+  // CHECK-FIXES: const ExpensiveToCopyType& SpecS
+}
+
+void instantiatedTemplateSpecialization() {
+  instantiatedTemplateSpecialization(ExpensiveToCopyType());
+}
+
+template  void instantiatedTemplateWithConstValue(const T S) {
+  // CHECK-MESSAGES: [[@LINE-1]]:71: warning: the const qualified parameter 'S'
+  // CHECK-FIXES: template  void 
instantiatedTemplateWithConstValue(const T& S) {
+}
+
+void instantiatedConstValue() {
+  instantiatedTemplateWithConstValue(ExpensiveToCopyType());
+}
+
+template  void instantiatedTemplateWithNonConstValue(T S) {
+  // CHECK-MESSAGES: [[@LINE-1]]:68: warning: the parameter 'S'
+  // CHECK-FIXES: template  void 
instantiatedTemplateWithNonConstValue(const T& S) {
+}
+
+void instantiatedNonConstValue() {
+  instantiatedTemplateWithNonConstValue(ExpensiveToCopyType());
+}
+
+void lambdaConstValue() {
+  auto fn = [](const ExpensiveToCopyType S) {
+// CHECK-MESSAGES: [[@LINE-1]]:42: warning: the const qualified parameter 
'S'
+// CHECK-FIXES: auto fn = [](const ExpensiveToCopyType& S) {
+  };
+  fn(ExpensiveToCopyType());
+}
+
+void lambdaNonConstValue() {
+  auto fn = [](ExpensiveToCopyType S) {
+// CHECK-MESSAGES: [[@LINE-1]]:36: warning: the parameter 'S'
+// CHECK-FIXES: auto fn = [](const ExpensiveToCopyType& S) {
+  };
+  fn(ExpensiveToCopyType());
+}
+
+void lambdaConstAutoValue() {
+  auto fn = [](const auto S) {
+// CHECK-MESSAGES: [[@LINE-1]]:27: warning: the const qualified parameter 
'S'
+// CHECK-FIXES: auto fn = [](const auto& S) {
+  };
+  fn(ExpensiveToCopyType());
+}
+
+void lambdaNonConstAutoValue() {
+  auto fn = [](auto S) {
+// CHECK-MESSAGES: [[@LINE-1]]:21: warning: the parameter 'S'
+// CHECK-FIXES: auto fn = [](const auto& S) {
+  };
+  fn(ExpensiveToCopyType());
+}

>From 593b3363de0f7fd4ec378ac183bf1f160cb9e613 Mon Sep 17 00:00:00 2001
From: %username% <%userna...@google.com>
Date: Thu, 4 Jul 2024 22:32:19 +0200
Subject: [PATCH 2/5] Allow unnecessary-value-para

[clang-tools-extra] Allow unnecessary-value-param to match templated functions including lambdas with auto. (PR #97767)

2024-07-08 Thread Vitaly Goldshteyn via cfe-commits


@@ -0,0 +1,93 @@
+// RUN: %check_clang_tidy  -std=c++14-or-later %s 
performance-unnecessary-value-param %t
+
+struct ExpensiveToCopyType {
+  virtual ~ExpensiveToCopyType();
+};
+
+template  void templateWithNonTemplatizedParameter(const 
ExpensiveToCopyType S, T V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
+  // CHECK-MESSAGES: [[@LINE-2]]:95: warning: the parameter 'V'
+  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, const T& V) {
+}
+
+void instantiatedWithExpensiveValue() {
+  templateWithNonTemplatizedParameter(
+  ExpensiveToCopyType(), ExpensiveToCopyType());
+  templateWithNonTemplatizedParameter(ExpensiveToCopyType(), 5);
+}
+
+template  void 
templateWithNonTemplatizedParameterCheapTemplate(const ExpensiveToCopyType S, T 
V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:103: warning: the const qualified parameter 
'S'
+  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameterCheapTemplate(const ExpensiveToCopyType& S, 
T V) {
+}
+
+void instantiatedWithCheapValue() {
+  templateWithNonTemplatizedParameterCheapTemplate(ExpensiveToCopyType(), 5);
+}
+
+template  void nonInstantiatedTemplateWithConstValue(const T S) {}
+template  void nonInstantiatedTemplateWithNonConstValue(T S) {}
+
+template  void instantiatedTemplateSpecialization(T NoSpecS) {}
+template <>
+void instantiatedTemplateSpecialization(
+ExpensiveToCopyType SpecS) {
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: the parameter 'SpecS'
+  // When updating a template specialization, we also update the main template.

goldvitaly wrote:

I have found a partial fix for this issue (and created fixup commit).

The changes are:
1. No fixes are proposed for explicit specializations.
2. Fixes are still proposed for the main template in case warning is issued 
during instantiation of the main template. I couldn't find the way to find that 
any instantiation is available. And in case they are defined in another 
translation unit, there is no way to do it.


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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -1520,10 +1520,14 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, 
const ArgList &Args,
 }
 
 bool tools::addXRayRuntime(const ToolChain&TC, const ArgList &Args, 
ArgStringList &CmdArgs) {
-  if (Args.hasArg(options::OPT_shared))
-return false;
-
-  if (TC.getXRayArgs().needsXRayRt()) {
+  if (Args.hasArg(options::OPT_shared)) {
+if (TC.getXRayArgs().needsXRayDSORt()) {
+  CmdArgs.push_back("-whole-archive");

sebastiankreutzer wrote:

This is a typo, I will add the missing dashes. 

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


[clang] [RISCV] Handle empty structs/unions passing in C++ (PR #97315)

2024-07-08 Thread Sudharsan Veeravalli via cfe-commits

https://github.com/svs-quic updated 
https://github.com/llvm/llvm-project/pull/97315

>From 3c744fe6111f0b6d24356a584f94c6d1cb273f7a Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Mon, 1 Jul 2024 21:58:37 +0530
Subject: [PATCH 1/4] [RISCV] Handle empty structs/unions passing in C++

---
 clang/lib/CodeGen/Targets/RISCV.cpp  |  9 +++---
 clang/test/CodeGen/RISCV/abi-empty-structs.c | 34 
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index a4c5ec315b8df..f2add9351c03c 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -361,12 +361,13 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType 
Ty, bool IsFixed,
CGCXXABI::RAA_DirectInMemory);
   }
 
-  // Ignore empty structs/unions.
-  if (isEmptyRecord(getContext(), Ty, true))
-return ABIArgInfo::getIgnore();
-
   uint64_t Size = getContext().getTypeSize(Ty);
 
+  // Ignore empty structs/unions whose size is zero. According to the calling
+  // convention empty structs/unions are required to be sized types in C++.
+  if (isEmptyRecord(getContext(), Ty, true) && Size == 0)
+return ABIArgInfo::getIgnore();
+
   // Pass floating point values via FPRs if possible.
   if (IsFixed && Ty->isFloatingType() && !Ty->isComplexType() &&
   FLen >= Size && ArgFPRsLeft) {
diff --git a/clang/test/CodeGen/RISCV/abi-empty-structs.c 
b/clang/test/CodeGen/RISCV/abi-empty-structs.c
index c48a2891627d4..877ed4962d4e8 100644
--- a/clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ b/clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -167,6 +167,40 @@ struct s9 {
 //
 void test_s9(struct s9 a) {}
 
+struct s10 { };
+// CHECK-C-LABEL: define dso_local void @test_s10
+// CHECK-C-SAME: () #[[ATTR0]] {
+// CHECK-C:  entry:
+//
+// CHECK32-CXX-LABEL: define dso_local i32 @_Z8test_s103s10
+// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK32-CXX:  entry:
+//
+// CHECK64-CXX-LABEL: define dso_local i64 @_Z8test_s103s10
+// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK64-CXX:  entry:
+//
+struct s10 test_s10(struct s10 a) {
+  return a;
+}
+
+struct s11 { int : 0; };
+// CHECK-C-LABEL: define dso_local void @test_s11
+// CHECK-C-SAME: () #[[ATTR0]] {
+// CHECK-C:  entry:
+//
+// CHECK32-CXX-LABEL: define dso_local i32 @_Z8test_s113s11
+// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK32-CXX:  entry:
+//
+// CHECK64-CXX-LABEL: define dso_local i64 @_Z8test_s113s11
+// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK64-CXX:  entry:
+//
+struct s11 test_s11(struct s11 a) {
+  return a;
+}
+
  NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
 // CHECK32-C: {{.*}}
 // CHECK64-C: {{.*}}

>From 004881e8b3453532bd5253e36a7c75b125784eda Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Thu, 4 Jul 2024 08:57:37 +0530
Subject: [PATCH 2/4] Add test case

---
 clang/test/CodeGen/RISCV/abi-empty-structs.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/clang/test/CodeGen/RISCV/abi-empty-structs.c 
b/clang/test/CodeGen/RISCV/abi-empty-structs.c
index 877ed4962d4e8..fd119fbda046d 100644
--- a/clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ b/clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -201,6 +201,19 @@ struct s11 test_s11(struct s11 a) {
   return a;
 }
 
+struct s12 {int x[0];};
+// CHECK-C-LABEL: define dso_local void @test_s12
+// CHECK-C-SAME: () #[[ATTR0]] {
+// CHECK-C:  entry:
+//
+// CHECK-CXX-LABEL: define dso_local void @_Z8test_s123s12
+// CHECK-CXX-SAME: () #[[ATTR0]] {
+// CHECK-CXX:  entry:
+//
+struct s12 test_s12(struct s12 a) {
+  return a;
+}
+
  NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
 // CHECK32-C: {{.*}}
 // CHECK64-C: {{.*}}

>From d6b523c859218ca1c982b289de269bc828087701 Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Sat, 6 Jul 2024 09:54:49 +0530
Subject: [PATCH 3/4] Change check and add release notes

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/lib/CodeGen/Targets/RISCV.cpp  |  3 ++-
 clang/test/CodeGen/RISCV/abi-empty-structs.c | 10 +++---
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 90c2469c1c89a..53ff40b1afef7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1061,6 +1061,7 @@ RISC-V Support
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
 - Profile names in ``-march`` option are now supported.
+- Passing empty structs/unions as arguments in C++ is now handled correctly. 
The behavior is similar to GCC's.
 
 CUDA/HIP Language Changes
 ^
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
inde

[clang] [RISCV] Handle empty structs/unions passing in C++ (PR #97315)

2024-07-08 Thread Sudharsan Veeravalli via cfe-commits

svs-quic wrote:

Thanks. I have modified the check and added a relevant test for empty arrays.

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -346,8 +392,8 @@ else() # not Apple
   DEFS ${XRAY_COMMON_DEFINITIONS}
   OBJECT_LIBS RTXrayBASIC
   PARENT_TARGET xray)
-   # Profiler Mode runtime
-   add_compiler_rt_runtime(clang_rt.xray-profiling
+# Profiler Mode runtime
+add_compiler_rt_runtime(clang_rt.xray-profiling

sebastiankreutzer wrote:

The indentation was inconsistent here so I've added the whitespaces to match 
the previous blocks.
Should I revert this change?

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


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread Rainer Orth via cfe-commits

https://github.com/rorth created https://github.com/llvm/llvm-project/pull/98001

At the end of the recent flurry of Illumos (and implicitly Solaris) safestack 
patches, the tests were disabled in
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc without explanation.

After re-enabling them, there were many problems on Solaris:

- Every single testcase failed to link:

  ``` Undefined first referenced
   symbol   in file
  __safestack_unsafe_stack_ptrbuffer-copy-vla.o
  __safestack_init(command line)
  ld: fatal: symbol referencing errors
  ```

  The problem is that `-u __safestack_init` was passed to the linker after the 
corresponding version of `libclang_rt.safestack-*.a`.  Since the Solaris linker 
(like Unix linkers for decades) respects the command line argument order 
(unlike e.g. GNU ld which uses GNU getopt), this cannot work.  Fixed by moving 
the `-u` arg further to the front.  Two affected testcases were adjusted 
accordingly.

* While 540fd42c755f20f7b79c6c79493ec36d8cb9b3d3 enabled safestack on Solaris 
unconditionally, it ignored that Solaris also exists on SPARC and forgot to 
enable SPARC support.  This patch fixes that.

- Afterwards, the tests still fail to link with undefined references to 
`__sanitizer_internal_memset` etc.  These are from 
`sanitizer_redefine_builtins.h`.  Definitions live in `sanitizer_libc.cpp.o` 
and were added to the safestack runtime lib as is already the case e.g. for 
asan and ubsan.  Why GNU ld allows the link to complete with those symbols 
undefined is beyond me.

- The `pthread*.c` tests `FAIL` with

  ``` safestack CHECK failed: 
/vol/llvm/src/llvm-project/local/compiler-rt/lib/safestack/safestack.cpp:227 
size ```

  The problem is that `pthread_attr_init` initializes the `stacksize` attribute 
to 0, signifying the default.  Unless explicitly overridded, it stays that way. 
 I think this is allowed by XPG7.  Since safestack cannot deal with this, I set 
`size` to the defaults documented in `pthread_create(3C)`.  Unfortunately, 
there's no macro for those values outside of private `libc` headers.

- The Solaris `syscall` interface isn't stable.  This is not just a theoretical 
concern, but the syscalls have changed incompatibly several times in the past.  
Therefore this patch switches the implementations of `TgKill` (where 
`SYS_lwp_kill` doesn't exist on Solaris 11.4 anyway), `Mmap`, `Munmap`, and 
`Mprotect` to the same `_REAL*` solution already used in 
`sanitizer_solaris.cpp`.  Instead of duplicating what's already in 
`sanitizer_common`, it seems way better to me to just reuse those 
implementations, though.  A subsequent patch does just that.

With those changes, safestack compiles and all tests `PASS`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, 
`x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`.

>From f8de9c3c2dbde4021f0d32a55c8a385221c0f749 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Mon, 8 Jul 2024 10:28:42 +0200
Subject: [PATCH] [safestack] Various Solaris fixes

At the end of the recent flurry of Illumos (and implicitly Solaris)
safestack patches, the tests were disabled in
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc without explanation.

After re-enabling them, there were many problems on Solaris:

- Every single testcase failed to link:

  ```
  Undefined first referenced
   symbol   in file
  __safestack_unsafe_stack_ptrbuffer-copy-vla.o
  __safestack_init(command line)
  ld: fatal: symbol referencing errors
  ```

  The problem is that `-u __safestack_init` was passed to the linker after
  the corresponding version of `libclang_rt.safestack-*.a`.  Since the
  Solaris linker (like Unix linkers for decades) respects the command line
  argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot
  work.  Fixed by moving the `-u` arg further to the front.  Two affected
  testcases were fixed accordingly.

* While 540fd42c755f20f7b79c6c79493ec36d8cb9b3d3 enabled safestack on
  Solaris unconditionally, it ignored that Solaris also exists on SPARC and
  forgot to enable SPARC support.  This patch fixes that.

- Afterwards, the tests still fail to link with undefined references to
  `__sanitizer_internal_memset` etc.  These are from
  `sanitizer_redefine_builtins.h`.  Definitions live in
  `sanitizer_libc.cpp.o` and were added to the safestack runtime lib as is
  already the case e.g. for asan and ubsan.  Why GNU ld allows the link to
  complete with those undefined is beyond me.

- The `pthread*.c` tests `FAIL` with

  ```
  safestack CHECK failed: 
/vol/llvm/src/llvm-project/local/compiler-rt/lib/safestack/safestack.cpp:227 
size
  ```

  The problem is that `pthread_attr_init` initializes the `stacksize`
  attribute to 0, signifying the default.  Unless explicitly overridded, it
  stays that way.  I think this is allowed by XPG7.  Since safestack cannot
  deal with this, I set 

[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -0,0 +1,62 @@
+//===-- xray_init.cpp ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// XRay initialisation logic for DSOs.
+//===--===//
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "xray_defs.h"
+#include "xray_flags.h"
+#include "xray_interface_internal.h"
+
+using namespace __sanitizer;
+
+extern "C" {
+extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+
+#if SANITIZER_MAC

sebastiankreutzer wrote:

This check was adopted from `compiler-rt/lib/xray/xray_init.cpp` (although I 
just noticed `SANITIZER_MAC` was recently changed to `SANITIZER_APPLE` 
throughout the project and needs updating).

Should I still update it as suggested?

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


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Rainer Orth (rorth)


Changes

At the end of the recent flurry of Illumos (and implicitly Solaris) safestack 
patches, the tests were disabled in
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc without explanation.

After re-enabling them, there were many problems on Solaris:

- Every single testcase failed to link:

  ``` Undefined first referenced
   symbol   in file
  __safestack_unsafe_stack_ptrbuffer-copy-vla.o
  __safestack_init(command line)
  ld: fatal: symbol referencing errors
  ```

  The problem is that `-u __safestack_init` was passed to the linker after the 
corresponding version of `libclang_rt.safestack-*.a`.  Since the Solaris linker 
(like Unix linkers for decades) respects the command line argument order 
(unlike e.g. GNU ld which uses GNU getopt), this cannot work.  Fixed by moving 
the `-u` arg further to the front.  Two affected testcases were adjusted 
accordingly.

* While 540fd42c755f20f7b79c6c79493ec36d8cb9b3d3 enabled safestack on Solaris 
unconditionally, it ignored that Solaris also exists on SPARC and forgot to 
enable SPARC support.  This patch fixes that.

- Afterwards, the tests still fail to link with undefined references to 
`__sanitizer_internal_memset` etc.  These are from 
`sanitizer_redefine_builtins.h`.  Definitions live in `sanitizer_libc.cpp.o` 
and were added to the safestack runtime lib as is already the case e.g. for 
asan and ubsan.  Why GNU ld allows the link to complete with those symbols 
undefined is beyond me.

- The `pthread*.c` tests `FAIL` with

  ``` safestack CHECK failed: 
/vol/llvm/src/llvm-project/local/compiler-rt/lib/safestack/safestack.cpp:227 
size ```

  The problem is that `pthread_attr_init` initializes the `stacksize` attribute 
to 0, signifying the default.  Unless explicitly overridded, it stays that way. 
 I think this is allowed by XPG7.  Since safestack cannot deal with this, I set 
`size` to the defaults documented in `pthread_create(3C)`.  Unfortunately, 
there's no macro for those values outside of private `libc` headers.

- The Solaris `syscall` interface isn't stable.  This is not just a theoretical 
concern, but the syscalls have changed incompatibly several times in the past.  
Therefore this patch switches the implementations of `TgKill` (where 
`SYS_lwp_kill` doesn't exist on Solaris 11.4 anyway), `Mmap`, `Munmap`, and 
`Mprotect` to the same `_REAL*` solution already used in 
`sanitizer_solaris.cpp`.  Instead of duplicating what's already in 
`sanitizer_common`, it seems way better to me to just reuse those 
implementations, though.  A subsequent patch does just that.

With those changes, safestack compiles and all tests `PASS`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, 
`x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`.

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


8 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+6-4) 
- (modified) clang/test/Driver/ohos.c (+1-1) 
- (modified) clang/test/Driver/sanitizer-ld.c (+1-1) 
- (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+1-1) 
- (modified) compiler-rt/lib/safestack/CMakeLists.txt (+2) 
- (modified) compiler-rt/lib/safestack/safestack.cpp (+11) 
- (modified) compiler-rt/lib/safestack/safestack_platform.h (+28-7) 
- (modified) compiler-rt/test/safestack/lit.cfg.py (+1-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index c56a0c2c46c47..fd70398027be9 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1543,6 +1543,12 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, 
const ArgList &Args,
  RequiredSymbols);
   }
 
+  // -u options must be added before the runtime libs that resolve them.
+  for (auto S : RequiredSymbols) {
+CmdArgs.push_back("-u");
+CmdArgs.push_back(Args.MakeArgString(S));
+  }
+
   // Inject libfuzzer dependencies.
   if (SanArgs.needsFuzzer() && SanArgs.linkRuntimes() &&
   !Args.hasArg(options::OPT_shared)) {
@@ -1575,10 +1581,6 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, 
const ArgList &Args,
 addSanitizerRuntime(TC, Args, CmdArgs, RT, false, false);
 AddExportDynamic |= !addSanitizerDynamicList(TC, Args, CmdArgs, RT);
   }
-  for (auto S : RequiredSymbols) {
-CmdArgs.push_back("-u");
-CmdArgs.push_back(Args.MakeArgString(S));
-  }
   // If there is a static runtime with no dynamic list, force all the symbols
   // to be dynamic to be sure we export sanitizer interface functions.
   if (AddExportDynamic)
diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c
index b1ce61e7227b6..8de4e6de57f7f 100644
--- a/clang/test/Driver/ohos.c
+++ b/clang/test/Driver/ohos.c
@@ -95,8 +95,8 @@
 // RUN: | FileCheck %s -check-prefix=CHEC

[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread Rainer Orth via cfe-commits

rorth wrote:

The mentioned patch to switch safestack to use the `sanitizer_common` functions 
instead of their own ones in `sanitizer_platform.h` has to wait until this one 
is approved: AFAIT github doesn't support stacked pull requests.

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


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 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 d6af73e9fbc84315100499a096f17ec5ea23 
f8de9c3c2dbde4021f0d32a55c8a385221c0f749 -- 
clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/ohos.c 
clang/test/Driver/sanitizer-ld.c compiler-rt/lib/safestack/safestack.cpp 
compiler-rt/lib/safestack/safestack_platform.h
``





View the diff from clang-format here.


``diff
diff --git a/compiler-rt/lib/safestack/safestack_platform.h 
b/compiler-rt/lib/safestack/safestack_platform.h
index 77eeb9cda6..27e29d6ead 100644
--- a/compiler-rt/lib/safestack/safestack_platform.h
+++ b/compiler-rt/lib/safestack/safestack_platform.h
@@ -13,9 +13,6 @@
 #ifndef SAFESTACK_PLATFORM_H
 #define SAFESTACK_PLATFORM_H
 
-#include "safestack_util.h"
-#include "sanitizer_common/sanitizer_platform.h"
-
 #include 
 #include 
 #include 
@@ -26,6 +23,9 @@
 #include 
 #include 
 
+#include "safestack_util.h"
+#include "sanitizer_common/sanitizer_platform.h"
+
 #if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || \
   SANITIZER_SOLARIS)
 #  error "Support for your platform has not been implemented"

``




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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -50,14 +52,72 @@ atomic_uint8_t XRayInitialized{0};
 
 // This should always be updated before XRayInitialized is updated.
 SpinMutex XRayInstrMapMutex;
-XRaySledMap XRayInstrMap;
+// XRaySledMap XRayInstrMap;
+//  Contains maps for the main executable as well as DSOs.
+// std::vector XRayInstrMaps;

sebastiankreutzer wrote:

Will do

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -111,6 +156,71 @@ void __xray_init() XRAY_NEVER_INSTRUMENT {
 #endif
 }
 
+// Default visibility is hidden, so we have to explicitly make it visible to
+// DSO.
+SANITIZER_INTERFACE_ATTRIBUTE int32_t __xray_register_dso(
+const XRaySledEntry *SledsBegin, const XRaySledEntry *SledsEnd,
+const XRayFunctionSledIndex *FnIndexBegin,
+const XRayFunctionSledIndex *FnIndexEnd,
+XRayTrampolines Trampolines) XRAY_NEVER_INSTRUMENT {
+  // Make sure XRay has been initialized in the main executable.
+  __xray_init();
+
+  if (__xray_num_objects() == 0) {
+if (Verbosity())
+  Report("No XRay instrumentation map in main executable. Not initializing 
"
+ "XRay for DSO.\n");
+return -1;
+  }
+
+  // Register sleds in global map.
+  int ObjId = __xray_register_sleds(SledsBegin, SledsEnd, FnIndexBegin,
+ FnIndexEnd, true, Trampolines);
+
+#ifndef XRAY_NO_PREINIT
+  if (ObjId >= 0 && flags()->patch_premain)
+__xray_patch_object(ObjId);
+#endif
+
+  return ObjId;
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE bool
+__xray_deregister_dso(int32_t ObjId) XRAY_NEVER_INSTRUMENT {
+  // Make sure XRay has been initialized in the main executable.
+  __xray_init();
+
+  if (ObjId <= 0 || ObjId >= __xray_num_objects()) {
+if (Verbosity())
+  Report("Can't deregister object with ID %d: ID is invalid.\n", ObjId);
+return false;
+  }
+
+  {
+SpinMutexLock Guard(&XRayInstrMapMutex);
+auto &Entry = XRayInstrMaps[ObjId];
+if (!Entry.FromDSO) {
+  if (Verbosity())
+Report("Can't deregister object with ID %d: object does not correspond 
"
+   "to a shared library.\n",
+   ObjId);
+  return false;
+}
+if (!Entry.Loaded) {
+  if (Verbosity())
+Report("Can't deregister object with ID %d: object is not loaded.\n",
+   ObjId);

sebastiankreutzer wrote:

I see your point. I will adjust it to only report the debug message and return 
true.
I will also add some documentation for the return values.

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


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread Rainer Orth via cfe-commits

rorth wrote:

> ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️
> You can test this locally with the following command:
> View the diff from clang-format here.
> 
> ```diff
> diff --git a/compiler-rt/lib/safestack/safestack_platform.h 
> b/compiler-rt/lib/safestack/safestack_platform.h
> index 77eeb9cda6..27e29d6ead 100644
> --- a/compiler-rt/lib/safestack/safestack_platform.h
> +++ b/compiler-rt/lib/safestack/safestack_platform.h
> @@ -13,9 +13,6 @@
>  #ifndef SAFESTACK_PLATFORM_H
>  #define SAFESTACK_PLATFORM_H
>  
> -#include "safestack_util.h"
> -#include "sanitizer_common/sanitizer_platform.h"
> -
>  #include 
>  #include 
>  #include 
> @@ -26,6 +23,9 @@
>  #include 
>  #include 
>  
> +#include "safestack_util.h"
> +#include "sanitizer_common/sanitizer_platform.h"
> +
>  #if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || \
>SANITIZER_SOLARIS)
>  #  error "Support for your platform has not been implemented"
> ```

I had seen that when running `clang-format-diff.py`, but chose to ignore that 
because it seems unrelated and even somewhat dangerous: there are often cases 
where you need to define some macro **before** including system headers.

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


[clang] [llvm] [RISCV] Remove experimental for bf16 extensions (PR #97996)

2024-07-08 Thread Jianjian Guan via cfe-commits


@@ -271,7 +271,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zalasr``
   LLVM implements the `0.0.5 draft specification 
`__.
 
-``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
+``zfbfmin``, ``zvfbfmin``, ``zvfbfwma``

jacquesguan wrote:

Fixed, move these extensions to the supported list.

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


[clang-tools-extra] Allow unnecessary-value-param to match templated functions including lambdas with auto. (PR #97767)

2024-07-08 Thread Vitaly Goldshteyn via cfe-commits

https://github.com/goldvitaly updated 
https://github.com/llvm/llvm-project/pull/97767

>From 1cf4340d7302e075a8785f23fd383db29cedd590 Mon Sep 17 00:00:00 2001
From: %username% <%userna...@google.com>
Date: Thu, 4 Jul 2024 22:32:19 +0200
Subject: [PATCH 1/6] Allow unnecessary-value-param to match templated
 functions including lambdas with auto.

Clang-Tidy unnecessary-value-param value param will be triggered for
templated functions if at least one instantiontion with expensive to
copy type is present in translation unit.

It is relatively common mistake to write lambda functions with auto
arguments for expensive to copy types.

Example:
Copy of the vectors will happen on every comparison.

void SortBySize(std::vector>& a) {
  std::sort(
  a.begin(), a.end(),
  [](auto x, auto y) { return a.size() < b.size()});
}
---
 .../unnecessary-value-param-templates.cpp | 92 +++
 1 file changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp
new file mode 100644
index 00..4e6ec401f17c81
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-templates.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy  -std=c++14-or-later %s 
performance-unnecessary-value-param %t
+
+struct ExpensiveToCopyType {
+  virtual ~ExpensiveToCopyType();
+};
+
+template  void templateWithNonTemplatizedParameter(const 
ExpensiveToCopyType S, T V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
+  // CHECK-MESSAGES: [[@LINE-2]]:95: warning: the parameter 'V'
+  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, const T& V) {
+}
+
+void instantiatedWithExpensiveValue() {
+  templateWithNonTemplatizedParameter(
+  ExpensiveToCopyType(), ExpensiveToCopyType());
+  templateWithNonTemplatizedParameter(ExpensiveToCopyType(), 5);
+}
+
+template  void 
templateWithNonTemplatizedParameterCheapTemplate(const ExpensiveToCopyType S, T 
V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:103: warning: the const qualified parameter 
'S'
+  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameterCheapTemplate(const ExpensiveToCopyType& S, 
T V) {
+}
+
+void instantiatedWithCheapValue() {
+  templateWithNonTemplatizedParameterCheapTemplate(ExpensiveToCopyType(), 5);
+}
+
+template  void nonInstantiatedTemplateWithConstValue(const T S) {}
+template  void nonInstantiatedTemplateWithNonConstValue(T S) {}
+
+template  void instantiatedTemplateSpecialization(T NoSpecS) {}
+template <>
+void instantiatedTemplateSpecialization(
+ExpensiveToCopyType SpecS) {
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: the parameter 'SpecS'
+  // CHECK-FIXES: const T& NoSpecS
+  // CHECK-FIXES: const ExpensiveToCopyType& SpecS
+}
+
+void instantiatedTemplateSpecialization() {
+  instantiatedTemplateSpecialization(ExpensiveToCopyType());
+}
+
+template  void instantiatedTemplateWithConstValue(const T S) {
+  // CHECK-MESSAGES: [[@LINE-1]]:71: warning: the const qualified parameter 'S'
+  // CHECK-FIXES: template  void 
instantiatedTemplateWithConstValue(const T& S) {
+}
+
+void instantiatedConstValue() {
+  instantiatedTemplateWithConstValue(ExpensiveToCopyType());
+}
+
+template  void instantiatedTemplateWithNonConstValue(T S) {
+  // CHECK-MESSAGES: [[@LINE-1]]:68: warning: the parameter 'S'
+  // CHECK-FIXES: template  void 
instantiatedTemplateWithNonConstValue(const T& S) {
+}
+
+void instantiatedNonConstValue() {
+  instantiatedTemplateWithNonConstValue(ExpensiveToCopyType());
+}
+
+void lambdaConstValue() {
+  auto fn = [](const ExpensiveToCopyType S) {
+// CHECK-MESSAGES: [[@LINE-1]]:42: warning: the const qualified parameter 
'S'
+// CHECK-FIXES: auto fn = [](const ExpensiveToCopyType& S) {
+  };
+  fn(ExpensiveToCopyType());
+}
+
+void lambdaNonConstValue() {
+  auto fn = [](ExpensiveToCopyType S) {
+// CHECK-MESSAGES: [[@LINE-1]]:36: warning: the parameter 'S'
+// CHECK-FIXES: auto fn = [](const ExpensiveToCopyType& S) {
+  };
+  fn(ExpensiveToCopyType());
+}
+
+void lambdaConstAutoValue() {
+  auto fn = [](const auto S) {
+// CHECK-MESSAGES: [[@LINE-1]]:27: warning: the const qualified parameter 
'S'
+// CHECK-FIXES: auto fn = [](const auto& S) {
+  };
+  fn(ExpensiveToCopyType());
+}
+
+void lambdaNonConstAutoValue() {
+  auto fn = [](auto S) {
+// CHECK-MESSAGES: [[@LINE-1]]:21: warning: the parameter 'S'
+// CHECK-FIXES: auto fn = [](const auto& S) {
+  };
+  fn(ExpensiveToCopyType());
+}

>From 593b3363de0f7fd4ec378ac183bf1f160cb9e613 Mon Sep 17 00:00:00 2001
From: %username% <%userna...@google.com>
Date: Thu, 4 Jul 2024 22:32:19 +0200
Subject: [PATCH 2/6] Allow unnecessary-value-para

[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-08 Thread Younan Zhang via cfe-commits


@@ -372,6 +374,292 @@ maybeDropCxxExplicitObjectParameters(ArrayRef Params) {
   return Params;
 }
 
+class TypeInlayHintLabelPartBuilder
+: public TypeVisitor {
+  QualType CurrentType;
+  NestedNameSpecifier *CurrentNestedNameSpecifier;
+  ASTContext &Context;
+  StringRef MainFilePath;
+  const PrintingPolicy &PP;
+  SourceManager &SM;
+  std::vector &LabelChunks;
+
+  struct CurrentTypeRAII {
+TypeInlayHintLabelPartBuilder &Builder;
+QualType PreviousType;
+NestedNameSpecifier *PreviousNestedNameSpecifier;
+CurrentTypeRAII(TypeInlayHintLabelPartBuilder &Builder, QualType New,
+NestedNameSpecifier *NNS = nullptr)
+: Builder(Builder), PreviousType(Builder.CurrentType),
+  PreviousNestedNameSpecifier(Builder.CurrentNestedNameSpecifier) {
+  Builder.CurrentType = New;
+  if (NNS)
+Builder.CurrentNestedNameSpecifier = NNS;
+}
+~CurrentTypeRAII() {
+  Builder.CurrentType = PreviousType;
+  Builder.CurrentNestedNameSpecifier = PreviousNestedNameSpecifier;
+}
+  };
+
+  void addLabel(llvm::function_ref NamePrinter,
+llvm::function_ref SourceLocationGetter) {
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+NamePrinter(OS);
+auto &Name = LabelChunks.emplace_back();
+Name.value = std::move(Label);
+Name.location = makeLocation(Context, SourceLocationGetter(), 
MainFilePath);
+  }
+
+  void addLabel(std::string Label) {
+if (LabelChunks.empty()) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+auto &Back = LabelChunks.back();
+if (Back.location) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+// Let's combine the "unclickable" pieces together.
+Back.value += std::move(Label);
+  }
+
+  void printTemplateArgumentList(llvm::ArrayRef Args) {
+unsigned Size = Args.size();
+for (unsigned I = 0; I < Size; ++I) {
+  auto &TA = Args[I];
+  if (PP.SuppressDefaultTemplateArgs && TA.getIsDefaulted())
+continue;
+  if (I)
+addLabel(", ");
+  printTemplateArgument(TA);
+}
+  }
+
+  void printTemplateArgument(const TemplateArgument &TA) {
+switch (TA.getKind()) {
+case TemplateArgument::Pack:
+  return printTemplateArgumentList(TA.pack_elements());
+case TemplateArgument::Type: {
+  CurrentTypeRAII Guard(*this, TA.getAsType());
+  return Visit(TA.getAsType().getTypePtr());
+}
+// TODO: Add support for NTTP arguments.
+case TemplateArgument::Expression:
+case TemplateArgument::StructuralValue:
+case TemplateArgument::Null:
+case TemplateArgument::Declaration:
+case TemplateArgument::NullPtr:
+case TemplateArgument::Integral:
+case TemplateArgument::Template:
+case TemplateArgument::TemplateExpansion:
+  break;
+}
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+TA.print(PP, OS, /*IncludeType=*/true);
+addLabel(std::move(Label));
+  }
+
+  void handleTemplateSpecialization(
+  TemplateName TN, llvm::ArrayRef Args,
+  SourceLocation TemplateNameLocation = SourceLocation()) {
+SourceLocation Location;
+TemplateDecl *TD = nullptr;
+auto PrintType = TemplateName::Qualified::AsWritten;
+switch (TN.getKind()) {
+case TemplateName::Template:
+  TD = TN.getAsTemplateDecl();
+  Location = nameLocation(*TD, SM);
+  break;
+case TemplateName::QualifiedTemplate:
+  if (NestedNameSpecifier *NNS =
+  TN.getAsQualifiedTemplateName()->getQualifier();
+  NNS == CurrentNestedNameSpecifier) {
+// We have handled the NNS in VisitElaboratedType(). Avoid printing it
+// twice.
+TN = TN.getAsQualifiedTemplateName()->getUnderlyingTemplate();
+PrintType = TemplateName::Qualified::None;
+  }
+  break;
+case TemplateName::OverloadedTemplate:
+case TemplateName::AssumedTemplate:
+case TemplateName::DependentTemplate:
+case TemplateName::SubstTemplateTemplateParm:
+case TemplateName::SubstTemplateTemplateParmPack:
+case TemplateName::UsingTemplate:
+  break;
+}
+
+addLabel([&](llvm::raw_ostream &OS) { TN.print(OS, PP, PrintType); },
+ [&] {
+   if (TemplateNameLocation.isValid())
+ return TemplateNameLocation;
+   return Location;
+ });
+
+addLabel("<");
+printTemplateArgumentList(Args);
+addLabel(">");
+  }
+
+  void maybeAddQualifiers() {
+auto Quals = CurrentType.split().Quals;
+if (!Quals.empty()) {
+  addLabel(Quals.getAsString());
+  addLabel(" ");
+}
+  }
+
+  // When printing a reference, the referenced type might also be a reference.
+  // If so, we want to skip that before printing the inner type.
+  static QualType skipTopLevelReferences(QualType T) {
+if (auto *Ref = T->getAs())
+  return skipTopLevelReferences(Ref->getPointeeTypeAsWr

[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-08 Thread Younan Zhang via cfe-commits


@@ -372,6 +374,292 @@ maybeDropCxxExplicitObjectParameters(ArrayRef Params) {
   return Params;
 }
 
+class TypeInlayHintLabelPartBuilder
+: public TypeVisitor {
+  QualType CurrentType;
+  NestedNameSpecifier *CurrentNestedNameSpecifier;
+  ASTContext &Context;
+  StringRef MainFilePath;
+  const PrintingPolicy &PP;
+  SourceManager &SM;
+  std::vector &LabelChunks;
+
+  struct CurrentTypeRAII {
+TypeInlayHintLabelPartBuilder &Builder;
+QualType PreviousType;
+NestedNameSpecifier *PreviousNestedNameSpecifier;
+CurrentTypeRAII(TypeInlayHintLabelPartBuilder &Builder, QualType New,
+NestedNameSpecifier *NNS = nullptr)
+: Builder(Builder), PreviousType(Builder.CurrentType),
+  PreviousNestedNameSpecifier(Builder.CurrentNestedNameSpecifier) {
+  Builder.CurrentType = New;
+  if (NNS)
+Builder.CurrentNestedNameSpecifier = NNS;
+}
+~CurrentTypeRAII() {
+  Builder.CurrentType = PreviousType;
+  Builder.CurrentNestedNameSpecifier = PreviousNestedNameSpecifier;
+}
+  };
+
+  void addLabel(llvm::function_ref NamePrinter,
+llvm::function_ref SourceLocationGetter) {
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+NamePrinter(OS);
+auto &Name = LabelChunks.emplace_back();
+Name.value = std::move(Label);
+Name.location = makeLocation(Context, SourceLocationGetter(), 
MainFilePath);
+  }
+
+  void addLabel(std::string Label) {
+if (LabelChunks.empty()) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+auto &Back = LabelChunks.back();
+if (Back.location) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+// Let's combine the "unclickable" pieces together.
+Back.value += std::move(Label);
+  }
+
+  void printTemplateArgumentList(llvm::ArrayRef Args) {
+unsigned Size = Args.size();
+for (unsigned I = 0; I < Size; ++I) {
+  auto &TA = Args[I];
+  if (PP.SuppressDefaultTemplateArgs && TA.getIsDefaulted())
+continue;
+  if (I)
+addLabel(", ");
+  printTemplateArgument(TA);
+}
+  }
+
+  void printTemplateArgument(const TemplateArgument &TA) {
+switch (TA.getKind()) {
+case TemplateArgument::Pack:
+  return printTemplateArgumentList(TA.pack_elements());
+case TemplateArgument::Type: {
+  CurrentTypeRAII Guard(*this, TA.getAsType());
+  return Visit(TA.getAsType().getTypePtr());
+}
+// TODO: Add support for NTTP arguments.
+case TemplateArgument::Expression:
+case TemplateArgument::StructuralValue:
+case TemplateArgument::Null:
+case TemplateArgument::Declaration:
+case TemplateArgument::NullPtr:
+case TemplateArgument::Integral:
+case TemplateArgument::Template:
+case TemplateArgument::TemplateExpansion:
+  break;
+}
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+TA.print(PP, OS, /*IncludeType=*/true);
+addLabel(std::move(Label));
+  }
+
+  void handleTemplateSpecialization(
+  TemplateName TN, llvm::ArrayRef Args,
+  SourceLocation TemplateNameLocation = SourceLocation()) {
+SourceLocation Location;
+TemplateDecl *TD = nullptr;
+auto PrintType = TemplateName::Qualified::AsWritten;
+switch (TN.getKind()) {
+case TemplateName::Template:
+  TD = TN.getAsTemplateDecl();
+  Location = nameLocation(*TD, SM);
+  break;
+case TemplateName::QualifiedTemplate:
+  if (NestedNameSpecifier *NNS =
+  TN.getAsQualifiedTemplateName()->getQualifier();
+  NNS == CurrentNestedNameSpecifier) {
+// We have handled the NNS in VisitElaboratedType(). Avoid printing it
+// twice.
+TN = TN.getAsQualifiedTemplateName()->getUnderlyingTemplate();
+PrintType = TemplateName::Qualified::None;
+  }
+  break;
+case TemplateName::OverloadedTemplate:
+case TemplateName::AssumedTemplate:
+case TemplateName::DependentTemplate:
+case TemplateName::SubstTemplateTemplateParm:
+case TemplateName::SubstTemplateTemplateParmPack:
+case TemplateName::UsingTemplate:
+  break;
+}
+
+addLabel([&](llvm::raw_ostream &OS) { TN.print(OS, PP, PrintType); },
+ [&] {
+   if (TemplateNameLocation.isValid())
+ return TemplateNameLocation;
+   return Location;
+ });
+
+addLabel("<");
+printTemplateArgumentList(Args);
+addLabel(">");
+  }
+
+  void maybeAddQualifiers() {
+auto Quals = CurrentType.split().Quals;
+if (!Quals.empty()) {
+  addLabel(Quals.getAsString());
+  addLabel(" ");
+}
+  }
+
+  // When printing a reference, the referenced type might also be a reference.
+  // If so, we want to skip that before printing the inner type.
+  static QualType skipTopLevelReferences(QualType T) {
+if (auto *Ref = T->getAs())
+  return skipTopLevelReferences(Ref->getPointeeTypeAsWr

[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-07-08 Thread Paul Heidekrüger via cfe-commits


@@ -0,0 +1,124 @@
+//===--- ProBoundsAvoidUncheckedContainerAccesses.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ProBoundsAvoidUncheckedContainerAccesses.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+static constexpr std::array SubscriptDefaultExclusions = {
+llvm::StringRef("::std::map"), llvm::StringRef("::std::unordered_map"),
+llvm::StringRef("::std::flat_map")};
+
+ProBoundsAvoidUncheckedContainerAccesses::
+ProBoundsAvoidUncheckedContainerAccesses(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+
+  SubscriptExcludedClasses = clang::tidy::utils::options::parseStringList(
+  Options.get("ExcludeClasses", ""));
+  SubscriptExcludedClasses.insert(SubscriptExcludedClasses.end(),
+  SubscriptDefaultExclusions.begin(),
+  SubscriptDefaultExclusions.end());
+}
+
+void ProBoundsAvoidUncheckedContainerAccesses::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+
+  if (SubscriptExcludedClasses.size() == SubscriptDefaultExclusions.size()) {
+Options.store(Opts, "ExcludeClasses", "");
+return;
+  }
+
+  // Sum up the sizes of the defaults ( + semicolons), so we can remove them
+  // from the saved options
+  size_t DefaultsStringLength = std::transform_reduce(
+  SubscriptDefaultExclusions.begin(), SubscriptDefaultExclusions.end(),
+  SubscriptDefaultExclusions.size(), std::plus<>(),
+  [](llvm::StringRef Name) { return Name.size(); });
+
+  std::string Serialized = clang::tidy::utils::options::serializeStringList(
+  SubscriptExcludedClasses);
+
+  Options.store(Opts, "ExcludeClasses",
+Serialized.substr(0, Serialized.size() - 
DefaultsStringLength));
+}
+
+const CXXMethodDecl *findAlternative(const CXXRecordDecl *MatchedParent,
+ const CXXMethodDecl *MatchedOperator) {

PBHDK wrote:

Ah, fair point.
@HerrCai0907, would a simple "TODO: account for alternative being defined in 
subclass" work? Or am I misunderstanding something?

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-07-08 Thread Paul Heidekrüger via cfe-commits


@@ -0,0 +1,124 @@
+//===--- ProBoundsAvoidUncheckedContainerAccesses.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ProBoundsAvoidUncheckedContainerAccesses.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+static constexpr std::array SubscriptDefaultExclusions = {
+llvm::StringRef("::std::map"), llvm::StringRef("::std::unordered_map"),
+llvm::StringRef("::std::flat_map")};

PBHDK wrote:

The "record have key_type, value_type, and .at method" suggestion would blindly 
exclude any map-related at() method, even if its semantics are different, 
correct? 
Do you think this could cause any issues? Is it fair to assume that other 
libraries will define it so that it needs to be excluded?
Worst case, we have false negatives. Or am I misunderstanding something?

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -471,42 +518,123 @@ uint16_t __xray_register_event_type(
 }
 
 XRayPatchingStatus __xray_patch() XRAY_NEVER_INSTRUMENT {
-  return controlPatching(true);
+  XRayPatchingStatus CombinedStatus{SUCCESS};
+  for (size_t I = 0; I < __xray_num_objects(); ++I) {
+if (!isObjectLoaded(I))
+  continue;
+auto LastStatus = controlPatching(true, I);
+switch (LastStatus) {
+case FAILED:
+  CombinedStatus = FAILED;
+  break;
+case NOT_INITIALIZED:
+  if (CombinedStatus != FAILED)
+CombinedStatus = NOT_INITIALIZED;
+  break;
+case ONGOING:
+  if (CombinedStatus != FAILED && CombinedStatus != NOT_INITIALIZED)
+CombinedStatus = ONGOING;
+  break;
+default:
+  break;

sebastiankreutzer wrote:

Will do

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


[clang] [llvm] [AArch64][RISCV] Improve the tests for --print-enabled-extensions and --print-supported-extensions (PR #97829)

2024-07-08 Thread Tomas Matheson via cfe-commits

tmatheson-arm wrote:

> Mind sticking it in a gist at least so folks can use it for downstream 
> subtargets?

[Here you 
go](https://gist.github.com/tmatheson-arm/333dd14cc1c95ab4ac563ed615add95d)

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


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread David CARLIER via cfe-commits

devnexen wrote:

you do not need to worry I won t do any illumos/solaris work anytime soon, feel 
free to do xray port and all the rest.

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


[clang] [NFC][clang] Add a release note for `#embed` (PR #97997)

2024-07-08 Thread via cfe-commits

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


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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -471,42 +518,123 @@ uint16_t __xray_register_event_type(
 }
 
 XRayPatchingStatus __xray_patch() XRAY_NEVER_INSTRUMENT {
-  return controlPatching(true);
+  XRayPatchingStatus CombinedStatus{SUCCESS};

sebastiankreutzer wrote:

I would argue yes, since in this case doing nothing would be the expected 
behavior. 
However, in practice this case should never occur because the executable itself 
is always "loaded".

We could add an assertion to make this assumption explicit. What do you think?



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


[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-08 Thread Younan Zhang via cfe-commits


@@ -372,6 +374,292 @@ maybeDropCxxExplicitObjectParameters(ArrayRef Params) {
   return Params;
 }
 
+class TypeInlayHintLabelPartBuilder
+: public TypeVisitor {
+  QualType CurrentType;
+  NestedNameSpecifier *CurrentNestedNameSpecifier;
+  ASTContext &Context;
+  StringRef MainFilePath;
+  const PrintingPolicy &PP;
+  SourceManager &SM;
+  std::vector &LabelChunks;
+
+  struct CurrentTypeRAII {
+TypeInlayHintLabelPartBuilder &Builder;
+QualType PreviousType;
+NestedNameSpecifier *PreviousNestedNameSpecifier;
+CurrentTypeRAII(TypeInlayHintLabelPartBuilder &Builder, QualType New,
+NestedNameSpecifier *NNS = nullptr)
+: Builder(Builder), PreviousType(Builder.CurrentType),
+  PreviousNestedNameSpecifier(Builder.CurrentNestedNameSpecifier) {
+  Builder.CurrentType = New;
+  if (NNS)
+Builder.CurrentNestedNameSpecifier = NNS;
+}
+~CurrentTypeRAII() {
+  Builder.CurrentType = PreviousType;
+  Builder.CurrentNestedNameSpecifier = PreviousNestedNameSpecifier;
+}
+  };
+
+  void addLabel(llvm::function_ref NamePrinter,
+llvm::function_ref SourceLocationGetter) {
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+NamePrinter(OS);
+auto &Name = LabelChunks.emplace_back();
+Name.value = std::move(Label);
+Name.location = makeLocation(Context, SourceLocationGetter(), 
MainFilePath);
+  }
+
+  void addLabel(std::string Label) {
+if (LabelChunks.empty()) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+auto &Back = LabelChunks.back();
+if (Back.location) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+// Let's combine the "unclickable" pieces together.
+Back.value += std::move(Label);
+  }
+
+  void printTemplateArgumentList(llvm::ArrayRef Args) {
+unsigned Size = Args.size();
+for (unsigned I = 0; I < Size; ++I) {
+  auto &TA = Args[I];
+  if (PP.SuppressDefaultTemplateArgs && TA.getIsDefaulted())
+continue;
+  if (I)
+addLabel(", ");
+  printTemplateArgument(TA);
+}
+  }
+
+  void printTemplateArgument(const TemplateArgument &TA) {
+switch (TA.getKind()) {
+case TemplateArgument::Pack:
+  return printTemplateArgumentList(TA.pack_elements());
+case TemplateArgument::Type: {
+  CurrentTypeRAII Guard(*this, TA.getAsType());
+  return Visit(TA.getAsType().getTypePtr());
+}
+// TODO: Add support for NTTP arguments.
+case TemplateArgument::Expression:
+case TemplateArgument::StructuralValue:
+case TemplateArgument::Null:
+case TemplateArgument::Declaration:
+case TemplateArgument::NullPtr:
+case TemplateArgument::Integral:
+case TemplateArgument::Template:
+case TemplateArgument::TemplateExpansion:
+  break;
+}
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+TA.print(PP, OS, /*IncludeType=*/true);
+addLabel(std::move(Label));
+  }
+
+  void handleTemplateSpecialization(
+  TemplateName TN, llvm::ArrayRef Args,
+  SourceLocation TemplateNameLocation = SourceLocation()) {
+SourceLocation Location;
+TemplateDecl *TD = nullptr;
+auto PrintType = TemplateName::Qualified::AsWritten;
+switch (TN.getKind()) {
+case TemplateName::Template:
+  TD = TN.getAsTemplateDecl();
+  Location = nameLocation(*TD, SM);
+  break;
+case TemplateName::QualifiedTemplate:
+  if (NestedNameSpecifier *NNS =
+  TN.getAsQualifiedTemplateName()->getQualifier();
+  NNS == CurrentNestedNameSpecifier) {
+// We have handled the NNS in VisitElaboratedType(). Avoid printing it
+// twice.
+TN = TN.getAsQualifiedTemplateName()->getUnderlyingTemplate();
+PrintType = TemplateName::Qualified::None;
+  }
+  break;
+case TemplateName::OverloadedTemplate:
+case TemplateName::AssumedTemplate:
+case TemplateName::DependentTemplate:
+case TemplateName::SubstTemplateTemplateParm:
+case TemplateName::SubstTemplateTemplateParmPack:
+case TemplateName::UsingTemplate:
+  break;
+}
+
+addLabel([&](llvm::raw_ostream &OS) { TN.print(OS, PP, PrintType); },
+ [&] {
+   if (TemplateNameLocation.isValid())
+ return TemplateNameLocation;
+   return Location;
+ });
+
+addLabel("<");
+printTemplateArgumentList(Args);
+addLabel(">");
+  }
+
+  void maybeAddQualifiers() {
+auto Quals = CurrentType.split().Quals;
+if (!Quals.empty()) {
+  addLabel(Quals.getAsString());
+  addLabel(" ");
+}
+  }
+
+  // When printing a reference, the referenced type might also be a reference.
+  // If so, we want to skip that before printing the inner type.
+  static QualType skipTopLevelReferences(QualType T) {
+if (auto *Ref = T->getAs())
+  return skipTopLevelReferences(Ref->getPointeeTypeAsWr

[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -10685,6 +10689,26 @@ SDValue AArch64TargetLowering::LowerBR_JT(SDValue Op,
   return DAG.getNode(ISD::BRIND, DL, MVT::Other, JTInfo, SDValue(Dest, 0));
 }
 
+SDValue AArch64TargetLowering::LowerBRIND(SDValue Op, SelectionDAG &DAG) const 
{
+  MachineFunction &MF = DAG.getMachineFunction();

kovdan01 wrote:

Nit
```suggestion
  const MachineFunction &MF = DAG.getMachineFunction();
```

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 commented:

The changes mostly look reasonable, but there are several comments to be 
answered before the PR can be merged.

Regarding previous @efriedma-quic 's comment about computing the difference 
between two blockaddresses - I suppose it might be OK just to explicitly do not 
support this as for now and implement+test a proper error message (if it's too 
time-consuming to have full support right now).

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -412,6 +412,15 @@ class AArch64Subtarget final : public 
AArch64GenSubtargetInfo {
   /// Choose a method of checking LR before performing a tail call.
   AArch64PAuth::AuthCheckMethod getAuthenticatedLRCheckMethod() const;
 
+  /// Compute the integer discriminator for a given BlockAddress constant, if
+  /// blockaddress signing is enabled (using function attribute
+  /// "ptrauth-indirect-gotos").

kovdan01 wrote:

Nit: it might be worth explicitly saying that `std::nullopt` return value 
stands for disabled indirect gotos signing: someone might mistakenly think that 
`std::nullopt` might indicate absent discriminator (say, zero discr by default) 
with signing enabled.

Alternatively, you might consider adding a separate function for determining 
presence of "ptrauth-indirect-gotos" attribute and use just `uint16_t` as a 
return value for `getPtrAuthBlockAddressDiscriminator` (with an assertion 
inserted against presence of "ptrauth-indirect-gotos"). A drawback of such 
approach is that we might occasionally forget to check if indirect gotos are 
signed before calling get discr function, but a benefit is that function names 
will be more expressive IMHO - `getPtrAuthBlockAddressDiscriminator` will only 
get the discriminator and it'll not have a responsibility to check if the 
signing is enabled.

Feel free to ignore.

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -10704,15 +10728,36 @@ SDValue 
AArch64TargetLowering::LowerConstantPool(SDValue Op,
 
 SDValue AArch64TargetLowering::LowerBlockAddress(SDValue Op,
SelectionDAG &DAG) const {
-  BlockAddressSDNode *BA = cast(Op);
+  BlockAddressSDNode *BAN = cast(Op);
+  const BlockAddress *BA = BAN->getBlockAddress();
+
+  if (std::optional BADisc =
+  Subtarget->getPtrAuthBlockAddressDiscriminator(*BA->getFunction())) {
+SDLoc DL(Op);

kovdan01 wrote:

Is there a test which covers this code path?

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -1866,6 +1876,20 @@ void AArch64AsmPrinter::LowerMOVaddrPAC(const 
MachineInstr &MI) {
   assert(STI->getInstrInfo()->getInstSizeInBytes(MI) >= InstsEmitted * 4);
 }
 
+const MCExpr *
+AArch64AsmPrinter::lowerBlockAddressConstant(const BlockAddress &BA) {
+  const MCExpr *BAE = AsmPrinter::lowerBlockAddressConstant(BA);
+  const Function &Fn = *BA.getFunction();
+
+  if (std::optional BADisc =
+  STI->getPtrAuthBlockAddressDiscriminator(Fn))
+return AArch64AuthMCExpr::create(BAE, *BADisc, AArch64PACKey::IA,
+ /* HasAddressDiversity= */ false,

kovdan01 wrote:

Nit: it looks like that across llvm it's more common not to leave spaces inside 
comment in such case 
https://llvm.org/docs/CodingStandards.html#comment-formatting

```suggestion
 /*HasAddressDiversity=*/ false,
```

Feel free to ignore

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -2516,6 +2516,10 @@ bool AArch64FastISel::selectIndirectBr(const Instruction 
*I) {
   if (AddrReg == 0)
 return false;
 
+  // Authenticated indirectbr is not implemented yet.

kovdan01 wrote:

It looks like that a test with FastISel ensuring that we fall back to 
SelectionDAG ISel is missing. I'm OK with adding missing tests later as a 
separate patch.

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -3461,6 +3470,23 @@ bool AArch64InstructionSelector::select(MachineInstr &I) 
{
 return true;
   }
   case TargetOpcode::G_BLOCK_ADDR: {
+Function *BAFn = I.getOperand(1).getBlockAddress()->getFunction();
+if (std::optional BADisc =
+STI.getPtrAuthBlockAddressDiscriminator(*BAFn)) {
+  MIB.buildInstr(TargetOpcode::IMPLICIT_DEF, {AArch64::X16}, {});

kovdan01 wrote:

Is there a test which covers this code path?

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -0,0 +1,106 @@
+; RUN: llc -mtriple arm64e-apple-darwin \
+; RUN:   -asm-verbose=false -aarch64-enable-collect-loh=false \
+; RUN:   -o - %s | FileCheck %s
+
+; RUN: llc -mtriple arm64e-apple-darwin \
+; RUN:   -global-isel -global-isel-abort=1 -verify-machineinstrs \
+; RUN:   -asm-verbose=false -aarch64-enable-collect-loh=false \
+; RUN:   -o - %s | FileCheck %s
+
+; The discriminator is the same for all blockaddresses in the function.

kovdan01 wrote:

Nit: it looks like that comments which are actually comments and not run/check 
lines use `;;` as prefix instead of `;` in newly added tests. Same applies 
below.

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


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-08 Thread Daniil Kovalev via cfe-commits


@@ -1789,6 +1789,9 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
   options::OPT_fno_ptrauth_vtable_pointer_type_discrimination);
   Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
 options::OPT_fno_ptrauth_init_fini);
+

kovdan01 wrote:

Nit: there is no empty line between previous `Args.addOptInFlag(...)` 
invocations, so probably this new line should also be deleted.

Feel free to ignore

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -63,6 +63,10 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) 
{
 << XRayInstrument->getSpelling() << Triple.str();
   }
 
+  if (Args.hasFlag(options::OPT_fxray_enable_shared,
+   options::OPT_fno_xray_enable_shared, false))
+XRayEnableShared = true;
+

sebastiankreutzer wrote:

Good idea. I will do that.

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


[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-08 Thread Younan Zhang via cfe-commits


@@ -1005,14 +1332,22 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 // The sugared type is more useful in some cases, and the canonical
 // type in other cases.
 auto Desugared = maybeDesugar(AST, T);
-std::string TypeName = Desugared.getAsString(TypeHintPolicy);
-if (T != Desugared && !shouldPrintTypeHint(TypeName)) {
+std::vector Chunks;
+TypeInlayHintLabelPartBuilder Builder(Desugared, AST, MainFilePath,
+  TypeHintPolicy, Prefix, Chunks);
+Builder.Visit(Desugared.getTypePtr());
+if (T != Desugared && !shouldPrintTypeHint(Chunks)) {
   // If the desugared type is too long to display, fallback to the sugared
   // type.
-  TypeName = T.getAsString(TypeHintPolicy);
+  Chunks.clear();
+  TypeInlayHintLabelPartBuilder Builder(T, AST, MainFilePath,
+TypeHintPolicy, Prefix, Chunks);
+  Builder.Visit(T.getTypePtr());
 }
-if (shouldPrintTypeHint(TypeName))
-  addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
+if (shouldPrintTypeHint(Chunks))
+  addInlayHint(R, HintSide::Right, InlayHintKind::Type,
+   /*Prefix=*/"", // We have handled prefixes in the builder.

zyn0217 wrote:

Looking into my previous implementation again, I think my intent was more to 
avoid an extra copy (insertion) of strings...

I don't seem to have a better approach to simplify the code here, so ideas are 
welcome.

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


[clang] [Clang] Make -fcomplete-member-pointers the same as using the Microsoft C++ ABI (PR #98010)

2024-07-08 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/98010

This essentially adds a new language mode `CompleteMemberPointers`. With the 
Microsoft C++ ABI, this will always be true. Otherwise, it can be enabled with 
`-fcomplete-member-pointers`, and will work the same as if the Microsoft C++ 
ABI was being used for member pointers (only during sema, not codegen).

Previously `-fcomplete-member-pointers` was also being used for 
`-fsanitize=cfi-mfcall`. It can still be used for this, but the new 
`-Wincomplete-member-pointer` will warn in a similar way without enabling a 
non-standard language mode.

Before, an MSVC triple with `-fc++-abi=itanium` would still complete base types 
of member pointers even though it wasn't needed for codegen. It can still be 
completed with `-fc++-abi=itanium -fcomplete-member-pointers`.

Also adds a new warning `-Wmicrosoft-incomplete-member-pointers`, which will 
warn if a member pointer's base type is given an unspecified inheritance. This 
only warns with `CompleteMemberPointers`. It is enabled by `-Wmost`/`-Wall`. A 
similar warning 
[C5243](https://learn.microsoft.com/en-gb/cpp/error-messages/compiler-warnings/c5243?view=msvc-170)
 exists in MSVC.


>From 0de7bd39af61eb47ee33ff991e6de18f83e005dd Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Mon, 8 Jul 2024 10:36:35 +0100
Subject: [PATCH] [Clang] Make -fcomplete-member-pointers the same as using the
 Microsoft C++ ABI

---
 clang/docs/ControlFlowIntegrity.rst   |  6 +-
 clang/include/clang/Basic/DiagnosticGroups.td |  5 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  9 +-
 clang/include/clang/Basic/TargetCXXABI.h  |  5 +
 clang/include/clang/Sema/Sema.h   | 14 +++
 clang/lib/AST/Type.cpp|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  7 +-
 clang/lib/Frontend/CompilerInvocation.cpp |  9 +-
 clang/lib/Sema/SemaCast.cpp   | 14 +--
 clang/lib/Sema/SemaExpr.cpp   | 10 +-
 clang/lib/Sema/SemaExprCXX.cpp|  6 +-
 clang/lib/Sema/SemaOverload.cpp   |  3 +-
 clang/lib/Sema/SemaType.cpp   | 99 ++-
 clang/test/Misc/warning-wall.c|  1 +
 .../test/SemaCXX/complete-member-pointers.cpp | 39 +++-
 15 files changed, 149 insertions(+), 80 deletions(-)

diff --git a/clang/docs/ControlFlowIntegrity.rst 
b/clang/docs/ControlFlowIntegrity.rst
index 7de805e2154db..9b1086f4bbb8d 100644
--- a/clang/docs/ControlFlowIntegrity.rst
+++ b/clang/docs/ControlFlowIntegrity.rst
@@ -351,9 +351,9 @@ The compiler will only emit a full CFI check if the member 
function pointer's
 base type is complete. This is because the complete definition of the base
 type contains information that is necessary to correctly compile the CFI
 check. To ensure that the compiler always emits a full CFI check, it is
-recommended to also pass the flag ``-fcomplete-member-pointers``, which
-enables a non-conforming language extension that requires member pointer
-base types to be complete if they may be used for a call.
+recommended to enable the ``-Wincomplete-member-pointer`` warning, which
+warns if a member pointer does not have a complete base types when the
+member pointer type is specified.
 
 For this scheme to work, all translation units containing the definition
 of a virtual member function (whether inline or not), other than members
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..16ede9e2a59ac 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1040,6 +1040,8 @@ def VoidPointerDeref : DiagGroup<"void-ptr-dereference">;
 
 def FUseLdPath : DiagGroup<"fuse-ld-path">;
 
+def MicrosoftIncompleteMemberPointer : 
DiagGroup<"microsoft-incomplete-member-pointer">;
+
 def Move : DiagGroup<"move", [
 PessimizingMove,
 RedundantMove,
@@ -1102,7 +1104,8 @@ def Most : DiagGroup<"most", [
 PrivateExtern,
 SelTypeCast,
 ExternCCompat,
-UserDefinedWarnings
+UserDefinedWarnings,
+MicrosoftIncompleteMemberPointer
  ]>;
 
 // Thread Safety warnings
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..79dc6b15fb704 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8082,8 +8082,13 @@ def err_bad_memptr_rhs : Error<
 def err_bad_memptr_lhs : Error<
   "left hand operand to %0 must be a %select{|pointer to }1class "
   "compatible with the right hand operand, but is %2">;
-def err_memptr_incomplete : Error<
-  "member pointer has incomplete base type %0">;
+def warn_memptr_incomplete : Warning<
+  "member pointer has incomplete base type %0">, 
InGroup>, DefaultIgnore;
+def warn_memptr_incomplete_ms : Warning<
+  "this usage of a member pointer with an incompl

[clang] [Clang] Make -fcomplete-member-pointers the same as using the Microsoft C++ ABI (PR #98010)

2024-07-08 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 f50f7a7aa0b897ef91361d7dc159f3262d142bdc 
0de7bd39af61eb47ee33ff991e6de18f83e005dd -- 
clang/include/clang/Basic/TargetCXXABI.h clang/include/clang/Sema/Sema.h 
clang/lib/AST/Type.cpp clang/lib/Driver/ToolChains/Clang.cpp 
clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Sema/SemaCast.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp 
clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaType.cpp 
clang/test/Misc/warning-wall.c clang/test/SemaCXX/complete-member-pointers.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6e2cb9f8b..58d6bdf705 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14932,11 +14932,14 @@ public:
   }
 
 private:
-  void AssignInheritanceModelToBase(SourceLocation Loc, const 
MemberPointerType *T);
+  void AssignInheritanceModelToBase(SourceLocation Loc,
+const MemberPointerType *T);
+
 public:
   /// Called when the Microsoft ABI would require the base type of a member
   /// pointer to have its inheritance model calculated.
-  void microsoftCompleteMemberPointer(SourceLocation Loc, const 
MemberPointerType *T) {
+  void microsoftCompleteMemberPointer(SourceLocation Loc,
+  const MemberPointerType *T) {
 if (getLangOpts().CompleteMemberPointers)
   AssignInheritanceModelToBase(Loc, T);
   }
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 58225fa207..a05b83b9f4 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7146,7 +7146,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-fdelayed-template-parsing");
   }
 
-  if (Args.hasFlag(options::OPT_fcomplete_member_pointers, 
options::OPT_fno_complete_member_pointers, false)) {
+  if (Args.hasFlag(options::OPT_fcomplete_member_pointers,
+   options::OPT_fno_complete_member_pointers, false)) {
 CmdArgs.push_back("-fcomplete-member-pointers");
 CmdArgs.push_back("-Werror=microsoft-incomplete-member-pointer");
   }
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 3f00c7b77e..e3e81b8597 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8969,14 +8969,18 @@ bool Sema::hasReachableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
  OnlyNeedComplete);
 }
 
-void Sema::AssignInheritanceModelToBase(SourceLocation Loc, const 
MemberPointerType *T) {
-  if (!T || T->getClass()->isDependentType()) return;
+void Sema::AssignInheritanceModelToBase(SourceLocation Loc,
+const MemberPointerType *T) {
+  if (!T || T->getClass()->isDependentType())
+return;
 
-  assert(getLangOpts().CompleteMemberPointers && "Should not need assign the 
inheritance model in this case");
+  assert(getLangOpts().CompleteMemberPointers &&
+ "Should not need assign the inheritance model in this case");
 
   QualType Base = QualType(T->getClass(), 0);
   (void)isCompleteType(Loc, Base);
-  CXXRecordDecl *RD = 
T->getClass()->getAsCXXRecordDecl()->getMostRecentNonInjectedDecl();
+  CXXRecordDecl *RD =
+  T->getClass()->getAsCXXRecordDecl()->getMostRecentNonInjectedDecl();
   if (RD->hasAttr())
 return;
 
@@ -8999,13 +9003,14 @@ void Sema::AssignInheritanceModelToBase(SourceLocation 
Loc, const MemberPointerT
   }
 
   SourceRange AttrLoc = ImplicitMSInheritanceAttrLoc.isValid()
-? ImplicitMSInheritanceAttrLoc
-: RD->getSourceRange();
+? ImplicitMSInheritanceAttrLoc
+: RD->getSourceRange();
   RD->addAttr(MSInheritanceAttr::CreateImplicit(
   Context, BestCase, AttrLoc, MSInheritanceAttr::Spelling(IM)));
   Consumer.AssignInheritanceModel(RD);
 
-  // Don't warn if the inheritance model is explicitly unspecified because of 
a pragma
+  // Don't warn if the inheritance model is explicitly unspecified because of a
+  // pragma
   if (IM != MSInheritanceModel::Unspecified || !BestCase)
 return;
 
@@ -9013,8 +9018,12 @@ void Sema::AssignInheritanceModelToBase(SourceLocation 
Loc, const MemberPointerT
   if (!RD->hasDefinition())
 Diag(RD->getLocation(), diag::note_forward_declaration) << Base;
   else if (RD->isParsingBaseSpecifiers())
-Diag(RD->getDefinition()->getLocation(), 
diag::note_memptr_incomplete_until_bases);
-  Diag(RD->getLocation(), diag::note_memptr_incomplete_specify_inheritance) << 
FixItHint::CreateInsertion(RD->getLocation(), 
"__single_inheritance|__multiple_inheritance|__virtual_inheritance");
+ 

[clang] [Clang] Make -fcomplete-member-pointers the same as using the Microsoft C++ ABI (PR #98010)

2024-07-08 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

TODO:

 - Tests for `-Wincomplete-member-pointer`
 - Possibly do something else about `-fsanitize=cfi-mfcall`. 
`-Wincomplete-member-pointer` is too broad, for the sanitizer we only care 
about a call to a pointer to member function. The warning could also be emitted 
here: 
https://github.com/llvm/llvm-project/blob/1b8ab2f08998d3220e5d95003d47bb3d7cac966b/clang/lib/CodeGen/ItaniumCXXABI.cpp#L800
 - It's weird that `-fcomplete-member-pointers` enables an error. Possibly 
deprecate `-fcomplete-member-pointers` and have it be an alias for 
`-fmicrosoft-complete-member-pointers 
-Werror=microsoft-incomplete-member-pointer` (where 
`-fmicrosoft-complete-member-pointers` is a new option).
 - Release note
 - Maybe reword the warning with `-fcomplete-member-pointers` is used with a 
non-Microsoft ABI. It's not actually an ODR violation then, and the 
`__single_inheritance` etc. keywords might not be available.

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


[clang] [Clang] Make -fcomplete-member-pointers the same as using the Microsoft C++ ABI (PR #98010)

2024-07-08 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/98010

>From 7cc8f4c8c4e39db82ff8f7cb7164a94abf6b2029 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Mon, 8 Jul 2024 10:36:35 +0100
Subject: [PATCH] [Clang] Make -fcomplete-member-pointers the same as using the
 Microsoft C++ ABI

---
 clang/docs/ControlFlowIntegrity.rst   |   6 +-
 clang/include/clang/Basic/DiagnosticGroups.td |   5 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   9 +-
 clang/include/clang/Basic/TargetCXXABI.h  |   5 +
 clang/include/clang/Sema/Sema.h   |  17 +++
 clang/lib/AST/Type.cpp|   2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   8 +-
 clang/lib/Frontend/CompilerInvocation.cpp |   9 +-
 clang/lib/Sema/SemaCast.cpp   |  14 +--
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaExprCXX.cpp|   6 +-
 clang/lib/Sema/SemaOverload.cpp   |   3 +-
 clang/lib/Sema/SemaType.cpp   | 108 +++---
 clang/test/Misc/warning-wall.c|   1 +
 .../test/SemaCXX/complete-member-pointers.cpp |  39 ++-
 15 files changed, 162 insertions(+), 80 deletions(-)

diff --git a/clang/docs/ControlFlowIntegrity.rst 
b/clang/docs/ControlFlowIntegrity.rst
index 7de805e2154db..9b1086f4bbb8d 100644
--- a/clang/docs/ControlFlowIntegrity.rst
+++ b/clang/docs/ControlFlowIntegrity.rst
@@ -351,9 +351,9 @@ The compiler will only emit a full CFI check if the member 
function pointer's
 base type is complete. This is because the complete definition of the base
 type contains information that is necessary to correctly compile the CFI
 check. To ensure that the compiler always emits a full CFI check, it is
-recommended to also pass the flag ``-fcomplete-member-pointers``, which
-enables a non-conforming language extension that requires member pointer
-base types to be complete if they may be used for a call.
+recommended to enable the ``-Wincomplete-member-pointer`` warning, which
+warns if a member pointer does not have a complete base types when the
+member pointer type is specified.
 
 For this scheme to work, all translation units containing the definition
 of a virtual member function (whether inline or not), other than members
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..16ede9e2a59ac 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1040,6 +1040,8 @@ def VoidPointerDeref : DiagGroup<"void-ptr-dereference">;
 
 def FUseLdPath : DiagGroup<"fuse-ld-path">;
 
+def MicrosoftIncompleteMemberPointer : 
DiagGroup<"microsoft-incomplete-member-pointer">;
+
 def Move : DiagGroup<"move", [
 PessimizingMove,
 RedundantMove,
@@ -1102,7 +1104,8 @@ def Most : DiagGroup<"most", [
 PrivateExtern,
 SelTypeCast,
 ExternCCompat,
-UserDefinedWarnings
+UserDefinedWarnings,
+MicrosoftIncompleteMemberPointer
  ]>;
 
 // Thread Safety warnings
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..79dc6b15fb704 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8082,8 +8082,13 @@ def err_bad_memptr_rhs : Error<
 def err_bad_memptr_lhs : Error<
   "left hand operand to %0 must be a %select{|pointer to }1class "
   "compatible with the right hand operand, but is %2">;
-def err_memptr_incomplete : Error<
-  "member pointer has incomplete base type %0">;
+def warn_memptr_incomplete : Warning<
+  "member pointer has incomplete base type %0">, 
InGroup>, DefaultIgnore;
+def warn_memptr_incomplete_ms : Warning<
+  "this usage of a member pointer with an incomplete base type %0 may cause 
ODR violations">, InGroup, DefaultIgnore;
+def note_memptr_incomplete_specify_inheritance : Note<"consider specifying the 
inheritance model">;
+def note_memptr_incomplete_until_bases : Note<
+  "this will affect the ABI of the member pointer until the bases have been 
specified">;
 def warn_exception_caught_by_earlier_handler : Warning<
   "exception of type %0 will be caught by earlier handler">,
   InGroup;
diff --git a/clang/include/clang/Basic/TargetCXXABI.h 
b/clang/include/clang/Basic/TargetCXXABI.h
index d204452afbf4b..d88846839b20c 100644
--- a/clang/include/clang/Basic/TargetCXXABI.h
+++ b/clang/include/clang/Basic/TargetCXXABI.h
@@ -68,6 +68,11 @@ class TargetCXXABI {
 return T.isOSFuchsia();
   }
 
+  // Return true if this target uses the Microsoft C++ ABI by default.
+  static bool defaultABIIsMicrosoft(const llvm::Triple &T) {
+return T.isKnownWindowsMSVCEnvironment();
+  }
+
   /// A bogus initialization of the platform ABI.
   TargetCXXABI() : TheKind(GenericItanium) {}
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 75a80540

[clang] [Clang] Fix Microsoft ABI inheritance model when member pointer is used in a base specifier (PR #91990)

2024-07-08 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

> Will that include fixing clang incorrectly warning when an inheritance model 
> is explicitly specified?

Yes, I have a WIP of it here #98010 where that doesn't get a warning 
(https://github.com/llvm/llvm-project/pull/98010/files#diff-bec1ae40e5793adbd61e7a9dc41a4715a06e27888a384c0752bb6b4b09a1075fR20-R21)

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


[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)

2024-07-08 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/98013

As described in 
https://github.com/llvm/llvm-project/issues/90209#issuecomment-2135972202, 
Clang may not preserve enough information during template argument deduction. 
This can result in a merely canonical `TemplateTypeParmType` with a null 
`Decl`, leading to an incomplete template parameter list for the synthesized 
deduction guide.

This patch addresses the issue by using the index and depth information to 
retrieve the corresponding template parameter, rather than relying on 
`TTP->getDecl()`.

Fixes #90209

>From 1b4a711ebe32879608026007de7fc373d44fbcf4 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 8 Jul 2024 13:19:13 +0200
Subject: [PATCH] [clang] CTAD: use index and depth to retrieve template
 parameters in TemplateParamsReferencedInTemplateArgumentList.

---
 clang/lib/Sema/SemaTemplate.cpp| 31 +++---
 clang/test/AST/ast-dump-ctad-alias.cpp | 25 +
 2 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 07b3f793b3a29d..46be2e90df847f 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform {
 // Find all template parameters that appear in the given DeducedArgs.
 // Return the indices of the template parameters in the TemplateParams.
 SmallVector TemplateParamsReferencedInTemplateArgumentList(
-ArrayRef TemplateParams,
+const TemplateParameterList* TemplateParamsList,
 ArrayRef DeducedArgs) {
   struct TemplateParamsReferencedFinder
   : public RecursiveASTVisitor {
+const TemplateParameterList* TemplateParamList;
 llvm::DenseSet TemplateParams;
 llvm::DenseSet ReferencedTemplateParams;
 
-TemplateParamsReferencedFinder(ArrayRef TemplateParams)
-: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {}
+TemplateParamsReferencedFinder(
+const TemplateParameterList *TemplateParamList)
+: TemplateParamList(TemplateParamList),
+  TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) 
{
+}
 
 bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) {
-  MarkAppeared(TTP->getDecl());
+  // We use the index and depth to retrieve the corresponding template
+  // parameter from the parameter list.
+  // Note that Clang may not preserve type sugar during template argument
+  // deduction. In such cases, the TTP is a canonical 
TemplateTypeParamType,
+  // which only retains its index and depth information.
+  if (TTP->getDepth() == TemplateParamList->getDepth() &&
+  TTP->getIndex() < TemplateParamList->size()) {
+ReferencedTemplateParams.insert(
+TemplateParamList->getParam(TTP->getIndex()));
+  }
   return true;
 }
+
 bool VisitDeclRefExpr(DeclRefExpr *DRE) {
   MarkAppeared(DRE->getFoundDecl());
   return true;
@@ -2683,12 +2697,13 @@ SmallVector 
TemplateParamsReferencedInTemplateArgumentList(
 ReferencedTemplateParams.insert(ND);
 }
   };
-  TemplateParamsReferencedFinder Finder(TemplateParams);
+  TemplateParamsReferencedFinder Finder(TemplateParamsList);
   Finder.TraverseTemplateArguments(DeducedArgs);
 
   SmallVector Results;
-  for (unsigned Index = 0; Index < TemplateParams.size(); ++Index) {
-if (Finder.ReferencedTemplateParams.contains(TemplateParams[Index]))
+  for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
+if (Finder.ReferencedTemplateParams.contains(
+TemplateParamsList->getParam(Index)))
   Results.push_back(Index);
   }
   return Results;
@@ -3047,7 +3062,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   }
   auto DeducedAliasTemplateParams =
   TemplateParamsReferencedInTemplateArgumentList(
-  AliasTemplate->getTemplateParameters()->asArray(), DeducedArgs);
+  AliasTemplate->getTemplateParameters(), DeducedArgs);
   // All template arguments null by default.
   SmallVector TemplateArgsForBuildingFPrime(
   F->getTemplateParameters()->size());
diff --git a/clang/test/AST/ast-dump-ctad-alias.cpp 
b/clang/test/AST/ast-dump-ctad-alias.cpp
index 6f07a62e9a0691..adccad97a205b4 100644
--- a/clang/test/AST/ast-dump-ctad-alias.cpp
+++ b/clang/test/AST/ast-dump-ctad-alias.cpp
@@ -99,3 +99,28 @@ BFoo b2(1.0, 2.0);
 // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'type-parameter-0-0'
 // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'type-parameter-0-0'
 // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (double, double) -> Foo' implicit_instantiation
+
+namespace GH90209 {
+template 
+struct List {
+  List(int);
+};
+
+template 
+struct TemplatedClass {
+  TemplatedClass(T1);
+};
+
+template 
+TemplatedClass(T1) -> TemplatedClass>;
+
+template 
+using ATemplatedClass = TemplatedClass>;
+
+ATemplatedClass test(1);

[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)

2024-07-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

As described in 
https://github.com/llvm/llvm-project/issues/90209#issuecomment-2135972202, 
Clang may not preserve enough information during template argument deduction. 
This can result in a merely canonical `TemplateTypeParmType` with a null 
`Decl`, leading to an incomplete template parameter list for the synthesized 
deduction guide.

This patch addresses the issue by using the index and depth information to 
retrieve the corresponding template parameter, rather than relying on 
`TTP->getDecl()`.

Fixes #90209

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+23-8) 
- (modified) clang/test/AST/ast-dump-ctad-alias.cpp (+25) 


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 07b3f793b3a29..46be2e90df847 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform {
 // Find all template parameters that appear in the given DeducedArgs.
 // Return the indices of the template parameters in the TemplateParams.
 SmallVector TemplateParamsReferencedInTemplateArgumentList(
-ArrayRef TemplateParams,
+const TemplateParameterList* TemplateParamsList,
 ArrayRef DeducedArgs) {
   struct TemplateParamsReferencedFinder
   : public RecursiveASTVisitor {
+const TemplateParameterList* TemplateParamList;
 llvm::DenseSet TemplateParams;
 llvm::DenseSet ReferencedTemplateParams;
 
-TemplateParamsReferencedFinder(ArrayRef TemplateParams)
-: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {}
+TemplateParamsReferencedFinder(
+const TemplateParameterList *TemplateParamList)
+: TemplateParamList(TemplateParamList),
+  TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) 
{
+}
 
 bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) {
-  MarkAppeared(TTP->getDecl());
+  // We use the index and depth to retrieve the corresponding template
+  // parameter from the parameter list.
+  // Note that Clang may not preserve type sugar during template argument
+  // deduction. In such cases, the TTP is a canonical 
TemplateTypeParamType,
+  // which only retains its index and depth information.
+  if (TTP->getDepth() == TemplateParamList->getDepth() &&
+  TTP->getIndex() < TemplateParamList->size()) {
+ReferencedTemplateParams.insert(
+TemplateParamList->getParam(TTP->getIndex()));
+  }
   return true;
 }
+
 bool VisitDeclRefExpr(DeclRefExpr *DRE) {
   MarkAppeared(DRE->getFoundDecl());
   return true;
@@ -2683,12 +2697,13 @@ SmallVector 
TemplateParamsReferencedInTemplateArgumentList(
 ReferencedTemplateParams.insert(ND);
 }
   };
-  TemplateParamsReferencedFinder Finder(TemplateParams);
+  TemplateParamsReferencedFinder Finder(TemplateParamsList);
   Finder.TraverseTemplateArguments(DeducedArgs);
 
   SmallVector Results;
-  for (unsigned Index = 0; Index < TemplateParams.size(); ++Index) {
-if (Finder.ReferencedTemplateParams.contains(TemplateParams[Index]))
+  for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
+if (Finder.ReferencedTemplateParams.contains(
+TemplateParamsList->getParam(Index)))
   Results.push_back(Index);
   }
   return Results;
@@ -3047,7 +3062,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   }
   auto DeducedAliasTemplateParams =
   TemplateParamsReferencedInTemplateArgumentList(
-  AliasTemplate->getTemplateParameters()->asArray(), DeducedArgs);
+  AliasTemplate->getTemplateParameters(), DeducedArgs);
   // All template arguments null by default.
   SmallVector TemplateArgsForBuildingFPrime(
   F->getTemplateParameters()->size());
diff --git a/clang/test/AST/ast-dump-ctad-alias.cpp 
b/clang/test/AST/ast-dump-ctad-alias.cpp
index 6f07a62e9a069..adccad97a205b 100644
--- a/clang/test/AST/ast-dump-ctad-alias.cpp
+++ b/clang/test/AST/ast-dump-ctad-alias.cpp
@@ -99,3 +99,28 @@ BFoo b2(1.0, 2.0);
 // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'type-parameter-0-0'
 // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'type-parameter-0-0'
 // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (double, double) -> Foo' implicit_instantiation
+
+namespace GH90209 {
+template 
+struct List {
+  List(int);
+};
+
+template 
+struct TemplatedClass {
+  TemplatedClass(T1);
+};
+
+template 
+TemplatedClass(T1) -> TemplatedClass>;
+
+template 
+using ATemplatedClass = TemplatedClass>;
+
+ATemplatedClass test(1);
+// Verify that we have a correct template parameter list for the deduction 
guide.
+//
+// CHECK:  FunctionTemplateDecl {{.*}} 
+// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2
+// CHECK-NEXT: |-TypeTraitExpr {{.*

[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)

2024-07-08 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 f50f7a7aa0b897ef91361d7dc159f3262d142bdc 
1b4a711ebe32879608026007de7fc373d44fbcf4 -- clang/lib/Sema/SemaTemplate.cpp 
clang/test/AST/ast-dump-ctad-alias.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 46be2e90df..07bd94544b 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2653,11 +2653,11 @@ private:
 // Find all template parameters that appear in the given DeducedArgs.
 // Return the indices of the template parameters in the TemplateParams.
 SmallVector TemplateParamsReferencedInTemplateArgumentList(
-const TemplateParameterList* TemplateParamsList,
+const TemplateParameterList *TemplateParamsList,
 ArrayRef DeducedArgs) {
   struct TemplateParamsReferencedFinder
   : public RecursiveASTVisitor {
-const TemplateParameterList* TemplateParamList;
+const TemplateParameterList *TemplateParamList;
 llvm::DenseSet TemplateParams;
 llvm::DenseSet ReferencedTemplateParams;
 

``




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


[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)

2024-07-08 Thread Constantin Kronbichler via cfe-commits

https://github.com/ccrownhill created 
https://github.com/llvm/llvm-project/pull/98016

This fixes issue #39558 which mentions the problem when compiling the following 
code with `-pedantic-errors` flag (it also mentions `-Wall -Wextra` but those 
shouldn't change the output, which is also the case in GCC):

```c
static void f();

int main()
{
f;
}
```

Clang only outputs an `undefined-internal` warning on the first line, but 
according to 6.9/3

```
"... Moreover, if an identifier declared with internal linkage is used in an
 expression (other than as a part of the operand of a sizeof or _Alignof
 operator whose result is an integer constant), there shall be exactly one
 external definition for the identifier in the translation unit."
```

this should be illegal and hence an error.

I fixed this by changing the warning type from `Warning` to `ExtWarn` and by 
adding a suitable test.



>From 5dd2bb12dee26ba93d927ad1cd99fa610f9ace97 Mon Sep 17 00:00:00 2001
From: ccrownhill 
Date: Mon, 8 Jul 2024 11:42:37 +0100
Subject: [PATCH] fix bug that undefined internal is a warning only for
 -pedantic-errors

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 +-
 clang/test/Sema/undefined_internal.c | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/undefined_internal.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..ae3dbedd01693 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6013,7 +6013,7 @@ def note_deleted_assign_field : Note<
   "because field %2 is of %select{reference|const-qualified}4 type %3">;
 
 // These should be errors.
-def warn_undefined_internal : Warning<
+def warn_undefined_internal : ExtWarn<
   "%select{function|variable}0 %q1 has internal linkage but is not defined">,
   InGroup>;
 def err_undefined_internal_type : Error<
diff --git a/clang/test/Sema/undefined_internal.c 
b/clang/test/Sema/undefined_internal.c
new file mode 100644
index 0..1b6c3a4b76e05
--- /dev/null
+++ b/clang/test/Sema/undefined_internal.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+static void f(void); // expected-error {{function 'f' has internal linkage but 
is not defined}}
+
+int main(void)
+{
+f;
+// expected-note@-1 {{used here}}
+// expected-warning@-2 {{expression result unused}}
+}
+

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


[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)

2024-07-08 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/98016
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)

2024-07-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Constantin Kronbichler (ccrownhill)


Changes

This fixes issue #39558 which mentions the problem when compiling the 
following code with `-pedantic-errors` flag (it also mentions `-Wall -Wextra` 
but those shouldn't change the output, which is also the case in GCC):

```c
static void f();

int main()
{
f;
}
```

Clang only outputs an `undefined-internal` warning on the first line, but 
according to 6.9/3

```
"... Moreover, if an identifier declared with internal linkage is used in an
 expression (other than as a part of the operand of a sizeof or _Alignof
 operator whose result is an integer constant), there shall be exactly one
 external definition for the identifier in the translation unit."
```

this should be illegal and hence an error.

I fixed this by changing the warning type from `Warning` to `ExtWarn` and by 
adding a suitable test.



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


2 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (added) clang/test/Sema/undefined_internal.c (+11) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..ae3dbedd01693 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6013,7 +6013,7 @@ def note_deleted_assign_field : Note<
   "because field %2 is of %select{reference|const-qualified}4 type %3">;
 
 // These should be errors.
-def warn_undefined_internal : Warning<
+def warn_undefined_internal : ExtWarn<
   "%select{function|variable}0 %q1 has internal linkage but is not defined">,
   InGroup>;
 def err_undefined_internal_type : Error<
diff --git a/clang/test/Sema/undefined_internal.c 
b/clang/test/Sema/undefined_internal.c
new file mode 100644
index 0..1b6c3a4b76e05
--- /dev/null
+++ b/clang/test/Sema/undefined_internal.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+static void f(void); // expected-error {{function 'f' has internal linkage but 
is not defined}}
+
+int main(void)
+{
+f;
+// expected-note@-1 {{used here}}
+// expected-warning@-2 {{expression result unused}}
+}
+

``




https://github.com/llvm/llvm-project/pull/98016
___
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 warn on const variables in misc-use-internal-linkage (PR #97969)

2024-07-08 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/97969

>From a1fec907b5d3920d5dda8761b6e173e153b7f281 Mon Sep 17 00:00:00 2001
From: Carlos Galvez 
Date: Sun, 7 Jul 2024 21:11:54 +0200
Subject: [PATCH] [clang-tidy] Do not warn on const variables in
 misc-use-internal-linkage

Since in C++ they already have implicit internal linkage.
https://eel.is/c++draft/diff#basic-3

Also, ensure that the check is only active in C++ code, since the
warning message presents anonymous namespaces as a solution, which
is not applicable to C.

Fixes #97947
---
 .../clang-tidy/misc/UseInternalLinkageCheck.cpp  | 5 -
 clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h  | 3 +++
 .../clang-tidy/checkers/misc/use-internal-linkage-var.cpp| 3 +++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index 44ccc2bc906a5b..bc3fc50ca75dff 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -103,7 +103,10 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder 
*Finder) {
   functionDecl(Common, unless(cxxMethodDecl()), unless(isMain()))
   .bind("fn"),
   this);
-  Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this);
+  Finder->addMatcher(
+  varDecl(Common, hasGlobalStorage(), unless(hasType(isConstQualified(
+  .bind("var"),
+  this);
 }
 
 static constexpr StringRef Message =
diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h
index 0d6c3e43aa9457..1ad28333ddc49d 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h
@@ -21,6 +21,9 @@ namespace clang::tidy::misc {
 class UseInternalLinkageCheck : public ClangTidyCheck {
 public:
   UseInternalLinkageCheck(StringRef Name, ClangTidyContext *Context);
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus;
+  }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
index 01b8d28e612301..6777ce4bb0265e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
@@ -42,3 +42,6 @@ int global_in_extern_c_1;
 }
 
 extern "C" int global_in_extern_c_2;
+
+const int const_global = 123;
+constexpr int constexpr_global = 123;

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


[clang] [analyzer][docs] Add clang-19 release notes for CSA (PR #97418)

2024-07-08 Thread Balazs Benics via cfe-commits

steakhal wrote:

Ping.

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


[clang] [analyzer][docs] Add clang-19 release notes for CSA (PR #97418)

2024-07-08 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] [analyzer][docs] Add clang-19 release notes for CSA (PR #97418)

2024-07-08 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

Small note, the screenshot has the "improvements" part, but I did not find that 
in the actual PR. 

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


[clang] [clang] CTAD: Generate deduction guides for alias templates from non-template explicit deduction guides (PR #96686)

2024-07-08 Thread Haojian Wu via cfe-commits

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

>From c835f5acbcb9c768c525df835d09fbe301edd197 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 25 Jun 2024 10:16:54 +0200
Subject: [PATCH 1/2] [clang] CTAD: Fix deduction guides for alias are not
 generated from non-template explicit deduction guides.

---
 clang/lib/Sema/SemaTemplate.cpp  | 64 +---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 41 +
 2 files changed, 97 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 07b3f793b3a29d..5fac68fb10617a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2220,8 +2220,12 @@ class ExtractTypeForDeductionGuide
   }
 };
 
-// Build a deduction guide with the specified parameter types.
-FunctionTemplateDecl *buildDeductionGuide(
+// Build a deduction guide using the provided information.
+//
+// A deduction guide can be either a template or a non-template function
+// declaration. If \p TemplateParams is null, a non-template function
+// declaration will be created.
+NamedDecl *buildDeductionGuide(
 Sema &SemaRef, TemplateDecl *OriginalTemplate,
 TemplateParameterList *TemplateParams, CXXConstructorDecl *Ctor,
 ExplicitSpecifier ES, TypeSourceInfo *TInfo, SourceLocation LocStart,
@@ -2247,16 +2251,21 @@ FunctionTemplateDecl *buildDeductionGuide(
 Param->setDeclContext(Guide);
   for (auto *TD : MaterializedTypedefs)
 TD->setDeclContext(Guide);
+  if (isa(DC))
+Guide->setAccess(AS_public);
+
+  if (!TemplateParams) {
+DC->addDecl(Guide);
+return Guide;
+  }
 
   auto *GuideTemplate = FunctionTemplateDecl::Create(
   SemaRef.Context, DC, Loc, DeductionGuideName, TemplateParams, Guide);
   GuideTemplate->setImplicit(IsImplicit);
   Guide->setDescribedFunctionTemplate(GuideTemplate);
 
-  if (isa(DC)) {
-Guide->setAccess(AS_public);
+  if (isa(DC))
 GuideTemplate->setAccess(AS_public);
-  }
 
   DC->addDecl(GuideTemplate);
   return GuideTemplate;
@@ -2898,7 +2907,8 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
   ASTContext &Context = SemaRef.Context;
   // Constraint AST nodes must use uninstantiated depth.
   if (auto *PrimaryTemplate =
-  AliasTemplate->getInstantiatedFromMemberTemplate()) {
+  AliasTemplate->getInstantiatedFromMemberTemplate();
+  PrimaryTemplate && TemplateParams.size() > 0) {
 LocalInstantiationScope Scope(SemaRef);
 
 // Adjust the depth for TemplateParams.
@@ -3162,12 +3172,12 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 FPrimeTemplateParams,
 AliasTemplate->getTemplateParameters()->getRAngleLoc(),
 /*RequiresClause=*/RequiresClause);
-FunctionTemplateDecl *Result = buildDeductionGuide(
+auto *Result = cast(buildDeductionGuide(
 SemaRef, AliasTemplate, FPrimeTemplateParamList,
 GG->getCorrespondingConstructor(), GG->getExplicitSpecifier(),
 GG->getTypeSourceInfo(), AliasTemplate->getBeginLoc(),
 AliasTemplate->getLocation(), AliasTemplate->getEndLoc(),
-F->isImplicit());
+F->isImplicit()));
 cast(Result->getTemplatedDecl())
 ->setDeductionCandidateKind(GG->getDeductionCandidateKind());
 return Result;
@@ -3198,6 +3208,44 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   Guides.suppressDiagnostics();
 
   for (auto *G : Guides) {
+if (auto *DG = dyn_cast(G)) {
+  // The deduction guide is a non-template function decl, we just clone it.
+  auto *FunctionType =
+  SemaRef.Context.getTrivialTypeSourceInfo(DG->getType());
+  FunctionProtoTypeLoc FPTL =
+  FunctionType->getTypeLoc().castAs();
+
+  // Clone the parameters.
+  unsigned ProcessedParamIndex = 0;
+  for (auto *P : DG->parameters()) {
+auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(P->getType());
+ParmVarDecl *NewParam = ParmVarDecl::Create(
+SemaRef.Context, G->getDeclContext(), P->getBeginLoc(),
+P->getLocation(), nullptr, TSI->getType(), TSI, SC_None, nullptr);
+NewParam->setScopeInfo(0, ProcessedParamIndex);
+FPTL.setParam(ProcessedParamIndex, NewParam);
+ProcessedParamIndex++;
+  }
+  auto *Transformed = cast(buildDeductionGuide(
+  SemaRef, AliasTemplate, /*TemplateParams=*/nullptr,
+  /*Constructor=*/nullptr, DG->getExplicitSpecifier(), FunctionType,
+  AliasTemplate->getBeginLoc(), AliasTemplate->getLocation(),
+  AliasTemplate->getEndLoc(), DG->isImplicit()));
+
+  // FIXME: Here the synthesized deduction guide is not a templated 
function.
+  // Per [dcl.decl]p4, the requires-clause shall be present only if the
+  // declarator declares a templated function, a bug in standard?
+  auto *Constraint = buildIsDeducibleConstraint(
+  SemaRef, AliasTemplate, Transformed->getReturnType(), {});
+  

[clang] [LinkerWrapper] Pass all files to the device linker (PR #97573)

2024-07-08 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/97573

>From 7a64ee668b33c912f83d4f848ab72d421f8a1bec Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 24 Jun 2024 15:14:52 -0500
Subject: [PATCH 1/2] [Clang] Introduce 'clang-nvlink-wrappaer' to work around
 'nvlink'

Summary:
The `clang-nvlink-wrapper` is a utility that I removed awhile back
during the transition to the new driver. This patch adds back in a new,
upgraded version that does LTO + archive linking. It's not an easy
choice to reintroduce something I happily deleted, but this is the only
way to move forward with improving GPU support in LLVM.

While NVIDIA provides a linker called 'nvlink', its main interface is
very difficult to work with. It does not provide LTO, or static linking,
requires all files to be named a non-standard `.cubin`, and rejects link
jobs that other linkers would be fine with (i.e empty). I have spent a
great deal of time hacking around this in the GPU `libc` implementation,
where I deliberately avoid LTO and static linking and have about 100
lines of hacky CMake dedicated to storing these files in a format that
the clang-linker-wrapper accepts to avoid this limitation.

The main reason I want to re-intorudce this tool is because I am
planning on creating a more standard C/C++ toolchain for GPUs to use.
This will install files like the following.
```
/lib/nvptx64-nvidia-cuda/libc.a
/lib/nvptx64-nvidia-cuda/libc++.a
/lib/nvptx64-nvidia-cuda/libomp.a
/lib/clang/19/lib/nvptx64-nvidia-cuda/libclang_rt.builtins.a
```
Linking in these libraries will then simply require passing `-lc` like
is already done for non-GPU toolchains. However, this doesn't work with
the currently deficient `nvlink` linker, so I consider this a blocking
issue to massively improving the state of building GPU libraries.

In the future we may be able to convince NVIDIA to port their linker to
`ld.lld`, but for now this is the only workable solution that allows us
to hack around the weird behavior of their closed-source software.
---
 clang/docs/ClangNVLinkWrapper.rst |  64 ++
 clang/docs/index.rst  |   1 +
 clang/lib/Driver/ToolChains/Cuda.cpp  |  61 +-
 clang/lib/Driver/ToolChains/Cuda.h|   3 +
 clang/test/Driver/cuda-cross-compiling.c  |   8 +-
 clang/test/Driver/nvlink-wrapper.c|  65 ++
 clang/test/lit.cfg.py |   1 +
 clang/tools/CMakeLists.txt|   1 +
 .../tools/clang-nvlink-wrapper/CMakeLists.txt |  44 +
 .../ClangNVLinkWrapper.cpp| 776 ++
 .../tools/clang-nvlink-wrapper/NVLinkOpts.td  |  88 ++
 11 files changed, 1055 insertions(+), 57 deletions(-)
 create mode 100644 clang/docs/ClangNVLinkWrapper.rst
 create mode 100644 clang/test/Driver/nvlink-wrapper.c
 create mode 100644 clang/tools/clang-nvlink-wrapper/CMakeLists.txt
 create mode 100644 clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
 create mode 100644 clang/tools/clang-nvlink-wrapper/NVLinkOpts.td

diff --git a/clang/docs/ClangNVLinkWrapper.rst 
b/clang/docs/ClangNVLinkWrapper.rst
new file mode 100644
index 00..0a312bdbf3066f
--- /dev/null
+++ b/clang/docs/ClangNVLinkWrapper.rst
@@ -0,0 +1,64 @@
+
+Clang nvlink Wrapper
+
+
+.. contents::
+   :local:
+
+.. _clang-nvlink-wrapper:
+
+Introduction
+
+
+This tools works as a wrapper around the NVIDIA ``nvlink`` linker. The purpose 
+of this wrapper is to provide an interface similar to the ``ld.lld`` linker 
+while still relying on NVIDIA's proprietary linker to produce the final 
output. 
+Features include, static archive (.a) linking, LTO, and accepting files ending 
+in ``.o`` without error.
+
+Usage
+=
+
+This tool can be used with the following options. Any arguments not intended
+only for the linker wrapper will be forwarded to ``nvlink``.
+
+.. code-block:: console
+
+  OVERVIEW: A utility that wraps around the NVIDIA 'nvlink' linker.
+  This enables static linking and LTO handling for NVPTX targets.
+
+  USAGE: clang-nvlink-wrapper [options] 
+
+  OPTIONS:
+--archSpecify the 'sm_' name of the target architecture.
+--cuda-path=Set the system CUDA path
+--dry-runPrint generated commands without running.
+--feature Specify the '+ptx' freature to use for LTO.
+-g   Specify that this was a debug compile.
+-help-hidden Display all available options
+-helpDisplay available options (--help-hidden for more)
+-L  Add  to the library search path
+-l  Search for library 
+-mllvm  Arguments passed to LLVM, including Clang 
invocations, for which the '-mllvm' prefix is preserved. Use '-mllvm --help' 
for a list of options.
+-o Path to file to write output
+--plugin-opt=jobs=
+ Number of LTO codegen partitions
+--plugi

[clang] [clang] CTAD: Generate deduction guides for alias templates from non-template explicit deduction guides (PR #96686)

2024-07-08 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 8ac6b415e4e5e631410d9cf6a10f15668f663441 
240a56717440df2f857b5aa2fc556ffc3ce4adca -- clang/lib/Sema/SemaTemplate.cpp 
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 55ecddcfa4..b2a654ec78 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3217,11 +3217,12 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 
   // Clone the parameters.
   for (unsigned I = 0, N = DG->getNumParams(); I != N; ++I) {
-const auto* P = DG->getParamDecl(I);
+const auto *P = DG->getParamDecl(I);
 auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(P->getType());
 ParmVarDecl *NewParam = ParmVarDecl::Create(
-SemaRef.Context, G->getDeclContext(), 
DG->getParamDecl(I)->getBeginLoc(),
-P->getLocation(), nullptr, TSI->getType(), TSI, SC_None, nullptr);
+SemaRef.Context, G->getDeclContext(),
+DG->getParamDecl(I)->getBeginLoc(), P->getLocation(), nullptr,
+TSI->getType(), TSI, SC_None, nullptr);
 NewParam->setScopeInfo(0, I);
 FPTL.setParam(I, NewParam);
   }
@@ -3231,9 +3232,9 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   AliasTemplate->getBeginLoc(), AliasTemplate->getLocation(),
   AliasTemplate->getEndLoc(), DG->isImplicit()));
 
-  // FIXME: Here the synthesized deduction guide is not a templated 
function.
-  // Per [dcl.decl]p4, the requires-clause shall be present only if the
-  // declarator declares a templated function, a bug in standard?
+  // FIXME: Here the synthesized deduction guide is not a templated
+  // function. Per [dcl.decl]p4, the requires-clause shall be present only
+  // if the declarator declares a templated function, a bug in standard?
   auto *Constraint = buildIsDeducibleConstraint(
   SemaRef, AliasTemplate, Transformed->getReturnType(), {});
   if (auto *RC = DG->getTrailingRequiresClause()) {

``




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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -0,0 +1,62 @@
+//===-- xray_init.cpp ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// XRay initialisation logic for DSOs.
+//===--===//
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "xray_defs.h"
+#include "xray_flags.h"
+#include "xray_interface_internal.h"
+
+using namespace __sanitizer;
+
+extern "C" {
+extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));

sebastiankreutzer wrote:

The `{start,stop}_xray_instr_map`  symbols are resolved to the begin and end 
addresses of the `xray_instr_map` ELF section. Same for the `xray_fn_idx` 
section.

They are using weak linkage so that if, for whatever reason, these sections 
don't exist, the linker will not fail.
In this case, the XRay runtime will simply not register any patchable sleds. 
I adopted this behavior from the existing `xray_init.cpp`.

Because they are using hidden visibility and each DSO has their own 
`xray_dso_init.cpp` statically linked, these symbols should resolve correctly 
regardless of `RTLD_GLOBAL`/`RTLD_GLOBAL`. 

I therefore think that the situation you describe should be handled correctly. 
I will add tests to verify this.

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


[clang] [clang] CTAD: Generate deduction guides for alias templates from non-template explicit deduction guides (PR #96686)

2024-07-08 Thread Haojian Wu via cfe-commits

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

>From c835f5acbcb9c768c525df835d09fbe301edd197 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 25 Jun 2024 10:16:54 +0200
Subject: [PATCH 1/2] [clang] CTAD: Fix deduction guides for alias are not
 generated from non-template explicit deduction guides.

---
 clang/lib/Sema/SemaTemplate.cpp  | 64 +---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 41 +
 2 files changed, 97 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 07b3f793b3a29d..5fac68fb10617a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2220,8 +2220,12 @@ class ExtractTypeForDeductionGuide
   }
 };
 
-// Build a deduction guide with the specified parameter types.
-FunctionTemplateDecl *buildDeductionGuide(
+// Build a deduction guide using the provided information.
+//
+// A deduction guide can be either a template or a non-template function
+// declaration. If \p TemplateParams is null, a non-template function
+// declaration will be created.
+NamedDecl *buildDeductionGuide(
 Sema &SemaRef, TemplateDecl *OriginalTemplate,
 TemplateParameterList *TemplateParams, CXXConstructorDecl *Ctor,
 ExplicitSpecifier ES, TypeSourceInfo *TInfo, SourceLocation LocStart,
@@ -2247,16 +2251,21 @@ FunctionTemplateDecl *buildDeductionGuide(
 Param->setDeclContext(Guide);
   for (auto *TD : MaterializedTypedefs)
 TD->setDeclContext(Guide);
+  if (isa(DC))
+Guide->setAccess(AS_public);
+
+  if (!TemplateParams) {
+DC->addDecl(Guide);
+return Guide;
+  }
 
   auto *GuideTemplate = FunctionTemplateDecl::Create(
   SemaRef.Context, DC, Loc, DeductionGuideName, TemplateParams, Guide);
   GuideTemplate->setImplicit(IsImplicit);
   Guide->setDescribedFunctionTemplate(GuideTemplate);
 
-  if (isa(DC)) {
-Guide->setAccess(AS_public);
+  if (isa(DC))
 GuideTemplate->setAccess(AS_public);
-  }
 
   DC->addDecl(GuideTemplate);
   return GuideTemplate;
@@ -2898,7 +2907,8 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
   ASTContext &Context = SemaRef.Context;
   // Constraint AST nodes must use uninstantiated depth.
   if (auto *PrimaryTemplate =
-  AliasTemplate->getInstantiatedFromMemberTemplate()) {
+  AliasTemplate->getInstantiatedFromMemberTemplate();
+  PrimaryTemplate && TemplateParams.size() > 0) {
 LocalInstantiationScope Scope(SemaRef);
 
 // Adjust the depth for TemplateParams.
@@ -3162,12 +3172,12 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 FPrimeTemplateParams,
 AliasTemplate->getTemplateParameters()->getRAngleLoc(),
 /*RequiresClause=*/RequiresClause);
-FunctionTemplateDecl *Result = buildDeductionGuide(
+auto *Result = cast(buildDeductionGuide(
 SemaRef, AliasTemplate, FPrimeTemplateParamList,
 GG->getCorrespondingConstructor(), GG->getExplicitSpecifier(),
 GG->getTypeSourceInfo(), AliasTemplate->getBeginLoc(),
 AliasTemplate->getLocation(), AliasTemplate->getEndLoc(),
-F->isImplicit());
+F->isImplicit()));
 cast(Result->getTemplatedDecl())
 ->setDeductionCandidateKind(GG->getDeductionCandidateKind());
 return Result;
@@ -3198,6 +3208,44 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   Guides.suppressDiagnostics();
 
   for (auto *G : Guides) {
+if (auto *DG = dyn_cast(G)) {
+  // The deduction guide is a non-template function decl, we just clone it.
+  auto *FunctionType =
+  SemaRef.Context.getTrivialTypeSourceInfo(DG->getType());
+  FunctionProtoTypeLoc FPTL =
+  FunctionType->getTypeLoc().castAs();
+
+  // Clone the parameters.
+  unsigned ProcessedParamIndex = 0;
+  for (auto *P : DG->parameters()) {
+auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(P->getType());
+ParmVarDecl *NewParam = ParmVarDecl::Create(
+SemaRef.Context, G->getDeclContext(), P->getBeginLoc(),
+P->getLocation(), nullptr, TSI->getType(), TSI, SC_None, nullptr);
+NewParam->setScopeInfo(0, ProcessedParamIndex);
+FPTL.setParam(ProcessedParamIndex, NewParam);
+ProcessedParamIndex++;
+  }
+  auto *Transformed = cast(buildDeductionGuide(
+  SemaRef, AliasTemplate, /*TemplateParams=*/nullptr,
+  /*Constructor=*/nullptr, DG->getExplicitSpecifier(), FunctionType,
+  AliasTemplate->getBeginLoc(), AliasTemplate->getLocation(),
+  AliasTemplate->getEndLoc(), DG->isImplicit()));
+
+  // FIXME: Here the synthesized deduction guide is not a templated 
function.
+  // Per [dcl.decl]p4, the requires-clause shall be present only if the
+  // declarator declares a templated function, a bug in standard?
+  auto *Constraint = buildIsDeducibleConstraint(
+  SemaRef, AliasTemplate, Transformed->getReturnType(), {});
+  

[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits


@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int &i);",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__))\nint j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__))\ninline int f(int 
&i);",

hnakamura5 wrote:

Also '\n' here.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 commented:

There are small suggestions on the format of test.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits


@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int &i);",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);

hnakamura5 wrote:

How about breaking the string and the line after '\n' ?

```suggestion
  verifyFormat("__attribute__((__warn_unused_result__))\n"
   "const int i;",
   Style);
```
↑ Test cases around look like that.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits


@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int &i);",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__))\nint j;",

hnakamura5 wrote:

Same as above.

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


[clang] [clang] Add -Wimplicit-fallthrough to -Wextra (PR #97926)

2024-07-08 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman please review
> 
> I don't know how to go about measuring if there even is a performance 
> regression. How would I do that?

I would put up a branch on http://llvm-compile-time-tracker.com (instructions 
in the `About` page) and see how this impacts compile times. We've always left 
diagnostics out of -Wextra that require a CFG, so getting performance 
measurements is important.

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


[clang] [hexagon] Add {con, de}structive interference size defn (PR #94877)

2024-07-08 Thread Aaron Ballman via cfe-commits

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

LGTM, thank you!

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


[clang] [C23] Add INFINITY and NAN macros to (PR #96659)

2024-07-08 Thread via cfe-commits

bgra8 wrote:

@AaronBallman 
[N2848](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2848.pdf) explicitly 
mentions that `NAN` and `INFINITY` macros should  expand to a constant 
expression of type `float` not `double` like was implemented in this patch.

`__builtin_nanf` and `__builtin_inff` should have been used instead, right?

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


[clang] [llvm] [AArch64][RISCV] Improve the tests for --print-enabled-extensions and --print-supported-extensions (PR #97829)

2024-07-08 Thread Tomas Matheson via cfe-commits

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


[clang] [llvm] [AArch64][RISCV] Improve the tests for --print-enabled-extensions and --print-supported-extensions (PR #97829)

2024-07-08 Thread Tomas Matheson via cfe-commits


@@ -0,0 +1,24 @@
+// REQUIRES: aarch64-registered-target

tmatheson-arm wrote:

I've kept them as-is so that they still correspond to the [generating 
script](https://gist.github.com/tmatheson-arm/333dd14cc1c95ab4ac563ed615add95d).

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


[clang] [C23] Add INFINITY and NAN macros to (PR #96659)

2024-07-08 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman 
> [N2848](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2848.pdf) 
> explicitly mentions that `NAN` and `INFINITY` macros should expand to a 
> constant expression of type `float` not `double` like was implemented in this 
> patch.
> 
> `__builtin_nanf` and `__builtin_inff` should have been used instead, right?

WHOOSSS yup, looks like I also missed some test coverage. :-D I'll get 
that fixed up ASAP, thank you!

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Brian Cain via cfe-commits


@@ -346,8 +392,8 @@ else() # not Apple
   DEFS ${XRAY_COMMON_DEFINITIONS}
   OBJECT_LIBS RTXrayBASIC
   PARENT_TARGET xray)
-   # Profiler Mode runtime
-   add_compiler_rt_runtime(clang_rt.xray-profiling
+# Profiler Mode runtime
+add_compiler_rt_runtime(clang_rt.xray-profiling

androm3da wrote:

no - as long as it's intentional, leave it as-is

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits


@@ -0,0 +1,62 @@
+//===-- xray_init.cpp ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// XRay initialisation logic for DSOs.
+//===--===//
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "xray_defs.h"
+#include "xray_flags.h"
+#include "xray_interface_internal.h"
+
+using namespace __sanitizer;
+
+extern "C" {
+extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));

sebastiankreutzer wrote:

To your second point: 

With `-fxray-enable`, are you refering to the general `-fxray-instrument` flag 
or `-fxray-enable-shared`?

If the main executable was built entirely without `-fxray-instrument`, linking 
the DSO will fail, as the `__xray_register_dso` and `__xray_deregister_dso` 
functions could not be resolved.

Otherwise, the XRay runtime will currently always work with instrumented DSOs,  
regardless of whether the executable was compiled with `-fxray-enable-shared` 
or not.
I don't see a reason to change this, since IMO there is no benefit (performance 
or otherwise) from disabling this feature statically.

I can see practical use cases where one might want to explicitly disable 
patching DSOs (all or a specific subset).
We could handle this by adding a runtime option, e.g. 
`xray_patch_dsos=true/false/list of names`.
However, this would probably be best as a separate PR. 

Let me know what you think.

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Brian Cain via cfe-commits


@@ -471,42 +518,123 @@ uint16_t __xray_register_event_type(
 }
 
 XRayPatchingStatus __xray_patch() XRAY_NEVER_INSTRUMENT {
-  return controlPatching(true);
+  XRayPatchingStatus CombinedStatus{SUCCESS};

androm3da wrote:

> We could add an assertion to make this assumption explicit. What do you think?

Yeah - good idea, if it's easily done.

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


[clang] [clang] Lower _BitInt(129+) to a different type in LLVM IR (PR #91364)

2024-07-08 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping!

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


[clang] [llvm] [AArch64][RISCV] Improve the tests for --print-enabled-extensions and --print-supported-extensions (PR #97829)

2024-07-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot2` while building `clang,llvm` at step 2 
"annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/i386-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m32', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: 
note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 4348 of 9965 tests, 80 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80
FAIL: libFuzzer-i386-default-Linux :: fuzzer-finalstats.test (1446 of 4348)
 TEST 'libFuzzer-i386-default-Linux :: 
fuzzer-finalstats.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/sanitizer-x86_64-linux/build/build_debug/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/SimpleTest.cpp
 -o 
/b/sanitizer-x86_64-linux/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386DefaultLinuxConfig/Output/fuzzer-finalstats.test.tmp-SimpleTest
+ /b/sanitizer-x86_64-linux/build/build_debug/./bin/clang -Wthread-safety 
-Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 
-gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/SimpleTest.cpp
 -o 
/b/sanitizer-x86_64-linux/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386DefaultLinuxConfig/Output/fuzzer-finalstats.test.tmp-SimpleTest
RUN: at line 2: 
/b/sanitizer-x86_64-

[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-07-08 Thread Michael Kruse via cfe-commits

Meinersbur wrote:

Using git bisect, I tracked down Flang not working anymore on Windows to this 
PR:

```
> flang-new hello.f90 -o hello
flang-new version 19.0.0git
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\meinersbur\build\llvm-project\release\bin
Build config: +assertions
 "C:\\Users\\meinersbur\\build\\llvm-project\\release\\bin\\flang-new" -fc1 
-triple x86_64-pc-windows-msvc19.40.33811 -emit-obj -fcolor-diagnostics 
-mrelocation-model pic -pic-level 2 -target-cpu x86-64 
--dependent-lib=clang_rt.builtins-x86_64.lib -D_MT --dependent-lib=libcmt 
--dependent-lib=Fortran_main.static.lib 
--dependent-lib=FortranRuntime.static.lib 
--dependent-lib=FortranDecimal.static.lib -D_MSC_VER=1940 
-D_MSC_FULL_VER=194033811 -D_WIN32 -D_M_X64=100 -mframe-pointer=none -o 
"C:\\Users\\MEINER~1\\AppData\\Local\\Temp\\hello-2ee671.o" -x f95-cpp-input 
hello.f90
 "C:\\Program Files\\Microsoft Visual 
Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\link.exe"
 -out:hello "-libpath:C:\\Users\\meinersbur\\build\\llvm-project\\release\\lib" 
/WHOLEARCHIVE:Fortran_main.static.lib /subsystem:console 
"-libpath:C:\\Users\\meinersbur\\build\\llvm-project\\release\\lib\\clang\\19\\lib\\windows"
 -nologo "C:\\Users\\MEINER~1\\AppData\\Local\\Temp\\hello-2ee671.o"
LINK : fatal error LNK1104: cannot open file 'clang_rt.builtins.lib'
flang-new: error: linker command failed with exit code 1104 (use -v to see 
invocation)
```

Before this commit, `/DEFAULTLIB:clang_rt.builtins-x86_64.lib` the linking 
directive, now it is `/DEFAULTLIB:clang_rt.builtins-x86_64.lib`. Turns out, 
`clang_rt.builtins-x86_64.lib` is actually shipped with the MSVC compiler 
(`C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Tools\MSVC\\lib\x64`, possibly for Sanitizer 
support in MSVC), which makes the former work, but not the latter.

With `-DLLVM_ENABLE_PROJECTS=compiler-rt`, the resource-dir 
`build\llvm-project\release\lib\clang\19\lib\windows` is filled with 
`clang_rt.builtins-x86_64.lib` et.al., but also changes it back to 
`/DEFAULTLIB:clang_rt.builtins-x86_64.lib`, and it works again.





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


[clang] 2f2b931 - [C23] Correct the type for INFINITY and NAN in freestanding

2024-07-08 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-07-08T09:10:25-04:00
New Revision: 2f2b931e1296aebe6c03fd969363683b637973e5

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

LOG: [C23] Correct the type for INFINITY and NAN in freestanding

This amends bcb7c38af7de59f3b2201734ee11987839cd7bbe to correct the
type use for the two macros to be float rather than double. Also adds
additional test coverage.

https://github.com/llvm/llvm-project/issues/98018 was filed to track
the duplicate diagnostic issue that was discovered.

Added: 


Modified: 
clang/lib/Headers/float.h
clang/test/Headers/float.c

Removed: 




diff  --git a/clang/lib/Headers/float.h b/clang/lib/Headers/float.h
index a565a33243df1..49d4212414d64 100644
--- a/clang/lib/Headers/float.h
+++ b/clang/lib/Headers/float.h
@@ -164,8 +164,8 @@
 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
 !defined(__STRICT_ANSI__)
/* C23 5.2.5.3.3p29-30 */
-#  define INFINITY (__builtin_inf())
-#  define NAN (__builtin_nan(""))
+#  define INFINITY (__builtin_inff())
+#  define NAN (__builtin_nanf(""))
 #endif
 
 #ifdef __STDC_WANT_IEC_60559_TYPES_EXT__

diff  --git a/clang/test/Headers/float.c b/clang/test/Headers/float.c
index b9e6e971545e5..218ab58ba62ef 100644
--- a/clang/test/Headers/float.c
+++ b/clang/test/Headers/float.c
@@ -2,11 +2,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -ffreestanding %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -ffreestanding 
-ffinite-math-only %s
+// RUN: %clang_cc1 -fsyntax-only -verify=finite -std=c23 -ffreestanding 
-ffinite-math-only %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++11 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++14 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++17 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++23 -ffreestanding %s
+// NOTE: C++23 wasn't based on top of C23, so it gets no diagnostics for
+//   finite-math-only mode as happens in C. When C++ rebased onto C23, that
+//   is when we'll issue diagnostics for INFINITY and NAN use.
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++23 -ffreestanding 
-ffinite-math-only %s
 // expected-no-diagnostics
 
@@ -218,6 +221,10 @@
   #ifndef NAN
 #error "Mandatory macro NAN is missing."
   #endif
+  // FIXME: the NAN diagnostic should only be issued once, not twice.
+  _Static_assert(_Generic(INFINITY, float : 1, default : 0), ""); // 
finite-warning {{use of infinity via a macro is undefined behavior due to the 
currently enabled floating-point options}}
+  _Static_assert(_Generic(NAN, float : 1, default : 0), ""); // finite-warning 
{{use of NaN is undefined behavior due to the currently enabled floating-point 
options}} \
+finite-warning 
{{use of NaN via a macro is undefined behavior due to the currently enabled 
floating-point options}}
 #else
   #ifdef INFINITY
 #error "Macro INFINITY should not be defined."



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


[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)

2024-07-08 Thread Simon Pilgrim via cfe-commits

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


[clang] [clang] Lower _BitInt(129+) to a different type in LLVM IR (PR #91364)

2024-07-08 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Ping!

CC @rjmccall and @efriedma-quic -- we're still hoping to get this resolved for 
Clang 19 and the branch date is Tue Jul 23, so it's coming up quickly.

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


[clang] [C23] Add INFINITY and NAN macros to (PR #96659)

2024-07-08 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > @AaronBallman 
> > [N2848](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2848.pdf) 
> > explicitly mentions that `NAN` and `INFINITY` macros should expand to a 
> > constant expression of type `float` not `double` like was implemented in 
> > this patch.
> > `__builtin_nanf` and `__builtin_inff` should have been used instead, right?
> 
> WHOOSSS yup, looks like I also missed some test coverage. :-D I'll 
> get that fixed up ASAP, thank you!

This should be fixed now in 2f2b931e1296aebe6c03fd969363683b637973e5, thank you!

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


[clang] ba1d21c - [C2y] Claim conformance to WG14 N3254 (#97581)

2024-07-08 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-07-08T09:13:24-04:00
New Revision: ba1d21c7d8613c90e424fa3e77d52184d531c302

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

LOG: [C2y] Claim conformance to WG14 N3254 (#97581)

The test coverage for this has to lean on LLVM's test coverage for the
actual TBAA behavior, but this demonstrates that Clang emits reasonable
LLVM IR to support this construct. It would be surprising should LLVM
break this pattern given how ubiquitous the pattern is in the wild.

The paper can be found at:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3254.pdf

Added: 
clang/test/C/C2y/n3254.c

Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C2y/n3254.c b/clang/test/C/C2y/n3254.c
new file mode 100644
index 0..e08659cf377aa
--- /dev/null
+++ b/clang/test/C/C2y/n3254.c
@@ -0,0 +1,149 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple=x86_64 -std=c2y %s -emit-llvm -o - | FileCheck %s
+
+/* WG14 N3254: Yes
+ * Accessing byte arrays
+ *
+ * NB: this basically boils down to how LLVM handles TBAA, so the best we can
+ * do for a Clang test is to test that the LLVM IR we pass is reasonable and we
+ * presume that LLVM has the test coverage to ensure that this behavior isn't
+ * regressed.
+ */
+
+struct S {
+  int x;
+  char c;
+  float f;
+};
+
+#define DECL_BUFFER(Ty, Name) alignas(Ty) unsigned char Name[sizeof(Ty)]
+
+// CHECK-LABEL: define dso_local i32 @foo(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[BUFFER:%.*]] = alloca [12 x i8], align 1
+// CHECK-NEXT:[[S_PTR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 1 [[BUFFER]], i8 0, 
i64 12, i1 false)
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [12 x i8], ptr 
[[BUFFER]], i64 0, i64 0
+// CHECK-NEXT:store ptr [[ARRAYDECAY]], ptr [[S_PTR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[S_PTR]], align 8
+// CHECK-NEXT:[[X:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr 
[[TMP0]], i32 0, i32 0
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+//
+int foo() {
+  DECL_BUFFER(struct S, buffer) = {};
+  struct S *s_ptr = (struct S *)buffer;
+  return s_ptr->x;
+}
+
+// CHECK-LABEL: define dso_local signext i8 @bar(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[BUFFER:%.*]] = alloca [12 x i8], align 1
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [12 x i8], ptr 
[[BUFFER]], i64 0, i64 0
+// CHECK-NEXT:[[C:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr 
[[ARRAYDECAY]], i32 0, i32 1
+// CHECK-NEXT:store i8 97, ptr [[C]], align 1
+// CHECK-NEXT:[[ARRAYDECAY1:%.*]] = getelementptr inbounds [12 x i8], ptr 
[[BUFFER]], i64 0, i64 0
+// CHECK-NEXT:[[C2:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr 
[[ARRAYDECAY1]], i32 0, i32 1
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, ptr [[C2]], align 1
+// CHECK-NEXT:ret i8 [[TMP0]]
+//
+char bar() {
+  DECL_BUFFER(struct S, buffer);
+  ((struct S *)buffer)->c = 'a';
+  return ((struct S *)buffer)->c;
+}
+
+// CHECK-LABEL: define dso_local float @baz(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[BUFFER:%.*]] = alloca [12 x i8], align 1
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [12 x i8], ptr 
[[BUFFER]], i64 0, i64 0
+// CHECK-NEXT:[[F:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr 
[[ARRAYDECAY]], i32 0, i32 2
+// CHECK-NEXT:store float 3.00e+00, ptr [[F]], align 1
+// CHECK-NEXT:[[ARRAYDECAY1:%.*]] = getelementptr inbounds [12 x i8], ptr 
[[BUFFER]], i64 0, i64 0
+// CHECK-NEXT:[[F2:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr 
[[ARRAYDECAY1]], i32 0, i32 2
+// CHECK-NEXT:[[TMP0:%.*]] = load float, ptr [[F2]], align 1
+// CHECK-NEXT:ret float [[TMP0]]
+//
+float baz() {
+  DECL_BUFFER(struct S, buffer);
+  ((struct S *)buffer)->f = 3.0f;
+  return ((const struct S *)buffer)->f;
+}
+
+struct T {
+  DECL_BUFFER(struct S, buffer);
+};
+
+// CHECK-LABEL: define dso_local signext i8 @quux(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[T:%.*]] = alloca [[STRUCT_T:%.*]], align 1
+// CHECK-NEXT:[[S_PTR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 1 [[T]], i8 0, i64 
12, i1 false)
+// CHECK-NEXT:[[BUFFER:%.*]] = getelementptr inbounds [[STRUCT_T]], ptr 
[[T]], i32 0, i32 0
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [12 x i8], ptr 
[[BUFFER]], i64 0, i64 0
+// CHECK-NEXT:store ptr [[ARRAYDECAY]], ptr [[S_PTR]], align 8

[clang] [C2y] Claim conformance to WG14 N3254 (PR #97581)

2024-07-08 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-08 Thread via cfe-commits


@@ -1018,6 +1018,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 
 // primary-expression
   case tok::numeric_constant:

cor3ntin wrote:

Can you adapt the couple other places where we parse a numeric constant?

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-08 Thread Sebastian Kreutzer via cfe-commits

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


[clang] [X86][vectorcall] Do not consume register for indirect return value (PR #97939)

2024-07-08 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> I meant, at the beginning of X86_32ABIInfo::computeInfo there's a chain of if 
> statements that set up the properties of different calling conventions, and 
> maybe some bits could be set there. If you don't think that makes sense, 
> though, it's fine.

Thanks @efriedma-quic! I prefer to using the convention name directly. I think 
it's more readable than hiding them under a state bit.

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


[clang] [C23] Add INFINITY and NAN macros to (PR #96659)

2024-07-08 Thread via cfe-commits

bgra8 wrote:

> > > @AaronBallman 
> > > [N2848](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2848.pdf) 
> > > explicitly mentions that `NAN` and `INFINITY` macros should expand to a 
> > > constant expression of type `float` not `double` like was implemented in 
> > > this patch.
> > > `__builtin_nanf` and `__builtin_inff` should have been used instead, 
> > > right?
> > 
> > 
> > WHOOSSS yup, looks like I also missed some test coverage. :-D I'll 
> > get that fixed up ASAP, thank you!
> 
> This should be fixed now in 
> [2f2b931](https://github.com/llvm/llvm-project/commit/2f2b931e1296aebe6c03fd969363683b637973e5),
>  thank you!

Thanks a lot for the quick fix!

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


[clang] [X86][vectorcall] Do not consume register for indirect return value (PR #97939)

2024-07-08 Thread Phoebe Wang via cfe-commits

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


  1   2   3   4   5   >