[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)

2024-04-30 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/89247

From 7138f026e845ebb4f1a3e6a86bdeb534d666ae7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 18 Apr 2024 16:40:03 +0200
Subject: [PATCH 1/5] [clang][analyzer] Move StreamChecker out of the alpha
 package.

---
 clang/docs/analyzer/checkers.rst  | 186 +-
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  31 +--
 clang/test/Analysis/analyzer-config.c |   2 +-
 .../test/Analysis/analyzer-enabled-checkers.c |   1 +
 ...c-library-functions-arg-enabled-checkers.c |   6 +-
 .../std-c-library-functions-arg-weakdeps.c|   4 +-
 ...td-c-library-functions-vs-stream-checker.c |   8 +-
 clang/test/Analysis/stream-errno-note.c   |   4 +-
 clang/test/Analysis/stream-errno.c|   4 +-
 clang/test/Analysis/stream-error.c|   4 +-
 clang/test/Analysis/stream-invalidate.c   |   2 +-
 .../test/Analysis/stream-non-posix-function.c |   2 +-
 clang/test/Analysis/stream-noopen.c   |   2 +-
 clang/test/Analysis/stream-note.c |   8 +-
 clang/test/Analysis/stream-pedantic.c |   8 +-
 .../Analysis/stream-stdlibraryfunctionargs.c  |  10 +-
 clang/test/Analysis/stream.c  |  16 +-
 clang/test/Analysis/stream.cpp|   2 +-
 clang/www/analyzer/alpha_checks.html  |   4 +-
 clang/www/analyzer/open_projects.html |   2 +-
 20 files changed, 154 insertions(+), 152 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fb748d23a53d01..32c2a312962754 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1462,6 +1462,99 @@ checker).
 
 Default value of the option is ``true``.
 
+.. _unix-Stream:
+
+unix.Stream (C)
+"
+Check C stream handling functions:
+``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, 
fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, 
ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
+
+The checker maintains information about the C stream objects (``FILE *``) and
+can detect error conditions related to use of streams. The following conditions
+are detected:
+
+* The ``FILE *`` pointer passed to the function is NULL (the single exception 
is
+  ``fflush`` where NULL is allowed).
+* Use of stream after close.
+* Opened stream is not closed.
+* Read from a stream after end-of-file. (This is not a fatal error but reported
+  by the checker. Stream remains in EOF state and the read operation fails.)
+* Use of stream when the file position is indeterminate after a previous failed
+  operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are
+  allowed in this state.
+* Invalid 3rd ("``whence``") argument to ``fseek``.
+
+The stream operations are by this checker usually split into two cases, a 
success
+and a failure case. However, in the case of write operations (like ``fwrite``,
+``fprintf`` and even ``fsetpos``) this behavior could produce a large amount of
+unwanted reports on projects that don't have error checks around the write
+operations, so by default the checker assumes that write operations always 
succeed.
+This behavior can be controlled by the ``Pedantic`` flag: With
+``-analyzer-config unix.Stream:Pedantic=true`` the checker will model the
+cases where a write operation fails and report situations where this leads to
+erroneous behavior. (The default is ``Pedantic=false``, where write operations
+are assumed to succeed.)
+
+.. code-block:: c
+
+ void test1() {
+   FILE *p = fopen("foo", "r");
+ } // warn: opened file is never closed
+
+ void test2() {
+   FILE *p = fopen("foo", "r");
+   fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
+   fclose(p);
+ }
+
+ void test3() {
+   FILE *p = fopen("foo", "r");
+   if (p) {
+ fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or 
SEEK_CUR
+ fclose(p);
+   }
+ }
+
+ void test4() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fclose(p);
+   fclose(p); // warn: stream already closed
+ }
+
+ void test5() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!ferror(p))
+ fgetc(p); // warn: possible read after end-of-file
+
+   fclose(p);
+ }
+
+ void test6() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!feof(p))
+ fgetc(p); // warn: file position may be indeterminate after I/O error
+
+   fclose(p);
+ }
+
+**Limitations**
+
+The checker does not track the correspondence between integer file descriptors
+and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not
+treated specially and are therefore often not recognized (because these streams
+are usually not opened explicitly by the program, and are global variables).
+
 .. _osx-checkers:
 
 osx
@@ -3116,99 +3209,6 @@ Check for misuse

[clang] 09f160c - [clang][analyzer] Move StreamChecker out of the alpha package. (#89247)

2024-04-30 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-04-30T09:01:45+02:00
New Revision: 09f160c6298255f520b379b88161fbd1c365b308

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

LOG: [clang][analyzer] Move StreamChecker out of the alpha package. (#89247)

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/analyzer-enabled-checkers.c
clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
clang/test/Analysis/std-c-library-functions-arg-weakdeps.c
clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
clang/test/Analysis/stream-errno-note.c
clang/test/Analysis/stream-errno.c
clang/test/Analysis/stream-error.c
clang/test/Analysis/stream-invalidate.c
clang/test/Analysis/stream-non-posix-function.c
clang/test/Analysis/stream-noopen.c
clang/test/Analysis/stream-note.c
clang/test/Analysis/stream-pedantic.c
clang/test/Analysis/stream-stdlibraryfunctionargs.c
clang/test/Analysis/stream.c
clang/test/Analysis/stream.cpp
clang/www/analyzer/alpha_checks.html
clang/www/analyzer/open_projects.html

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index fb748d23a53d01..0d87df36ced0e9 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1462,6 +1462,99 @@ checker).
 
 Default value of the option is ``true``.
 
+.. _unix-Stream:
+
+unix.Stream (C)
+"""
+Check C stream handling functions:
+``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, 
fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, 
ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
+
+The checker maintains information about the C stream objects (``FILE *``) and
+can detect error conditions related to use of streams. The following conditions
+are detected:
+
+* The ``FILE *`` pointer passed to the function is NULL (the single exception 
is
+  ``fflush`` where NULL is allowed).
+* Use of stream after close.
+* Opened stream is not closed.
+* Read from a stream after end-of-file. (This is not a fatal error but reported
+  by the checker. Stream remains in EOF state and the read operation fails.)
+* Use of stream when the file position is indeterminate after a previous failed
+  operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are
+  allowed in this state.
+* Invalid 3rd ("``whence``") argument to ``fseek``.
+
+The stream operations are by this checker usually split into two cases, a 
success
+and a failure case. However, in the case of write operations (like ``fwrite``,
+``fprintf`` and even ``fsetpos``) this behavior could produce a large amount of
+unwanted reports on projects that don't have error checks around the write
+operations, so by default the checker assumes that write operations always 
succeed.
+This behavior can be controlled by the ``Pedantic`` flag: With
+``-analyzer-config unix.Stream:Pedantic=true`` the checker will model the
+cases where a write operation fails and report situations where this leads to
+erroneous behavior. (The default is ``Pedantic=false``, where write operations
+are assumed to succeed.)
+
+.. code-block:: c
+
+ void test1() {
+   FILE *p = fopen("foo", "r");
+ } // warn: opened file is never closed
+
+ void test2() {
+   FILE *p = fopen("foo", "r");
+   fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
+   fclose(p);
+ }
+
+ void test3() {
+   FILE *p = fopen("foo", "r");
+   if (p) {
+ fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or 
SEEK_CUR
+ fclose(p);
+   }
+ }
+
+ void test4() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fclose(p);
+   fclose(p); // warn: stream already closed
+ }
+
+ void test5() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!ferror(p))
+ fgetc(p); // warn: possible read after end-of-file
+
+   fclose(p);
+ }
+
+ void test6() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!feof(p))
+ fgetc(p); // warn: file position may be indeterminate after I/O error
+
+   fclose(p);
+ }
+
+**Limitations**
+
+The checker does not track the correspondence between integer file descriptors
+and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not
+treated specially and are therefore often not recognized (because these streams
+are usually not opened explicitly by the program, and are global variables).
+
 .. _osx-checkers:
 
 osx
@@ -3116,99 +3209,6 @@ Check for misuses of stream APIs. Check for misuses of 
stream APIs: ``fopen, fcl
fclose(F); // war

[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)

2024-04-30 Thread Balázs Kéri via cfe-commits

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-30 Thread Michael Spencer via cfe-commits

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

I did some testing today and this change seems fine. For scanning modules I 
actually saw some get smaller with your change.

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


[clang] [llvm] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-30 Thread via cfe-commits

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


[clang] eb148ae - [LoongArch][Codegen] Add support for TLSDESC

2024-04-30 Thread via cfe-commits

Author: wanglei
Date: 2024-04-30T15:14:44+08:00
New Revision: eb148aecb3603c2ba6ecbdaebd3b8a87f44349bc

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

LOG: [LoongArch][Codegen] Add support for TLSDESC

The implementation only enables when the `-enable-tlsdesc` option is
passed and the TLS model is `dynamic`.

LoongArch's GCC has the same option(-mtls-dialet=) as RISC-V.

Reviewers: heiher, MaskRay, SixWeining

Reviewed By: SixWeining, MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/90159

Added: 
clang/test/CodeGen/LoongArch/tls-dialect.c

Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/tls-dialect.c
llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h
llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.h
llvm/test/CodeGen/LoongArch/tls-models.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index fec11c7e716fdf..6796b43a155020 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
   StringRef V = A->getValue();
   bool SupportedArgument = false, EnableTLSDESC = false;
   bool Unsupported = !Triple.isOSBinFormatELF();
-  if (Triple.isRISCV()) {
+  if (Triple.isLoongArch() || Triple.isRISCV()) {
 SupportedArgument = V == "desc" || V == "trad";
 EnableTLSDESC = V == "desc";
   } else if (Triple.isX86()) {

diff  --git a/clang/test/CodeGen/LoongArch/tls-dialect.c 
b/clang/test/CodeGen/LoongArch/tls-dialect.c
new file mode 100644
index 00..03401ef8af03d4
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/tls-dialect.c
@@ -0,0 +1,14 @@
+// REQUIRES: loongarch-registered-target
+/// cc1 -enable-tlsdesc (due to -mtls-dialect=desc) enables TLSDESC.
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
-enable-tlsdesc %s -o - | FileCheck %s --check-prefix=DESC
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
%s -o - | FileCheck %s --check-prefix=NODESC
+
+__thread int x;
+
+// DESC:   %desc_pc_hi20
+// DESC-NOT:   %gd_pc_hi20
+// NODESC: %gd_pc_hi20
+// NODESC-NOT: %desc_pc_hi20
+int use() {
+  return x;
+}

diff  --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

diff  --git a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp 
b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
index ad39658f698e7b..c136f5b3e515d7 100644
--- a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
@@ -80,6 +80,9 @@ class LoongArchPreRAExpandPseudo : public MachineFunctionPass 
{
   bool expandLoadAddressTLSGD(MachineBasicBlock &MBB,
 

[clang] [llvm] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-30 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

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

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


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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-04-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/89807

>From 1756044e71d756f7102f962d0298627ede27871c Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Tue, 9 Apr 2024 01:14:28 -0300
Subject: [PATCH] [clang] Enable C++17 relaxed template template argument
 matching by default

In order to implement this as a DR and avoid breaking reasonable code
that worked before P0522, this patch implements a provisional resolution
for CWG2398: When deducing template template parameters against each other,
and the argument side names a template specialization, instead of just
deducing A, we instead deduce a synthesized template template parameter based
on A, but with it's parameters using the template specialization's arguments
as defaults.

The driver flag is deprecated with a warning.

With this patch, we finally mark C++17 support in clang as complete.

Fixes https://github.com/llvm/llvm-project/issues/36505
---
 clang/docs/ReleaseNotes.rst   |  19 +++
 .../clang/Basic/DiagnosticDriverKinds.td  |   2 +-
 clang/include/clang/Basic/LangOptions.def |   2 +-
 clang/include/clang/Driver/Options.td |   8 +-
 clang/lib/Driver/SanitizerArgs.cpp|   9 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  16 +-
 clang/lib/Sema/SemaTemplate.cpp   |   3 -
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 107 +-
 .../temp/temp.arg/temp.arg.template/p3-2a.cpp |   2 +-
 clang/test/CodeGenCXX/mangle-concept.cpp  |   4 +-
 .../frelaxed-template-template-args.cpp   |   5 +
 clang/test/Lexer/cxx-features.cpp |   6 +-
 clang/test/SemaTemplate/cwg2398.cpp   | 139 ++
 clang/test/SemaTemplate/default-arguments.cpp |   7 +-
 .../instantiate-template-template-parm.cpp|  17 +--
 clang/test/SemaTemplate/nested-template.cpp   |   8 +-
 clang/test/SemaTemplate/temp_arg_template.cpp |   6 +-
 .../SemaTemplate/temp_arg_template_cxx1z.cpp  |   2 +-
 clang/www/cxx_status.html |  18 +--
 19 files changed, 317 insertions(+), 63 deletions(-)
 create mode 100644 clang/test/Driver/frelaxed-template-template-args.cpp
 create mode 100644 clang/test/SemaTemplate/cwg2398.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..bd7f96246fd407 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -48,6 +48,11 @@ C++ Specific Potentially Breaking Changes
 - Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
   This error can be disabled via `-Wno-strict-primary-template-shadow` for 
compatibility with previous versions of clang.
 
+- The behavior controlled by the `-frelaxed-template-template-args` flag is now
+  on by default, and the flag is deprecated. Until the flag is finally removed,
+  it's negative spelling can be used to obtain compatibility with previous
+  versions of clang.
+
 ABI Changes in This Version
 ---
 - Fixed Microsoft name mangling of implicitly defined variables used for thread
@@ -88,6 +93,17 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- C++17 support is now completed, with the enablement of the
+  relaxed temlate template argument matching rules introduced in P0522,
+  which was retroactively applied as a defect report.
+  While the implementation already existed since Clang 4, it was turned off by
+  default, and was controlled with the `-frelaxed-template-template-args` flag.
+  In this release, we implement provisional wording for a core defect on
+  P0522 (CWG2398), which avoids the most serious compatibility issues caused
+  by it, allowing us to enable it by default in this release.
+  The flag is now deprecated, and will be removed in the next release, but can
+  still be used to turn it off and regain compatibility with previous versions
+  (#GH36505).
 - Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++17 Feature Support
@@ -164,6 +180,9 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- P0522 implementation is enabled by default in all language versions, and
+  provisional wording for CWG2398 is implemented.
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ed3fd9b1c4a55b..9781fcaa4ff5e9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -435,7 +435,7 @@ def warn_drv_diagnostics_misexpect_requires_pgo : Warning<
 def warn_drv_clang_unsupported : Wa

[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

2024-04-30 Thread Mital Ashok via cfe-commits


@@ -67,6 +68,69 @@ void B::g() requires true;
 
 } // namespace cwg2847
 
+namespace cwg2851 { // cwg2851: 19
+
+#if __cplusplus >= 202002L
+template struct Val { static constexpr T value = v; };
+
+
+// Floating-point promotions
+
+static_assert(Val::value == 0.0L);
+static_assert(Val::value == 0.0L);
+static_assert(Val::value == 0.0);
+static_assert(Val::value == -0.0L);
+
+static_assert(!__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val(__builtin_nanf(""))>));
+static_assert(__is_same(Val, Val(__builtin_nansf(""))>));
+static_assert(__is_same(Val, Val(__builtin_nanf("0x1"))>));
+static_assert(__is_same(Val, Val(__builtin_nansf("0x1"))>));
+
+
+// Floating-point conversions where the source value can be represented 
exactly in the destination type
+
+static_assert(Val::value == 0.0L);
+static_assert(__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+static_assert(!__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val));
+Val _1;
+// since-cxx20-error-re@-1 {{non-type template argument evaluates to {{.+}} 
which cannot be exactly represented in type 'float'}}
+Val(__FLT_DENORM_MIN__) / 2.0L> _2;
+// since-cxx20-error-re@-1 {{non-type template argument evaluates to {{.+}} 
which cannot be exactly represented in type 'float'}}
+Val _3;
+// since-cxx20-error-re@-1 {{non-type template argument evaluates to {{.+}} 
which cannot be exactly represented in type 'float'}}
+
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val(__builtin_nanl(""))>));
+static_assert(__is_same(Val, Val(__builtin_nansl(""))>));
+#if __SIZEOF_LONG_DOUBLE__ > 8
+// since-cxx20-error@-2 {{non-type template argument evaluates to nan which 
cannot be exactly represented in type 'float'}}
+#endif
+// Payload is shifted right so these payloads will be preserved
+static_assert(__is_same(Val, Val(__builtin_nan("0xFF"))>));
+static_assert(__is_same(Val, Val(__builtin_nans("0xFF"))>));
+static_assert(__is_same(Val, Val(__builtin_nanl("0x1"))>));

MitalAshok wrote:

I'm not sure how exactly we plan to deal with `NaN`. How `APFloat::convert` 
seems to work is that when converting to a smaller type, only the most 
significant bits of the payload are used, so that 1 is cut off (thus lossy).

This has the side effect that `Val` and `Val` always work, because `(long double) 
__builtin_nanf(payload)` is like `__builtin_nanl(payload << (difference in 
number of fraction bits between long double and float))`, and anything with the 
lower bits set counts as "lossy". Anything implicitly converted to a larger 
type can be converted back in a converted constant expression. See also: 
IEEE754 6.2.3 "NaN propagation"

CWG2864 is about narrowing conversions. For sure `float{__builtin_nanl("0x1")}` 
isn't a narrowing conversion because it's not finite, but it does lose the 
payload entirely (`float{__builtin_nanl("0x1")}` and 
`float{__builtin_nanl("0x0")}` have the same bit pattern, even though the 
source long doubles don't). But maybe we should consider all NaNs to have the 
same "value" and this should work?

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


[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

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

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/90570

…te module file for C++20 modules instead of PCHGenerator

Previously we're re-using PCHGenerator to generate the module file for C++20 
modules. But this is slighty more or less odd. This patch tries to use a new 
class 'CXX20ModulesGenerator' to generate the module file for C++20 modules.

>From 7a8214efbfc1cc5e16c22bd7e3a21061d5a9555c Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 30 Apr 2024 13:28:52 +0800
Subject: [PATCH] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator
 to generate module file for C++20 modules instead of PCHGenerator

Previously we're re-using PCHGenerator to generate the module file for
C++20 modules. But this is slighty more or less odd. This patch tries
to use a new class 'CXX20ModulesGenerator' to generate the module file
for C++20 modules.
---
 clang/include/clang/Serialization/ASTWriter.h | 23 ++---
 clang/lib/Frontend/FrontendActions.cpp| 11 +++-
 clang/lib/Serialization/GeneratePCH.cpp   | 25 +++
 clang/test/Modules/pr67893.cppm   |  2 +-
 clang/test/Modules/search-partitions.cpp  |  8 +++---
 5 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 6c45b7348b8552..259208b7a91aec 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -885,6 +885,8 @@ class ASTWriter : public ASTDeserializationListener,
 /// AST and semantic-analysis consumer that generates a
 /// precompiled header from the parsed source code.
 class PCHGenerator : public SemaConsumer {
+  void anchor() override;
+
   Preprocessor &PP;
   std::string OutputFile;
   std::string isysroot;
@@ -928,17 +930,32 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
-class ReducedBMIGenerator : public PCHGenerator {
+class CXX20ModulesGenerator : public PCHGenerator {
+  void anchor() override;
 protected:
   virtual Module *getEmittingModule(ASTContext &Ctx) override;
 
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile, bool GeneratingReducedBMI);
+
 public:
-  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-  StringRef OutputFile);
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/false) {}
 
   void HandleTranslationUnit(ASTContext &Ctx) override;
 };
 
+class ReducedBMIGenerator : public CXX20ModulesGenerator {
+  void anchor() override;
+public:
+  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+  StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/true) {}
+};
+
 /// If we can elide the definition of \param D in reduced BMI.
 ///
 /// Generally, we can elide the definition of a declaration if it won't affect
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 480dfa8c975933..454653a31534cd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -272,13 +272,10 @@ bool GenerateModuleInterfaceAction::BeginSourceFileAction(
 std::unique_ptr
 GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) {
-  CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true;
-  CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true;
-
-  std::vector> Consumers =
-  CreateMultiplexConsumer(CI, InFile);
-  if (Consumers.empty())
-return nullptr;
+  std::vector> Consumers;
+  Consumers.push_back(std::make_unique(
+  CI.getPreprocessor(), CI.getModuleCache(),
+  CI.getFrontendOpts().OutputFile));
 
   if (CI.getFrontendOpts().GenReducedBMI &&
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {
diff --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index a2ddbe4624aae4..cc06106a47708e 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -88,31 +88,30 @@ ASTDeserializationListener 
*PCHGenerator::GetASTDeserializationListener() {
   return &Writer;
 }
 
-ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor &PP,
- InMemoryModuleCache &ModuleCache,
- StringRef OutputFile)
+void PCHGenerator::anchor() {}
+
+CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP,
+ InMemoryModuleCache &ModuleCache,
+   

[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

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

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


[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

…te module file for C++20 modules instead of PCHGenerator

Previously we're re-using PCHGenerator to generate the module file for C++20 
modules. But this is slighty more or less odd. This patch tries to use a new 
class 'CXX20ModulesGenerator' to generate the module file for C++20 modules.

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


5 Files Affected:

- (modified) clang/include/clang/Serialization/ASTWriter.h (+20-3) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+4-7) 
- (modified) clang/lib/Serialization/GeneratePCH.cpp (+14-11) 
- (modified) clang/test/Modules/pr67893.cppm (+1-1) 
- (modified) clang/test/Modules/search-partitions.cpp (+3-5) 


``diff
diff --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 6c45b7348b8552..259208b7a91aec 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -885,6 +885,8 @@ class ASTWriter : public ASTDeserializationListener,
 /// AST and semantic-analysis consumer that generates a
 /// precompiled header from the parsed source code.
 class PCHGenerator : public SemaConsumer {
+  void anchor() override;
+
   Preprocessor &PP;
   std::string OutputFile;
   std::string isysroot;
@@ -928,17 +930,32 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
-class ReducedBMIGenerator : public PCHGenerator {
+class CXX20ModulesGenerator : public PCHGenerator {
+  void anchor() override;
 protected:
   virtual Module *getEmittingModule(ASTContext &Ctx) override;
 
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile, bool GeneratingReducedBMI);
+
 public:
-  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-  StringRef OutputFile);
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/false) {}
 
   void HandleTranslationUnit(ASTContext &Ctx) override;
 };
 
+class ReducedBMIGenerator : public CXX20ModulesGenerator {
+  void anchor() override;
+public:
+  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+  StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/true) {}
+};
+
 /// If we can elide the definition of \param D in reduced BMI.
 ///
 /// Generally, we can elide the definition of a declaration if it won't affect
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 480dfa8c975933..454653a31534cd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -272,13 +272,10 @@ bool GenerateModuleInterfaceAction::BeginSourceFileAction(
 std::unique_ptr
 GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) {
-  CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true;
-  CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true;
-
-  std::vector> Consumers =
-  CreateMultiplexConsumer(CI, InFile);
-  if (Consumers.empty())
-return nullptr;
+  std::vector> Consumers;
+  Consumers.push_back(std::make_unique(
+  CI.getPreprocessor(), CI.getModuleCache(),
+  CI.getFrontendOpts().OutputFile));
 
   if (CI.getFrontendOpts().GenReducedBMI &&
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {
diff --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index a2ddbe4624aae4..cc06106a47708e 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -88,31 +88,30 @@ ASTDeserializationListener 
*PCHGenerator::GetASTDeserializationListener() {
   return &Writer;
 }
 
-ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor &PP,
- InMemoryModuleCache &ModuleCache,
- StringRef OutputFile)
+void PCHGenerator::anchor() {}
+
+CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP,
+ InMemoryModuleCache &ModuleCache,
+ StringRef OutputFile,
+ bool GeneratingReducedBMI)
 : PCHGenerator(
   PP, ModuleCache, OutputFile, llvm::StringRef(),
   std::make_shared(),
   /*Extensions=*/ArrayRef>(),
   /*AllowASTWithErrors*/ false, /*IncludeTimestamps=*/false,
   /*BuildingImplicitModule=*/false, /*ShouldCacheASTInMemory=*/false,
-  /*Generat

[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

2024-04-30 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 91a8cb781dbc981356207e0c3608d92ed6d26042 
7a8214efbfc1cc5e16c22bd7e3a21061d5a9555c -- 
clang/include/clang/Serialization/ASTWriter.h 
clang/lib/Frontend/FrontendActions.cpp clang/lib/Serialization/GeneratePCH.cpp 
clang/test/Modules/pr67893.cppm clang/test/Modules/search-partitions.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 259208b7a9..6f64ece9c5 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -932,6 +932,7 @@ public:
 
 class CXX20ModulesGenerator : public PCHGenerator {
   void anchor() override;
+
 protected:
   virtual Module *getEmittingModule(ASTContext &Ctx) override;
 
@@ -949,6 +950,7 @@ public:
 
 class ReducedBMIGenerator : public CXX20ModulesGenerator {
   void anchor() override;
+
 public:
   ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
   StringRef OutputFile)

``




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


[clang] [Modules] No transitive source location change (PR #86912)

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

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


[clang] 6c31104 - [Modules] No transitive source location change (#86912)

2024-04-30 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-30T15:57:58+08:00
New Revision: 6c3110464bac3600685af9650269b0b2b8669d34

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

LOG: [Modules] No transitive source location change (#86912)

This is part of "no transitive change" patch series, "no transitive
source location change". I talked this with @Bigcheese in the tokyo's
WG21 meeting.

The idea comes from @jyknight posted on LLVM discourse. That for:

```
// A.cppm
export module A;
...

// B.cppm
export module B;
import A;
...

//--- C.cppm
export module C;
import C;
```

Almost every time A.cppm changes, we need to recompile `B`. Due to we
think the source location is significant to the semantics. But it may be
good if we can avoid recompiling `C` if the change from `A` wouldn't
change the BMI of B.

# Motivation Example

This patch only cares source locations. So let's focus on source
location's example. We can see the full example from the attached test.

```
//--- A.cppm
export module A;
export template 
struct C {
T func() {
return T(43);
}
};
export int funcA() {
return 43;
}

//--- A.v1.cppm
export module A;

export template 
struct C {
T func() {
return T(43);
}
};
export int funcA() {
return 43;
}

//--- B.cppm
export module B;
import A;

export int funcB() {
return funcA();
}

//--- C.cppm
export module C;
import A;
export void testD() {
C c;
c.func();
}
```

Here the only difference between `A.cppm` and `A.v1.cppm` is that
`A.v1.cppm` has an additional blank line. Then the test shows that two
BMI of `B.cppm`, one specified `-fmodule-file=A=A.pcm` and the other
specified `-fmodule-file=A=A.v1.pcm`, should have the bit-wise same
contents.

However, it is a different story for C, since C instantiates templates
from A, and the instantiation records the source information from module
A, which is different from `A` and `A.v1`, so it is expected that the
BMI `C.pcm` and `C.v1.pcm` can and should differ.

# Internal perspective of status quo

To fully understand the patch, we need to understand how we encodes
source locations and how we serialize and deserialize them.

For source locations, we encoded them as:

```
|
|
| _ base offset of an imported module
|
|
|
|_ base offset of another imported module
|
|
|
|
| ___ 0
```

As the diagram shows, we encode the local (unloaded) source location
from 0 to higher bits. And we allocate the space for source locations
from the loaded modules from high bits to 0. Then the source locations
from the loaded modules will be mapped to our source location space
according to the allocated offset.

For example, for,

```
// a.cppm
export module a;
...

// b.cppm
export module b;
import a;
...
```

Assuming the offset of a source location (let's name the location as
`S`) in a.cppm is 45 and we will record the value `45` into the BMI
`a.pcm`. Then in b.cppm, when we import a, the source manager will
allocate a space for module 'a' (according to the recorded number of
source locations) as the base offset of module 'a' in the current source
location spaces. Let's assume the allocated base offset as 90 in this
example. Then when we want to get the location in the current source
location space for `S`, we can get it simply by adding `45` to `90` to
`135`. Finally we can get the source location for `S` in module B as
`135`.

And when we want to write module `b`, we would also write the source
location of `S` as `135` directly in the BMI. And to clarify the
location `S` comes from module `a`, we also need to record the base
offset of module `a`, 90 in the BMI of `b`.

Then the problem comes. Since the base offset of module 'a' is computed
by the number source locations in module 'a'. In module 'b', the
recorded base offset of module 'a' will change every time the number of
source locations in module 'a' increase or decrease. In other words, the
contents of BMI of B will change every time the number of locations in
module 'a' changes. This is pretty sensitive. Almost every change will
change the number of locations. So this is the problem this patch want
to solve.

Let's continue with the existing design to understand what's going on.
Another interesting case is:

```
// c.cppm
export module c;
import whatever;
import a;
import b;
...
```

In `c.cppm`, when we import `a`, we still need to allocate a base
location offset for it, let's say the value becomes to `200` somehow.
Then when we reach the location `S` recorded in module `b`, we need to
translate it into the current source location space. The solution is
quite simple, we can get it by `135 + (200 - 90) = 245`. In another
word, the offset of a source location in current module can be computed
as `Recorded Offset + Base Offset of the its module file - Recorded Base
Offset`.

Then we're almost done about how we handle the offset of source
locatio

[clang] 74e65ee - [clang][Interp] Handle Shifts in OpenCL correctly

2024-04-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-30T10:02:50+02:00
New Revision: 74e65eec48ee87c34e06a09ad25a1029506dd60d

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

LOG: [clang][Interp] Handle Shifts in OpenCL correctly

We need to adjust the RHS to account for the LHS bitwidth.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/opencl.cl

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 9da0286deada17..2b650d684be9c4 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1935,10 +1935,15 @@ template 
 inline bool Shr(InterpState &S, CodePtr OpPC) {
   using LT = typename PrimConv::T;
   using RT = typename PrimConv::T;
-  const auto &RHS = S.Stk.pop();
+  auto RHS = S.Stk.pop();
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
+  // OpenCL 6.3j: shift values are effectively % word size of LHS.
+  if (S.getLangOpts().OpenCL)
+RT::bitAnd(RHS, RT::from(LHS.bitWidth() - 1, RHS.bitWidth()),
+   RHS.bitWidth(), &RHS);
+
   if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
@@ -1960,10 +1965,15 @@ template 
 inline bool Shl(InterpState &S, CodePtr OpPC) {
   using LT = typename PrimConv::T;
   using RT = typename PrimConv::T;
-  const auto &RHS = S.Stk.pop();
+  auto RHS = S.Stk.pop();
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
+  // OpenCL 6.3j: shift values are effectively % word size of LHS.
+  if (S.getLangOpts().OpenCL)
+RT::bitAnd(RHS, RT::from(LHS.bitWidth() - 1, RHS.bitWidth()),
+   RHS.bitWidth(), &RHS);
+
   if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 

diff  --git a/clang/test/AST/Interp/opencl.cl b/clang/test/AST/Interp/opencl.cl
index b9ba4f8b9b555a..e7b9ec5caf2b1e 100644
--- a/clang/test/AST/Interp/opencl.cl
+++ b/clang/test/AST/Interp/opencl.cl
@@ -30,3 +30,6 @@ void foo(int3 arg1, int8 arg2) {
   int res12[vec_step(void) == 1 ? 1 : -1];
 }
 
+void negativeShift32(int a,int b) {
+  char array0[((int)1)<<40];
+}



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


[clang] [Clang][Sema] fix a bug on template partial specialization (PR #89862)

2024-04-30 Thread Qizhi Hu via cfe-commits

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

>From 242b88a37f08bb66bcdde5e5b30c43553107d29c Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 24 Apr 2024 09:37:53 +0800
Subject: [PATCH] [Clang][Sema] fix a bug on template partial specialization

---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaTemplate.cpp |  2 +-
 ...dentical-type-primary-partial-specialization.cpp | 13 +
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..98c80b6017f604 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -611,6 +611,7 @@ Bug Fixes to C++ Support
   immediate function context.
 - Fix CTAD for ``std::initializer_list``. This allows 
``std::initializer_list{1, 2, 3}`` to be deduced as
   ``std::initializer_list`` as intended.
+- Fix a bug on template partial specialization whose template parameter is 
`decltype(auto)`.
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bbcb7c33a98579..ed5507c0ec0100 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7706,7 +7706,7 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 // FIXME: The language rules don't say what happens in this case.
 // FIXME: We get an opaque dependent type out of decltype(auto) if the
 // expression is merely instantiation-dependent; is this enough?
-if (CTAK == CTAK_Deduced && Arg->isTypeDependent()) {
+if (Arg->isTypeDependent()) {
   auto *AT = dyn_cast(DeducedT);
   if (AT && AT->isDecltypeAuto()) {
 SugaredConverted = TemplateArgument(Arg);
diff --git 
a/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp 
b/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp
new file mode 100644
index 00..ad51ca8252ef50
--- /dev/null
+++ b/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+template 
+struct S { // expected-note {{previous definition is here}}
+static constexpr int i = 42;
+};
+
+template 
+struct S { // expected-error {{class template partial specialization does 
not specialize any template argument; to define the primary template, remove 
the template argument list}} \
+  // expected-error {{redefinition of 'S'}}
+static constexpr int i = 0;
+};

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


[clang] eaee8aa - [Clang][Sema] fix a bug on template partial specialization (#89862)

2024-04-30 Thread via cfe-commits

Author: Qizhi Hu
Date: 2024-04-30T16:09:09+08:00
New Revision: eaee8aa0afe111f9291d54ecef97a3640a0f6ce0

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

LOG: [Clang][Sema] fix a bug on template partial specialization (#89862)

attempt to fix
https://github.com/llvm/llvm-project/issues/68885#issuecomment-1764201896
Deduction of NTTP whose type is `decltype(auto)` would create an
implicit cast expression to dependent type and makes the type of primary
template definition (`InjectedClassNameSpecialization`) and its partial
specialization different. Prevent emitting cast expression to make clang
knows their types are identical by removing `CTAK == CTAK_Deduced` when
the type is `decltype(auto)`.

Co-authored-by: huqizhi <836744...@qq.com>

Added: 
clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..98c80b6017f604 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -611,6 +611,7 @@ Bug Fixes to C++ Support
   immediate function context.
 - Fix CTAD for ``std::initializer_list``. This allows 
``std::initializer_list{1, 2, 3}`` to be deduced as
   ``std::initializer_list`` as intended.
+- Fix a bug on template partial specialization whose template parameter is 
`decltype(auto)`.
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bbcb7c33a98579..ed5507c0ec0100 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7706,7 +7706,7 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 // FIXME: The language rules don't say what happens in this case.
 // FIXME: We get an opaque dependent type out of decltype(auto) if the
 // expression is merely instantiation-dependent; is this enough?
-if (CTAK == CTAK_Deduced && Arg->isTypeDependent()) {
+if (Arg->isTypeDependent()) {
   auto *AT = dyn_cast(DeducedT);
   if (AT && AT->isDecltypeAuto()) {
 SugaredConverted = TemplateArgument(Arg);

diff  --git 
a/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp 
b/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp
new file mode 100644
index 00..ad51ca8252ef50
--- /dev/null
+++ b/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+template 
+struct S { // expected-note {{previous definition is here}}
+static constexpr int i = 42;
+};
+
+template 
+struct S { // expected-error {{class template partial specialization does 
not specialize any template argument; to define the primary template, remove 
the template argument list}} \
+  // expected-error {{redefinition of 'S'}}
+static constexpr int i = 0;
+};



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


[clang] [Clang][Sema] fix a bug on template partial specialization (PR #89862)

2024-04-30 Thread Qizhi Hu via cfe-commits

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


[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype template parameter (PR #90376)

2024-04-30 Thread Qizhi Hu via cfe-commits

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

>From c5c67ed879fc58e5371de6fc8296b7b6f653a072 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 28 Apr 2024 14:24:30 +0800
Subject: [PATCH] [Clang][Sema] Fix a bug on template partial specialization
 with issue on deduction of nontype tempalte parameter

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/include/clang/Sema/Sema.h  | 10 ++
 clang/lib/Sema/SemaTemplate.cpp  | 19 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++
 clang/test/SemaCXX/PR68885.cpp   | 21 +
 5 files changed, 50 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR68885.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 98c80b6017f604..1abc00a25f1f42 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -612,6 +612,8 @@ Bug Fixes to C++ Support
 - Fix CTAD for ``std::initializer_list``. This allows 
``std::initializer_list{1, 2, 3}`` to be deduced as
   ``std::initializer_list`` as intended.
 - Fix a bug on template partial specialization whose template parameter is 
`decltype(auto)`.
+- Fix a bug on template partial specialization with issue on deduction of 
nontype template parameter
+  whose type is `decltype(auto)`. Fixes (#GH68885).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1ca523ec88c2f9..809b9c4498f697 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9249,7 +9249,8 @@ class Sema final : public SemaBase {
   void NoteTemplateParameterLocation(const NamedDecl &Decl);
 
   ExprResult BuildExpressionFromDeclTemplateArgument(
-  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc);
+  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+  NamedDecl *TemplateParam = nullptr);
   ExprResult
   BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
  SourceLocation Loc);
@@ -9572,9 +9573,10 @@ class Sema final : public SemaBase {
 
   bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
 
-  TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument 
&Arg,
-QualType NTTPType,
-SourceLocation Loc);
+  TemplateArgumentLoc
+  getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType,
+SourceLocation Loc,
+NamedDecl *TemplateParam = nullptr);
 
   /// Get a template argument mapping the given template parameter to itself,
   /// e.g. for X in \c template, this would return an expression 
template
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ed5507c0ec0100..3c2a5a4ac47e69 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8438,10 +8438,9 @@ void Sema::NoteTemplateParameterLocation(const NamedDecl 
&Decl) {
 /// declaration and the type of its corresponding non-type template
 /// parameter, produce an expression that properly refers to that
 /// declaration.
-ExprResult
-Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
-  QualType ParamType,
-  SourceLocation Loc) {
+ExprResult Sema::BuildExpressionFromDeclTemplateArgument(
+const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+NamedDecl *TemplateParam) {
   // C++ [temp.param]p8:
   //
   //   A non-type template-parameter of type "array of T" or
@@ -8508,6 +8507,18 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument &Arg,
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
+if (NonTypeTemplateParmDecl *NTTP =
+dyn_cast_if_present(TemplateParam)) {
+  QualType TemplateParamType = NTTP->getType();
+  const AutoType *AT = TemplateParamType->getAs();
+  if (AT && AT->isDecltypeAuto()) {
+RefExpr = new (getASTContext()) SubstNonTypeTemplateParmExpr(
+ParamType->getPointeeType(), RefExpr.get()->getValueKind(),
+RefExpr.get()->getExprLoc(), RefExpr.get(), VD, NTTP->getIndex(),
+/*PackIndex=*/std::nullopt,
+/*RefParam=*/true);
+  }
+}
   }
 
   // At this point we should have the right value category.
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index c3815bca038554..e93f7bd842e444 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2639,7 +2639,8 @@ static bool isSameTemplateArg(ASTContext &Context,
 /// argumen

[clang] a413c56 - [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype template parameter (#90376)

2024-04-30 Thread via cfe-commits

Author: Qizhi Hu
Date: 2024-04-30T16:15:06+08:00
New Revision: a413c563bdcaac08f7c325c7d69e19f924435e59

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

LOG: [Clang][Sema] Fix a bug on template partial specialization with issue on 
deduction of nontype template parameter (#90376)

Fix https://github.com/llvm/llvm-project/issues/68885
When build expression from a deduced argument whose kind is
`Declaration` and `NTTPType`(which declared as `decltype(auto)`) is
deduced as a reference type, `BuildExpressionFromDeclTemplateArgument`
just create a `DeclRef`. This is incorrect while we get type from the
expression since we can't get the original reference type from
`DeclRef`. Creating a `SubstNonTypeTemplateParmExpr` expression and make
the deduction correct. `Replacement` expression of
`SubstNonTypeTemplateParmExpr` just helps the deduction and may not be
same with the original expression.

Co-authored-by: huqizhi <836744...@qq.com>

Added: 
clang/test/SemaCXX/PR68885.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 98c80b6017f604..1abc00a25f1f42 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -612,6 +612,8 @@ Bug Fixes to C++ Support
 - Fix CTAD for ``std::initializer_list``. This allows 
``std::initializer_list{1, 2, 3}`` to be deduced as
   ``std::initializer_list`` as intended.
 - Fix a bug on template partial specialization whose template parameter is 
`decltype(auto)`.
+- Fix a bug on template partial specialization with issue on deduction of 
nontype template parameter
+  whose type is `decltype(auto)`. Fixes (#GH68885).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1ca523ec88c2f9..809b9c4498f697 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9249,7 +9249,8 @@ class Sema final : public SemaBase {
   void NoteTemplateParameterLocation(const NamedDecl &Decl);
 
   ExprResult BuildExpressionFromDeclTemplateArgument(
-  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc);
+  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+  NamedDecl *TemplateParam = nullptr);
   ExprResult
   BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
  SourceLocation Loc);
@@ -9572,9 +9573,10 @@ class Sema final : public SemaBase {
 
   bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
 
-  TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument 
&Arg,
-QualType NTTPType,
-SourceLocation Loc);
+  TemplateArgumentLoc
+  getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType,
+SourceLocation Loc,
+NamedDecl *TemplateParam = nullptr);
 
   /// Get a template argument mapping the given template parameter to itself,
   /// e.g. for X in \c template, this would return an expression 
template

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ed5507c0ec0100..3c2a5a4ac47e69 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8438,10 +8438,9 @@ void Sema::NoteTemplateParameterLocation(const NamedDecl 
&Decl) {
 /// declaration and the type of its corresponding non-type template
 /// parameter, produce an expression that properly refers to that
 /// declaration.
-ExprResult
-Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
-  QualType ParamType,
-  SourceLocation Loc) {
+ExprResult Sema::BuildExpressionFromDeclTemplateArgument(
+const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+NamedDecl *TemplateParam) {
   // C++ [temp.param]p8:
   //
   //   A non-type template-parameter of type "array of T" or
@@ -8508,6 +8507,18 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument &Arg,
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
+if (NonTypeTemplateParmDecl *NTTP =
+dyn_cast_if_present(TemplateParam)) {
+  QualType TemplateParamType = NTTP->getType();
+  const AutoType *AT = TemplateParamType->getAs();
+  if (AT && AT->isDecltypeAuto()) {
+RefExpr = new (getASTContext()) SubstNonTypeTemplate

[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype template parameter (PR #90376)

2024-04-30 Thread Qizhi Hu via cfe-commits

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


[clang] f78949a - [NFC][Clang] Add FIXME comment to the workaround for issue #89774

2024-04-30 Thread Orlando Cazalet-Hyams via cfe-commits

Author: Orlando Cazalet-Hyams
Date: 2024-04-30T09:16:14+01:00
New Revision: f78949a07e33017a798c410a102c95455685a9b1

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

LOG: [NFC][Clang] Add FIXME comment to the workaround for issue #89774

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 787db350487417..fac278f0e20a43 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1373,6 +1373,8 @@ llvm::DIType *CGDebugInfo::CreateType(const 
TemplateSpecializationType *Ty,
   SourceLocation Loc = AliasDecl->getLocation();
 
   if (CGM.getCodeGenOpts().DebugTemplateAlias &&
+  // FIXME: This is a workaround for the issue
+  //https://github.com/llvm/llvm-project/issues/89774
   // The TemplateSpecializationType doesn't contain any instantiation
   // information; dependent template arguments can't be resolved. For now,
   // fall back to DW_TAG_typedefs for template aliases that are



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


[clang] [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (PR #90467)

2024-04-30 Thread Chen Zheng via cfe-commits

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

LGTM. Thanks!

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


[clang] [Clang] Fall back to DW_TAG_typedef for instantiation dependent template aliases (PR #90032)

2024-04-30 Thread Orlando Cazalet-Hyams via cfe-commits

OCHyams wrote:

> Comment in the code should probably mention this as a FIXME and include a 
> reference to the issue?

Sure, added in f78949a07e33017a798c410a102c95455685a9b1

> Also, there's another bug here - the DW_TAG_typedef is in the CU scope, 
> instead of the struct scope. But if the struct is a non-template, the typedef 
> is in the struct scope as it should be, not the CU scope...

That does looks odd - I can reproduce it with normal (language-level) typedefs 
too (rather than with template aliases): https://godbolt.org/z/GsGKqhKzz. I can 
open a separate issue?

Now that I think about it, I recall @CarlosAlbertoEnciso running into something 
similar a while ago... I'm sure a bug was filed about something similar but I 
can't find it. Does this ring any bells @CarlosAlbertoEnciso?


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


[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

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

ChuanqiXu9 wrote:

The test failure looks no related. I'll commit this after formatted.

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


[clang] b2b463b - [C++20] [Modules] Add signature to the BMI recording export imported

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

Author: Chuanqi Xu
Date: 2024-04-30T16:33:34+08:00
New Revision: b2b463bd8f6b21f040b80c4493682cf74f8dced5

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

LOG: [C++20] [Modules] Add signature to the BMI recording export imported
modules

After https://github.com/llvm/llvm-project/pull/86912,
for the following example,

```
export module A;
export import B;
```

The generated BMI of `A` won't change if the source location in `A`
changes. Further, we plan avoid more such changes.

However, it is slightly problematic since `export import` should
propagate all the changes.

So this patch adds a signature to the BMI of C++20 modules so that we
can propagate the changes correctly.

Added: 
clang/test/Modules/force-transitive-changes.cppm

Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/no-transitive-source-location-change.cppm

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 428bf6a5a791b3..921678d278d6e2 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -525,6 +525,7 @@ class ASTWriter : public ASTDeserializationListener,
 
   /// Calculate hash of the pcm content.
   std::pair createSignature() const;
+  ASTFileSignature createSignatureForNamedModule() const;
 
   void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
   void WriteSourceManagerBlock(SourceManager &SourceMgr,

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 4d85f6eb10d232..c3fcd1a4df2368 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1174,26 +1174,47 @@ ASTWriter::createSignature() const {
   return std::make_pair(ASTBlockHash, Signature);
 }
 
+ASTFileSignature ASTWriter::createSignatureForNamedModule() const {
+  llvm::SHA1 Hasher;
+  Hasher.update(StringRef(Buffer.data(), Buffer.size()));
+
+  assert(WritingModule);
+  assert(WritingModule->isNamedModule());
+
+  // We need to combine all the export imported modules no matter
+  // we used it or not.
+  for (auto [ExportImported, _] : WritingModule->Exports)
+Hasher.update(ExportImported->Signature);
+
+  return ASTFileSignature::create(Hasher.result());
+}
+
+static void BackpatchSignatureAt(llvm::BitstreamWriter &Stream,
+ const ASTFileSignature &S, uint64_t BitNo) {
+  for (uint8_t Byte : S) {
+Stream.BackpatchByte(BitNo, Byte);
+BitNo += 8;
+  }
+}
+
 ASTFileSignature ASTWriter::backpatchSignature() {
+  if (isWritingStdCXXNamedModules()) {
+ASTFileSignature Signature = createSignatureForNamedModule();
+BackpatchSignatureAt(Stream, Signature, SignatureOffset);
+return Signature;
+  }
+
   if (!WritingModule ||
   !PP->getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent)
 return {};
 
   // For implicit modules, write the hash of the PCM as its signature.
-
-  auto BackpatchSignatureAt = [&](const ASTFileSignature &S, uint64_t BitNo) {
-for (uint8_t Byte : S) {
-  Stream.BackpatchByte(BitNo, Byte);
-  BitNo += 8;
-}
-  };
-
   ASTFileSignature ASTBlockHash;
   ASTFileSignature Signature;
   std::tie(ASTBlockHash, Signature) = createSignature();
 
-  BackpatchSignatureAt(ASTBlockHash, ASTBlockHashOffset);
-  BackpatchSignatureAt(Signature, SignatureOffset);
+  BackpatchSignatureAt(Stream, ASTBlockHash, ASTBlockHashOffset);
+  BackpatchSignatureAt(Stream, Signature, SignatureOffset);
 
   return Signature;
 }
@@ -1210,9 +1231,11 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor 
&PP,
   RecordData Record;
   Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5);
 
-  // For implicit modules, write the hash of the PCM as its signature.
-  if (WritingModule &&
-  PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) {
+  // For implicit modules and C++20 named modules, write the hash of the PCM as
+  // its signature.
+  if (isWritingStdCXXNamedModules() ||
+  (WritingModule &&
+   PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent)) {
 // At this point, we don't know the actual signature of the file or the AST
 // block - we're only able to compute those at the end of the serialization
 // process. Let's store dummy signatures for now, and replace them with the
@@ -1223,21 +1246,24 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor 
&PP,
 auto Dummy = ASTFileSignature::createDummy();
 SmallString<128> Blob{Dummy.begin(), Dummy.end()};
 
-auto Abbrev = std::make_shared();
-Abbrev->Add(BitCodeAbbrevOp(AST_BLOCK_HASH));
-Abbrev->Add(BitCodeAbbrevOp(BitCode

[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

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

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/90570

>From d73596affed67978c703c92789de045e9ebf0f6b Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 30 Apr 2024 13:28:52 +0800
Subject: [PATCH] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator
 to generate module file for C++20 modules instead of PCHGenerator

Previously we're re-using PCHGenerator to generate the module file for
C++20 modules. But this is slighty more or less odd. This patch tries
to use a new class 'CXX20ModulesGenerator' to generate the module file
for C++20 modules.
---
 clang/include/clang/Serialization/ASTWriter.h | 25 ---
 clang/lib/Frontend/FrontendActions.cpp| 11 +++-
 clang/lib/Serialization/GeneratePCH.cpp   | 25 +++
 clang/test/Modules/pr67893.cppm   |  2 +-
 clang/test/Modules/search-partitions.cpp  |  8 +++---
 5 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 6c45b7348b8552..6f64ece9c5a19b 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -885,6 +885,8 @@ class ASTWriter : public ASTDeserializationListener,
 /// AST and semantic-analysis consumer that generates a
 /// precompiled header from the parsed source code.
 class PCHGenerator : public SemaConsumer {
+  void anchor() override;
+
   Preprocessor &PP;
   std::string OutputFile;
   std::string isysroot;
@@ -928,17 +930,34 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
-class ReducedBMIGenerator : public PCHGenerator {
+class CXX20ModulesGenerator : public PCHGenerator {
+  void anchor() override;
+
 protected:
   virtual Module *getEmittingModule(ASTContext &Ctx) override;
 
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile, bool GeneratingReducedBMI);
+
 public:
-  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-  StringRef OutputFile);
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/false) {}
 
   void HandleTranslationUnit(ASTContext &Ctx) override;
 };
 
+class ReducedBMIGenerator : public CXX20ModulesGenerator {
+  void anchor() override;
+
+public:
+  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+  StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/true) {}
+};
+
 /// If we can elide the definition of \param D in reduced BMI.
 ///
 /// Generally, we can elide the definition of a declaration if it won't affect
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 480dfa8c975933..454653a31534cd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -272,13 +272,10 @@ bool GenerateModuleInterfaceAction::BeginSourceFileAction(
 std::unique_ptr
 GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) {
-  CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true;
-  CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true;
-
-  std::vector> Consumers =
-  CreateMultiplexConsumer(CI, InFile);
-  if (Consumers.empty())
-return nullptr;
+  std::vector> Consumers;
+  Consumers.push_back(std::make_unique(
+  CI.getPreprocessor(), CI.getModuleCache(),
+  CI.getFrontendOpts().OutputFile));
 
   if (CI.getFrontendOpts().GenReducedBMI &&
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {
diff --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index a2ddbe4624aae4..cc06106a47708e 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -88,31 +88,30 @@ ASTDeserializationListener 
*PCHGenerator::GetASTDeserializationListener() {
   return &Writer;
 }
 
-ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor &PP,
- InMemoryModuleCache &ModuleCache,
- StringRef OutputFile)
+void PCHGenerator::anchor() {}
+
+CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP,
+ InMemoryModuleCache &ModuleCache,
+ StringRef OutputFile,
+ bool GeneratingReducedBMI)
 : PCHGenerator(
   PP, ModuleCache, OutputFile, llvm::StringRef(),
   std::make_shared(),
   /*Extensions=*/ArrayRef>(),

[clang] fce0916 - [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (#90570)

2024-04-30 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-30T16:37:27+08:00
New Revision: fce0916969218fdb4b89ad0b3e18599204d4138d

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

LOG: [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… 
(#90570)

…te module file for C++20 modules instead of PCHGenerator

Previously we're re-using PCHGenerator to generate the module file for
C++20 modules. But this is slighty more or less odd. This patch tries to
use a new class 'CXX20ModulesGenerator' to generate the module file for
C++20 modules.

Added: 


Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Serialization/GeneratePCH.cpp
clang/test/Modules/pr67893.cppm
clang/test/Modules/search-partitions.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 921678d278d6e2..cfcd787530d0e9 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -890,6 +890,8 @@ class ASTWriter : public ASTDeserializationListener,
 /// AST and semantic-analysis consumer that generates a
 /// precompiled header from the parsed source code.
 class PCHGenerator : public SemaConsumer {
+  void anchor() override;
+
   Preprocessor &PP;
   std::string OutputFile;
   std::string isysroot;
@@ -933,17 +935,34 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
-class ReducedBMIGenerator : public PCHGenerator {
+class CXX20ModulesGenerator : public PCHGenerator {
+  void anchor() override;
+
 protected:
   virtual Module *getEmittingModule(ASTContext &Ctx) override;
 
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile, bool GeneratingReducedBMI);
+
 public:
-  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-  StringRef OutputFile);
+  CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/false) {}
 
   void HandleTranslationUnit(ASTContext &Ctx) override;
 };
 
+class ReducedBMIGenerator : public CXX20ModulesGenerator {
+  void anchor() override;
+
+public:
+  ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+  StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/true) {}
+};
+
 /// If we can elide the definition of \param D in reduced BMI.
 ///
 /// Generally, we can elide the definition of a declaration if it won't affect

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 480dfa8c975933..454653a31534cd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -272,13 +272,10 @@ bool GenerateModuleInterfaceAction::BeginSourceFileAction(
 std::unique_ptr
 GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) {
-  CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true;
-  CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true;
-
-  std::vector> Consumers =
-  CreateMultiplexConsumer(CI, InFile);
-  if (Consumers.empty())
-return nullptr;
+  std::vector> Consumers;
+  Consumers.push_back(std::make_unique(
+  CI.getPreprocessor(), CI.getModuleCache(),
+  CI.getFrontendOpts().OutputFile));
 
   if (CI.getFrontendOpts().GenReducedBMI &&
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {

diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index a2ddbe4624aae4..cc06106a47708e 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -88,31 +88,30 @@ ASTDeserializationListener 
*PCHGenerator::GetASTDeserializationListener() {
   return &Writer;
 }
 
-ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor &PP,
- InMemoryModuleCache &ModuleCache,
- StringRef OutputFile)
+void PCHGenerator::anchor() {}
+
+CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP,
+ InMemoryModuleCache &ModuleCache,
+ StringRef OutputFile,
+ bool GeneratingReducedBMI)
 : PCHGenerator(
   PP, ModuleCache, OutputFile, llvm::StringRef(),
   std::m

[clang] [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… (PR #90570)

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

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


[clang] [llvm] [Clang][RISCV] Handle RVV tuple types correctly as InputOperand/OutputOperand for inline asm (PR #89883)

2024-04-30 Thread Brandon Wu via cfe-commits

4vtomat wrote:

Ping.

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


[clang] 10aab63 - [NFC] [tests] Don't try to remove and create the same directory

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

Author: Chuanqi Xu
Date: 2024-04-30T17:08:40+08:00
New Revision: 10aab63c9cb49d3ddfbe2cf8992de433efeef6f1

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

LOG: [NFC] [tests] Don't try to remove and create the same directory

In the test of
clang/test/Modules/no-transitive-source-location-change.cppm, there were
reports about invalid directory names in windows. The reason may be that
we may remove and create the same directory. This patch tries to avoid
such patterns for that.

Added: 


Modified: 
clang/test/Modules/no-transitive-source-location-change.cppm

Removed: 




diff  --git a/clang/test/Modules/no-transitive-source-location-change.cppm 
b/clang/test/Modules/no-transitive-source-location-change.cppm
index 83cf6fb4f684d0..303142a1af890b 100644
--- a/clang/test/Modules/no-transitive-source-location-change.cppm
+++ b/clang/test/Modules/no-transitive-source-location-change.cppm
@@ -3,7 +3,6 @@
 //
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: cd %t
 //
 // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
 // RUN: %clang_cc1 -std=c++20 %t/A.v1.cppm -emit-module-interface -o 
%t/A.v1.pcm
@@ -25,10 +24,6 @@
 // RUN: -o %t/C.v1.pcm
 // RUN: not 
diff  %t/C.v1.pcm %t/C.pcm  &> /dev/null
 //
-// RUN: rm -rf %t
-// RUN: split-file %s %t
-// RUN: cd %t
-//
 // Test again with reduced BMI.
 // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o 
%t/A.pcm
 // RUN: %clang_cc1 -std=c++20 %t/A.v1.cppm -emit-reduced-module-interface -o 
%t/A.v1.pcm



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


[clang] [llvm] Add option to generate additional debug info for expression dereferencing pointer to pointers. (PR #81545)

2024-04-30 Thread William Junda Huang via cfe-commits

https://github.com/huangjd updated 
https://github.com/llvm/llvm-project/pull/81545

>From f2c82758e1cba7773e41d941d2812c829c339675 Mon Sep 17 00:00:00 2001
From: William Huang 
Date: Mon, 12 Feb 2024 02:27:13 -0500
Subject: [PATCH 01/12] Add option to generate additional info for expression
 containing pointer of pointers.

Such expression does correspond to a variable in the source code thus
does not have a debug location. However the user may want to collect
sampling counter for memory accesses to analyze usage frequency of class
members. By enabling -fdebug_info_for_pointer_type a psuedo variable and
its debug info is generated in place whenever there's an intermediate
expression with pointer access.
---
 clang/include/clang/Basic/DebugOptions.def |  4 ++
 clang/include/clang/Driver/Options.td  |  4 ++
 clang/lib/CodeGen/CGDebugInfo.cpp  | 16 +
 clang/lib/CodeGen/CGDebugInfo.h|  6 ++
 clang/lib/CodeGen/CGDecl.cpp   |  4 ++
 clang/lib/CodeGen/CGExpr.cpp   | 79 ++
 clang/lib/CodeGen/CodeGenFunction.h|  5 ++
 clang/lib/Driver/ToolChains/Clang.cpp  |  3 +
 8 files changed, 121 insertions(+)

diff --git a/clang/include/clang/Basic/DebugOptions.def 
b/clang/include/clang/Basic/DebugOptions.def
index 7cd3edf08a17ea..6dd09f46842077 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -129,6 +129,10 @@ DEBUGOPT(CodeViewCommandLine, 1, 0)
 /// Whether emit extra debug info for sample pgo profile collection.
 DEBUGOPT(DebugInfoForProfiling, 1, 0)
 
+/// Whether to generate pseudo variables and their debug info for intermediate
+/// pointer accesses.
+DEBUGOPT(DebugInfoForPointerType, 1, 0)
+
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 DEBUGOPT(DebugNameTable, 2, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748faca..96b22d3f7640dd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1675,6 +1675,10 @@ defm debug_info_for_profiling : 
BoolFOption<"debug-info-for-profiling",
   PosFlag,
   NegFlag>;
+def fdebug_info_for_pointer_type : Flag<["-"], "fdebug-info-for-pointer-type">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Generate pseudo variables and their debug info for intermediate 
pointer accesses">,
+  MarshallingInfoFlag>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0f3f684d61dc94..6ce40da22dc97d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5636,6 +5636,22 @@ void 
CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitPseudoVariable(llvm::AllocaInst *Alloca, QualType Ty,
+ SourceLocation Loc) {
+  llvm::DIFile *Unit = getOrCreateFile(Loc);
+  unsigned Line = getLineNumber(Loc);
+  unsigned Column = getColumnNumber(Loc);
+  llvm::DILocalVariable *D = DBuilder.createAutoVariable(
+  LexicalBlockStack.back(), Alloca->getName(), getOrCreateFile(Loc), Line,
+  getOrCreateType(Ty, Unit));
+  llvm::DILocation *DIL =
+  llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
+LexicalBlockStack.back(), CurInlinedAt);
+  SmallVector Expr;
+  DBuilder.insertDeclare(Alloca, D, DBuilder.createExpression(Expr), DIL,
+ Alloca->getParent());
+}
+
 void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
   const GlobalDecl GD) {
 
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 7b60e94555d060..a2c484f50b2bc5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -529,6 +529,12 @@ class CGDebugInfo {
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit debug information for a pseudo variable assigned to the value of an
+  /// intermediate expression, so that a performance counter can track the 
usage
+  /// of a specific expression of interest.
+  void EmitPseudoVariable(llvm::AllocaInst *Alloca, QualType Ty,
+  SourceLocation Loc);
+
   /// Emit information about global variable alias.
   void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index bbe14ef4c17244..5f7b2529179003 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -793,6 +793,10 @@ void CodeGenFun

[clang] [clang][NFC] Reformat suspicious condition (PR #89923)

2024-04-30 Thread Florian Hahn via cfe-commits


@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
  .Case("once", PPCallbacks::PWS_Once)
  .Case("suppress", PPCallbacks::PWS_Suppress)
  .Default(-1);
-  if ((SpecifierValid = SpecifierInt != -1))
+  if (SpecifierValid = (SpecifierInt != -1))

fhahn wrote:

Unfortunately this introduces a new warning

```
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: 
warning: using the result of an assignment as a condition without parentheses 
[-Wparentheses]
 1447 |   if (SpecifierValid = (SpecifierInt != -1))
  |   ~~~^~
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: 
note: place parentheses around the assignment to silence this warning
 1447 |   if (SpecifierValid = (SpecifierInt != -1))
  |  ^
  |   ()
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: 
note: use '==' to turn this assignment into an equality comparison
 1447 |   if (SpecifierValid = (SpecifierInt != -1))
  |  ^
  |  ==
1 warning generated.
```

We likely need to outer parenthesis as well

```
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index ced407355e00..2972ee2197e2 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
  .Case("once", PPCallbacks::PWS_Once)
  .Case("suppress", PPCallbacks::PWS_Suppress)
  .Default(-1);
-  if (SpecifierValid = (SpecifierInt != -1))
+  if ((SpecifierValid = (SpecifierInt != -1)))
 Specifier =
 static_cast(SpecifierInt);
```

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


[clang] [Sema] Avoid an undesired pack expansion while transforming PackIndexingType (PR #90195)

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

zyn0217 wrote:

@cor3ntin Mind looking at it again? Thanks so much!

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-04-30 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/90574

This PR implement [P3034R1 Module Declarations Shouldn’t be 
Macros](https://wg21.link/P3034R1)


>From 1dcb4c3ac1efaf3a6a4317751e23089a6c8ccac1 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Tue, 30 Apr 2024 17:18:26 +0800
Subject: [PATCH] =?UTF-8?q?[Clang]=20Implement=20P3034R1=20Module=20Declar?=
 =?UTF-8?q?ations=20Shouldn=E2=80=99t=20be=20Macros?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticParseKinds.td   |  2 ++
 clang/lib/Parse/Parser.cpp|  7 
 clang/test/CXX/cpp/cpp.module/p1.cppm | 13 +++
 clang/test/CXX/cpp/cpp.module/version.h   |  8 +
 .../basic/basic.link/module-declaration.cpp   | 35 +++
 .../dcl.module/dcl.module.import/p1.cppm  |  4 +--
 clang/test/SemaCXX/modules.cppm   |  4 +++
 clang/www/cxx_status.html |  2 +-
 9 files changed, 59 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CXX/cpp/cpp.module/p1.cppm
 create mode 100644 clang/test/CXX/cpp/cpp.module/version.h

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1abc00a25f1f42..40c6bd63e9948f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -153,6 +153,8 @@ C++2c Feature Support
 
 - Implemented `P2748R5 Disallow Binding a Returned Glvalue to a Temporary 
`_.
 
+- Implemented `P3034R1 Module Declarations Shouldn’t be Macros 
`_.
+
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index fdffb35ea0d955..0d4b526ec6d15a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1671,6 +1671,8 @@ def err_unexpected_module_decl : Error<
   "module declaration can only appear at the top level">;
 def err_module_expected_ident : Error<
   "expected a module name after '%select{module|import}0'">;
+def err_module_decl_cannot_be_macros : Error<
+  "module declaration cannot be a macro">;
 def err_attribute_not_module_attr : Error<
   "%0 attribute cannot be applied to a module">;
 def err_keyword_not_module_attr : Error<
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index adcbe5858bc78e..ef66348a83125c 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2690,6 +2690,13 @@ bool Parser::ParseModuleName(
   return true;
 }
 
+// P3034R1: Module Declarations Shouldn’t be Macros
+if (!IsImport && Tok.getLocation().isMacroID()) {
+  Diag(Tok, diag::err_module_decl_cannot_be_macros);
+  SkipUntil(tok::semi);
+  return true;
+}
+
 // Record this part of the module path.
 Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
 ConsumeToken();
diff --git a/clang/test/CXX/cpp/cpp.module/p1.cppm 
b/clang/test/CXX/cpp/cpp.module/p1.cppm
new file mode 100644
index 00..b439366db3fba0
--- /dev/null
+++ b/clang/test/CXX/cpp/cpp.module/p1.cppm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -triple 
x86_64-linux-gnu -DTEST=1 -verify
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -triple 
x86_64-linux-gnu -DTEST=2 -verify
+
+module;
+export module x;
+#include "version.h"
+#if TEST == 1
+export module VERSION;  // expected-error {{module declaration cannot be a 
macro}}
+#endif // TEST == 1
+
+#if TEST == 2
+export module A.B;  // expected-error {{module declaration cannot be a 
macro}}
+#endif // TEST == 2
diff --git a/clang/test/CXX/cpp/cpp.module/version.h 
b/clang/test/CXX/cpp/cpp.module/version.h
new file mode 100644
index 00..4608934290950b
--- /dev/null
+++ b/clang/test/CXX/cpp/cpp.module/version.h
@@ -0,0 +1,8 @@
+#ifndef VERSION_H
+#define VERSION_H
+
+#define VERSION libv5
+#define A a
+#define B b
+
+#endif
diff --git a/clang/test/CXX/module/basic/basic.link/module-declaration.cpp 
b/clang/test/CXX/module/basic/basic.link/module-declaration.cpp
index d71358cc7a571f..aa4bb52a57face 100644
--- a/clang/test/CXX/module/basic/basic.link/module-declaration.cpp
+++ b/clang/test/CXX/module/basic/basic.link/module-declaration.cpp
@@ -9,26 +9,26 @@
 //
 // Module implementation for unknown and known module. (The former is 
ill-formed.)
 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify -x c++ 
%t/M.cpp \
-// RUN:-DTEST=1 -DEXPORT= -DMODULE_NAME=z
+// RUN:-DTEST=1
 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x=%t/x.pcm 
-fmodule-file=x.y=%t/x.y.pcm -verify -x c++ %t/M.cpp \
-// RUN:-DTEST=2 -DEXPOR

[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

This PR implement [P3034R1 Module Declarations Shouldn’t be 
Macros](https://wg21.link/P3034R1)


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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/lib/Parse/Parser.cpp (+7) 
- (added) clang/test/CXX/cpp/cpp.module/p1.cppm (+13) 
- (added) clang/test/CXX/cpp/cpp.module/version.h (+8) 
- (modified) clang/test/CXX/module/basic/basic.link/module-declaration.cpp 
(+20-15) 
- (modified) clang/test/CXX/module/dcl.dcl/dcl.module/dcl.module.import/p1.cppm 
(+2-2) 
- (modified) clang/test/SemaCXX/modules.cppm (+4) 
- (modified) clang/www/cxx_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1abc00a25f1f42..40c6bd63e9948f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -153,6 +153,8 @@ C++2c Feature Support
 
 - Implemented `P2748R5 Disallow Binding a Returned Glvalue to a Temporary 
`_.
 
+- Implemented `P3034R1 Module Declarations Shouldn’t be Macros 
`_.
+
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index fdffb35ea0d955..0d4b526ec6d15a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1671,6 +1671,8 @@ def err_unexpected_module_decl : Error<
   "module declaration can only appear at the top level">;
 def err_module_expected_ident : Error<
   "expected a module name after '%select{module|import}0'">;
+def err_module_decl_cannot_be_macros : Error<
+  "module declaration cannot be a macro">;
 def err_attribute_not_module_attr : Error<
   "%0 attribute cannot be applied to a module">;
 def err_keyword_not_module_attr : Error<
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index adcbe5858bc78e..ef66348a83125c 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2690,6 +2690,13 @@ bool Parser::ParseModuleName(
   return true;
 }
 
+// P3034R1: Module Declarations Shouldn’t be Macros
+if (!IsImport && Tok.getLocation().isMacroID()) {
+  Diag(Tok, diag::err_module_decl_cannot_be_macros);
+  SkipUntil(tok::semi);
+  return true;
+}
+
 // Record this part of the module path.
 Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
 ConsumeToken();
diff --git a/clang/test/CXX/cpp/cpp.module/p1.cppm 
b/clang/test/CXX/cpp/cpp.module/p1.cppm
new file mode 100644
index 00..b439366db3fba0
--- /dev/null
+++ b/clang/test/CXX/cpp/cpp.module/p1.cppm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -triple 
x86_64-linux-gnu -DTEST=1 -verify
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -triple 
x86_64-linux-gnu -DTEST=2 -verify
+
+module;
+export module x;
+#include "version.h"
+#if TEST == 1
+export module VERSION;  // expected-error {{module declaration cannot be a 
macro}}
+#endif // TEST == 1
+
+#if TEST == 2
+export module A.B;  // expected-error {{module declaration cannot be a 
macro}}
+#endif // TEST == 2
diff --git a/clang/test/CXX/cpp/cpp.module/version.h 
b/clang/test/CXX/cpp/cpp.module/version.h
new file mode 100644
index 00..4608934290950b
--- /dev/null
+++ b/clang/test/CXX/cpp/cpp.module/version.h
@@ -0,0 +1,8 @@
+#ifndef VERSION_H
+#define VERSION_H
+
+#define VERSION libv5
+#define A a
+#define B b
+
+#endif
diff --git a/clang/test/CXX/module/basic/basic.link/module-declaration.cpp 
b/clang/test/CXX/module/basic/basic.link/module-declaration.cpp
index d71358cc7a571f..aa4bb52a57face 100644
--- a/clang/test/CXX/module/basic/basic.link/module-declaration.cpp
+++ b/clang/test/CXX/module/basic/basic.link/module-declaration.cpp
@@ -9,26 +9,26 @@
 //
 // Module implementation for unknown and known module. (The former is 
ill-formed.)
 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify -x c++ 
%t/M.cpp \
-// RUN:-DTEST=1 -DEXPORT= -DMODULE_NAME=z
+// RUN:-DTEST=1
 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x=%t/x.pcm 
-fmodule-file=x.y=%t/x.y.pcm -verify -x c++ %t/M.cpp \
-// RUN:-DTEST=2 -DEXPORT= -DMODULE_NAME=x
+// RUN:-DTEST=2
 //
 // Module interface for unknown and known module. (The latter is ill-formed 
due to
 // redefinition.)
 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify 
%t/M.cpp \
-// RUN:-DTEST=3 -DEXPORT=export -DMODULE_NAME=z
+// RUN:-DTEST=3
 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify 
%t/M.cpp \
-// RUN:

[clang] [Clang] Implement P2809: Trivial infinite loops are not Undefined Behavior (PR #90066)

2024-04-30 Thread via cfe-commits

yronglin wrote:

> @yronglin I'm reluctant to do that, that would be testing the optimizer in 
> the front end. If the patch did not fix this bug, there would be a back end 
> bug that should be fixed there

Agree!

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-30 Thread via cfe-commits


@@ -0,0 +1,5 @@
+Script started on 2024-04-27 13:50:15+05:30 [TERM="xterm-256color" 
TTY="/dev/pts/0" COLUMNS="100" LINES="18"]

komalverma04 wrote:

Thank you for pointing out, i will do as you said.

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-30 Thread via cfe-commits


@@ -22,7 +22,7 @@ namespace clang::tidy::abseil {
 //  - Make it work in macros if the outer and inner StrCats are both in the
 //argument.
 
-void RedundantStrcatCallsCheck::registerMatchers(MatchFinder* Finder) {
+void RedundantStrcatCallsCheck::registerMatchers(MatchFinder *Finder) {

komalverma04 wrote:

Okay !!

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-30 Thread via cfe-commits


@@ -0,0 +1,72 @@
+set(CMAKE_C_COMPILER "/usr/bin/cc")

komalverma04 wrote:

Yes, removing it.

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


[clang] [NFC][Clang] Update P2718R0 implementation status to partial supported (PR #90577)

2024-04-30 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/90577

Once https://github.com/llvm/llvm-project/issues/85613 fixed, we can mark this 
feature fully supported.

>From 9b7c8b61bec89310df916255e59924cefdbb01b1 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Tue, 30 Apr 2024 17:28:33 +0800
Subject: [PATCH] [NFC][Clang] Update P2718R0 implementation status to partial
 supported

Signed-off-by: yronglin 
---
 clang/www/cxx_status.html | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 0996abc2405857..6db6ae57d12603 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -167,7 +167,7 @@ C++2c implementation status
  
   Disallow Binding a Returned Glvalue to a Temporary
   https://wg21.link/P2748R5";>P2748R5
-  Clang 19
+  Clang 19
  
  
   Clarifying rules for brace elision in aggregate initialization
@@ -462,7 +462,14 @@ C++23 implementation status
 
   Lifetime extension in range-based for loops
   https://wg21.link/P2718R0";>P2718R0
-  Clang 19
+  
+
+  Clang 19 (Partial)
+The lifetime extension of temporaries bound to member references
+by default member initializers in aggregate initialization was 
+not supported now.
+
+  
 
 
 

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


[clang] [NFC][Clang] Update P2718R0 implementation status to partial supported (PR #90577)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

Once https://github.com/llvm/llvm-project/issues/85613 fixed, we can mark this 
feature fully supported.

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


1 Files Affected:

- (modified) clang/www/cxx_status.html (+9-2) 


``diff
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 0996abc2405857..6db6ae57d12603 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -167,7 +167,7 @@ C++2c implementation status
  
   Disallow Binding a Returned Glvalue to a Temporary
   https://wg21.link/P2748R5";>P2748R5
-  Clang 19
+  Clang 19
  
  
   Clarifying rules for brace elision in aggregate initialization
@@ -462,7 +462,14 @@ C++23 implementation status
 
   Lifetime extension in range-based for loops
   https://wg21.link/P2718R0";>P2718R0
-  Clang 19
+  
+
+  Clang 19 (Partial)
+The lifetime extension of temporaries bound to member references
+by default member initializers in aggregate initialization was 
+not supported now.
+
+  
 
 
 

``




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


[clang] f73e87f - [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (#90467)

2024-04-30 Thread via cfe-commits

Author: Ulrich Weigand
Date: 2024-04-30T11:34:34+02:00
New Revision: f73e87f53f5d8a86c29251dedc9dbd264179203a

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

LOG: [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (#90467)

The AltiVec (POWER) and ZVector (IBM Z) language extensions do not
support using the "vector" keyword when the element type is a complex
type, but current code does not verify this.

Add a Sema check and diagnostic for this case.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/DeclSpec.cpp
clang/test/Parser/altivec.c
clang/test/Parser/cxx-altivec.cpp
clang/test/Sema/zvector.c
clang/test/Sema/zvector2.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f72d5c252b863e..5cb3c808957b30 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -307,6 +307,8 @@ def err_invalid_vector_long_long_decl_spec : Error <
   "POWER7 or later) to be enabled">;
 def err_invalid_vector_long_double_decl_spec : Error<
   "cannot use 'long double' with '__vector'">;
+def err_invalid_vector_complex_decl_spec : Error<
+  "cannot use '_Complex' with '__vector'">;
 def warn_vector_long_decl_spec_combination : Warning<
   "Use of 'long' with '__vector' is deprecated">, InGroup;
 

diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 5f63c857c43067..60e81890257002 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1202,7 +1202,10 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy 
&Policy) {
 !S.Context.getTargetInfo().hasFeature("power8-vector"))
   S.Diag(TSTLoc, diag::err_invalid_vector_int128_decl_spec);
 
-if (TypeAltiVecBool) {
+// Complex vector types are not supported.
+if (TypeSpecComplex != TSC_unspecified)
+  S.Diag(TSCLoc, diag::err_invalid_vector_complex_decl_spec);
+else if (TypeAltiVecBool) {
   // Sign specifiers are not allowed with vector bool. (PIM 2.1)
   if (getTypeSpecSign() != TypeSpecifierSign::Unspecified) {
 S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec)

diff  --git a/clang/test/Parser/altivec.c b/clang/test/Parser/altivec.c
index daee5eae4d8430..445369f0dc0660 100644
--- a/clang/test/Parser/altivec.c
+++ b/clang/test/Parser/altivec.c
@@ -110,6 +110,12 @@ vector __bool long long v_bll4;  // expected-error 
{{use of 'long long' with
 #endif
 __vector long double  vv_ld3;// expected-error {{cannot use 'long 
double' with '__vector'}}
 vector long double  v_ld4;   // expected-error {{cannot use 'long 
double' with '__vector'}}
+vector float _Complex v_cf;  // expected-error {{cannot use '_Complex' 
with '__vector'}}
+vector double _Complex v_cd; // expected-error {{cannot use '_Complex' 
with '__vector'}}
+vector long double _Complex v_cld;   // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector float _Complex v_cf2;   // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector double _Complex v_cd2;  // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector long double _Complex v_cld2;// expected-error {{cannot use '_Complex' 
with '__vector'}}
 vector bool float v_bf;  // expected-error {{cannot use 'float' 
with '__vector bool'}}
 vector bool double v_bd; // expected-error {{cannot use 'double' 
with '__vector bool'}}
 vector bool pixel v_bp;  // expected-error {{cannot use '__pixel' 
with '__vector bool'}}

diff  --git a/clang/test/Parser/cxx-altivec.cpp 
b/clang/test/Parser/cxx-altivec.cpp
index 6da36663422b49..5cb760dababbb6 100644
--- a/clang/test/Parser/cxx-altivec.cpp
+++ b/clang/test/Parser/cxx-altivec.cpp
@@ -111,6 +111,12 @@ vector __bool long long v_bll4;  // expected-error 
{{use of 'long long' with
 #endif
 __vector long double  vv_ld3;// expected-error {{cannot use 'long 
double' with '__vector'}}
 vector long double  v_ld4;   // expected-error {{cannot use 'long 
double' with '__vector'}}
+vector float _Complex v_cf;  // expected-error {{cannot use '_Complex' 
with '__vector'}}
+vector double _Complex v_cd; // expected-error {{cannot use '_Complex' 
with '__vector'}}
+vector long double _Complex v_cld;   // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector float _Complex v_cf2;   // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector double _Complex v_cd2;  // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector long double _Complex v_cld2;// expe

[clang] [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (PR #90467)

2024-04-30 Thread Ulrich Weigand via cfe-commits

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-30 Thread via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

zmodem wrote:

> Sorry for insisting on this

Not at all, I want us to resolve this, not paper over it. :)

>  it's maybe because I got "bitten" before (with the suspend)

But in that case the problem was kind of the opposite, right? Instructions 
between the `resume` and `suspend` blocked the musttail optimization. The 
problem was not whether those instructions would have been executed or not, but 
that they were inserted in a place where it wasn't allowed due to special 
constraints on this intrinsic.

The idea with my patch is to eliminate that problem by not having special 
restrictions about instructions after the intrinsic, they just won't be 
executed because control continues in the resumed function and doesn't come 
back.

> what other examples do we have where, silently, instructions don't get 
> executed after a call?

This happens any time a call doesn't return.

> Also, maybe this would become moot if we address 
> https://discourse.llvm.org/t/coro-pre-split-handling-of-the-suspend-edge/75043
>  like @jyknight suggested (i.e. not even have the misleading edge)?

Yes that's probably true, but that's a bigger change and I think my patch is a 
simpler solution to this specific problem: now that we have an intrinsic that 
corresponds directly to the symmetric transfer, let's just lower it as such 
directly.

> If I read correctly, @zmodem said he'd like to mention this in the doc or 
> check it by assertions or verifiers. So it looks consensus to me?

No, I said that *if* we decide that instructions after 
`llvm.coro.await.suspend.handle` are not allowed, we should document and check 
it.

I still don't think we should do that, since it's a difficult invariant to 
maintain. We'd have to teach passes to respect it, keep updating a list of 
harmless instructions that are allowed (debug/lifetime intrinsics, ...) and 
we'd end up chasing down those assert/verifier failures forever.

With the current patch, we don't have to teach other passes anything. They 
already cannot assume that an unknown intrinsic call will return.

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


[clang] Fix output in coro-elide-thinlto.cpp (PR #90579)

2024-04-30 Thread Danial Klimkin via cfe-commits

https://github.com/dklimkin created 
https://github.com/llvm/llvm-project/pull/90579

Current dir can be read-only. Use a temp path instead.

>From 9140277a888ba6119730987bfb2cbbb4510b11c0 Mon Sep 17 00:00:00 2001
From: Danial Klimkin 
Date: Tue, 30 Apr 2024 11:35:47 +0200
Subject: [PATCH] Fix output in coro-elide-thinlto.cpp

Current dir can be read-only. Use a temp path instead.
---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 790899486ec9d1..5c5fed2f764622 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -4,8 +4,8 @@
 // RUN: split-file %s %t
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
-// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
-// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
%t/summary
+// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=%t/summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

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


[clang] fb2d305 - Fix output in coro-elide-thinlto.cpp (#90579)

2024-04-30 Thread via cfe-commits

Author: Danial Klimkin
Date: 2024-04-30T11:42:13+02:00
New Revision: fb2d3056618e3d03ba9a695627c7b002458e59f0

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

LOG: Fix output in coro-elide-thinlto.cpp (#90579)

Current dir can be read-only. Use a temp path instead.

Added: 


Modified: 
clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

Removed: 




diff  --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 790899486ec9d1..5c5fed2f764622 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -4,8 +4,8 @@
 // RUN: split-file %s %t
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
-// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
-// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
%t/summary
+// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=%t/summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once



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


[clang] Fix output in coro-elide-thinlto.cpp (PR #90579)

2024-04-30 Thread Danial Klimkin via cfe-commits

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


[clang] Fix output in coro-elide-thinlto.cpp (PR #90579)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-coroutines

Author: Danial Klimkin (dklimkin)


Changes

Current dir can be read-only. Use a temp path instead.

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


1 Files Affected:

- (modified) clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp (+2-2) 


``diff
diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 790899486ec9d1..5c5fed2f764622 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -4,8 +4,8 @@
 // RUN: split-file %s %t
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
-// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
-// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
%t/summary
+// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=%t/summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

``




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


[clang] [analysis] assume expr is not mutated after analysis to avoid recursive (PR #90581)

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

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/90581

Fixes: #89376.


>From f0d640d4c1ba2ede182fdf31cc7030aad01de8b8 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 30 Apr 2024 17:46:37 +0800
Subject: [PATCH] [analysis] assume expr is not mutated after analysis to avoid
 recursive

Fixes: #89376.
---
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   |  6 +++--
 .../Analysis/ExprMutationAnalyzerTest.cpp | 26 +--
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 941322be8f870b..3b3782fa1db9a0 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -235,15 +235,17 @@ const Stmt 
*ExprMutationAnalyzer::Analyzer::findMutationMemoized(
   if (Memoized != MemoizedResults.end())
 return Memoized->second;
 
+  // Assume Exp is not mutated before analyzing Exp.
+  MemoizedResults[Exp] = nullptr;
   if (isUnevaluated(Exp))
-return MemoizedResults[Exp] = nullptr;
+return nullptr;
 
   for (const auto &Finder : Finders) {
 if (const Stmt *S = (this->*Finder)(Exp))
   return MemoizedResults[Exp] = S;
   }
 
-  return MemoizedResults[Exp] = nullptr;
+  return nullptr;
 }
 
 const Stmt *
diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp 
b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index 9c1dc1a76db63d..79ccb024283c35 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -10,8 +10,8 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Frontend/ASTUnit.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/SmallString.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -43,7 +43,7 @@ std::unique_ptr buildASTFromCode(const Twine &Code) {
 }
 
 ExprMatcher declRefTo(StringRef Name) {
-  return declRefExpr(to(namedDecl(hasName(Name;
+  return declRefExpr(to(namedDecl(hasName(Name)).bind("decl")));
 }
 
 StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {
@@ -57,6 +57,13 @@ bool isMutated(const SmallVectorImpl &Results, 
ASTUnit *AST) {
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
+bool isDeclMutated(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  const auto *const D = selectFirst("decl", Results);
+  TraversalKindScope RAII(AST->getASTContext(), TK_AsIs);
+  return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(D);
+}
+
 SmallVector
 mutatedBy(const SmallVectorImpl &Results, ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
@@ -1552,6 +1559,21 @@ TEST(ExprMutationAnalyzerTest, UniquePtr) {
 
 // section: complex problems detected on real code
 
+TEST(ExprMutationAnalyzerTest, SelfRef) {
+  std::unique_ptr AST{};
+  SmallVector Results{};
+
+  AST = buildASTFromCodeWithArgs("void f() { int &x = x; }",
+ {"-Wno-unused-value", "-Wno-uninitialized"});
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isDeclMutated(Results, AST.get()));
+
+  AST = buildASTFromCodeWithArgs("void f() { int &x = x; x = 1; }",
+ {"-Wno-unused-value", "-Wno-uninitialized"});
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_TRUE(isDeclMutated(Results, AST.get()));
+}
+
 TEST(ExprMutationAnalyzerTest, UnevaluatedContext) {
   const std::string Example =
   "template "

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


[clang] [analysis] assume expr is not mutated after analysis to avoid recursive (PR #90581)

2024-04-30 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: Congcong Cai (HerrCai0907)


Changes

Fixes: #89376.


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


2 Files Affected:

- (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+4-2) 
- (modified) clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp (+24-2) 


``diff
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 941322be8f870b..3b3782fa1db9a0 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -235,15 +235,17 @@ const Stmt 
*ExprMutationAnalyzer::Analyzer::findMutationMemoized(
   if (Memoized != MemoizedResults.end())
 return Memoized->second;
 
+  // Assume Exp is not mutated before analyzing Exp.
+  MemoizedResults[Exp] = nullptr;
   if (isUnevaluated(Exp))
-return MemoizedResults[Exp] = nullptr;
+return nullptr;
 
   for (const auto &Finder : Finders) {
 if (const Stmt *S = (this->*Finder)(Exp))
   return MemoizedResults[Exp] = S;
   }
 
-  return MemoizedResults[Exp] = nullptr;
+  return nullptr;
 }
 
 const Stmt *
diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp 
b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index 9c1dc1a76db63d..79ccb024283c35 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -10,8 +10,8 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Frontend/ASTUnit.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/SmallString.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -43,7 +43,7 @@ std::unique_ptr buildASTFromCode(const Twine &Code) {
 }
 
 ExprMatcher declRefTo(StringRef Name) {
-  return declRefExpr(to(namedDecl(hasName(Name;
+  return declRefExpr(to(namedDecl(hasName(Name)).bind("decl")));
 }
 
 StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {
@@ -57,6 +57,13 @@ bool isMutated(const SmallVectorImpl &Results, 
ASTUnit *AST) {
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
+bool isDeclMutated(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  const auto *const D = selectFirst("decl", Results);
+  TraversalKindScope RAII(AST->getASTContext(), TK_AsIs);
+  return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(D);
+}
+
 SmallVector
 mutatedBy(const SmallVectorImpl &Results, ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
@@ -1552,6 +1559,21 @@ TEST(ExprMutationAnalyzerTest, UniquePtr) {
 
 // section: complex problems detected on real code
 
+TEST(ExprMutationAnalyzerTest, SelfRef) {
+  std::unique_ptr AST{};
+  SmallVector Results{};
+
+  AST = buildASTFromCodeWithArgs("void f() { int &x = x; }",
+ {"-Wno-unused-value", "-Wno-uninitialized"});
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isDeclMutated(Results, AST.get()));
+
+  AST = buildASTFromCodeWithArgs("void f() { int &x = x; x = 1; }",
+ {"-Wno-unused-value", "-Wno-uninitialized"});
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_TRUE(isDeclMutated(Results, AST.get()));
+}
+
 TEST(ExprMutationAnalyzerTest, UnevaluatedContext) {
   const std::string Example =
   "template "

``




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


[clang] [Clang] Fix LibTooling doc (PR #90441)

2024-04-30 Thread Maxim Moskalets via cfe-commits

https://github.com/maxmosk updated 
https://github.com/llvm/llvm-project/pull/90441

>From a09f0c836a4e8296ccae3c51889f90dea38c304c Mon Sep 17 00:00:00 2001
From: Maxim Moskalets 
Date: Tue, 30 Apr 2024 12:51:43 +0300
Subject: [PATCH] [Clang][Docs] Synchronize the LibTooling example

Synchronize the example in LibTooling documentation and header 
CommonOptionsParser.h
---
 clang/include/clang/Tooling/CommonOptionsParser.h | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Tooling/CommonOptionsParser.h 
b/clang/include/clang/Tooling/CommonOptionsParser.h
index 3c0480af377943..337e62cd7b7ed5 100644
--- a/clang/include/clang/Tooling/CommonOptionsParser.h
+++ b/clang/include/clang/Tooling/CommonOptionsParser.h
@@ -49,17 +49,20 @@ namespace tooling {
 /// using namespace clang::tooling;
 /// using namespace llvm;
 ///
-/// static cl::OptionCategory MyToolCategory("My tool options");
+/// static cl::OptionCategory MyToolCategory("my-tool options");
 /// static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 /// static cl::extrahelp MoreHelp("\nMore help text...\n");
-/// static cl::opt YourOwnOption(...);
-/// ...
 ///
 /// int main(int argc, const char **argv) {
-///   CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+///   auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+///   if (!ExpectedParser) {
+/// llvm::errs() << ExpectedParser.takeError();
+/// return 1;
+///   }
+///   CommonOptionsParser& OptionsParser = ExpectedParser.get();
 ///   ClangTool Tool(OptionsParser.getCompilations(),
 ///  OptionsParser.getSourcePathList());
-///   return Tool.run(newFrontendActionFactory().get());
+///   return 
Tool.run(newFrontendActionFactory().get());
 /// }
 /// \endcode
 class CommonOptionsParser {

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


[clang] [Clang] Fix LibTooling doc (PR #90441)

2024-04-30 Thread Maxim Moskalets via cfe-commits

maxmosk wrote:

@Sirraide updated with header doc fix, please review

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


[clang] [libcxx] [llvm] Triple::normalize: Use none as OS for XX-none-ABI (PR #89638)

2024-04-30 Thread Peter Waller via cfe-commits

peterwaller-arm wrote:

Thanks @wzssyqa again for implementing this and splitting bits out per Sander's 
suggestion. I propose we merge these changes tomorrow, on the understanding 
that each of the two patches (this and #90313) are passing tests. It looks to 
me like you're working towards that goal.

What I see in CI for this PR is `LLVM-Unit :: 
TargetParser/./TargetParserTests/TripleTest/Normalization` is currently failing.

Is it possible to have two patches such that they're both green? My expectation 
is that the majority of the triple changes in the source are unrelated to 
normalization and would work the same before and after the functional changes 
to triple normalization. (And that those tests which are impacted by changes to 
triple normalization should of course change in the same commit to keep things 
green).

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-30 Thread via cfe-commits




komalverma04 wrote:

Please ignore it, it is a format based change.

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-30 Thread via cfe-commits




komalverma04 wrote:

This file is deleted

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


[clang] [OpenMP][TR12] change property of map-type modifier. (PR #90499)

2024-04-30 Thread Alexey Bataev via cfe-commits


@@ -113,7 +114,7 @@ struct SA {
 #pragma omp target map(b[true:true])
 {}
 
-#pragma omp target map(: c,f) // expected-error {{missing map type}}
+#pragma omp target map(: c,f) // lt60-error {{missing map type}}

alexey-bataev wrote:

Check page 100, the supported format is `[modifier-specification-list 
:]clause-argument-list`

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


[clang] [llvm] [AArch64] Add support for Cortex-R82AE and improve Cortex-R82 (PR #90440)

2024-04-30 Thread David Green via cfe-commits


@@ -632,7 +632,18 @@ inline constexpr CpuInfo CpuInfos[] = {
AArch64::AEK_PAUTH, AArch64::AEK_SVE2BITPERM,
AArch64::AEK_FLAGM, AArch64::AEK_PERFMON,
AArch64::AEK_PREDRES, AArch64::AEK_PROFILE})},
-{"cortex-r82", ARMV8R, AArch64::ExtensionBitset({AArch64::AEK_LSE})},
+{"cortex-r82", ARMV8R,
+ AArch64::ExtensionBitset({AArch64::AEK_CRC, AArch64::AEK_DOTPROD,

davemgreen wrote:

Can you check if ARMV8R enables AEK_LSE? There is a flip(), which might be 
turning it off?

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


[clang-tools-extra] [clang-tidy] Relax readability-const-return-type (PR #90560)

2024-04-30 Thread Danny Mösch via cfe-commits

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


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


[clang] [llvm] [AArch64] Add support for Cortex-R82AE and improve Cortex-R82 (PR #90440)

2024-04-30 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray updated 
https://github.com/llvm/llvm-project/pull/90440

>From 16f06cb0d4b84a8084e963dc7d2036ead9446a87 Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Sat, 27 Apr 2024 22:51:19 +0100
Subject: [PATCH 1/4] [AArch64] Add support for Cortex-R82AE and improve
 Cortex-R82

Cortex-R82AE is an Armv8R AArch64 CPU. Also, update Cortex-R82
feature flags to be more accurate.

Technical Reference Manual for Cortex-R82AE:
   https://developer.arm.com/documentation/101550/latest/
---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/test/Misc/target-invalid-cpu-note.c   |  4 ++--
 llvm/docs/ReleaseNotes.rst  |  2 +-
 .../llvm/TargetParser/AArch64TargetParser.h | 13 -
 llvm/lib/Target/AArch64/AArch64Processors.td| 15 ++-
 llvm/lib/Target/AArch64/AArch64Subtarget.cpp|  1 +
 llvm/lib/TargetParser/Host.cpp  |  1 +
 .../unittests/TargetParser/TargetParserTest.cpp | 17 +++--
 8 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5d4d152b2eb540..c92d480023f4d4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -645,6 +645,7 @@ Arm and AArch64 Support
 * Arm Cortex-A78AE (cortex-a78ae).
 * Arm Cortex-A520AE (cortex-a520ae).
 * Arm Cortex-A720AE (cortex-a720ae).
+* Arm Cortex-R82AE (cortex-r82ae).
 * Arm Neoverse-N3 (neoverse-n3).
 * Arm Neoverse-V3 (neoverse-v3).
 * Arm Neoverse-V3AE (neoverse-v3ae).
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 21d80b7134508f..768b243b04e3a3 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a520ae, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, cortex-a710, 
cortex-a715, cortex-a720, cortex-a720ae, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, cortex-x3, cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, 
neoverse-n3, neoverse-512tvb, neoverse-v1, neoverse-v2, neoverse-v3, 
neoverse-v3ae, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, ampere1b, 
cobalt-100, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a520ae, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, cortex-a710, 
cortex-a715, cortex-a720, cortex-a720ae, cortex-r82, cortex-r82ae, cortex-x1, 
cortex-x1c, cortex-x2, cortex-x3, cortex-x4, neoverse-e1, neoverse-n1, 
neoverse-n2, neoverse-n3, neoverse-512tvb, neoverse-v1, neoverse-v2, 
neoverse-v3, neoverse-v3ae, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, 
apple-m1, apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, 
ampere1a, ampere1b, cobalt-100, grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a520ae, 
cortex-a57, cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, 
cortex-a76, cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, 
cortex-a710, cortex-a715, cortex-a720, cortex-a720ae, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, cortex-x3, cortex-x4, neoverse-e1, neoverse-n1, 
neoverse-n2, neoverse-n3, neoverse-512tvb, neoverse-v1, neoverse-v2, 
neoverse-v3, neoverse-v3ae, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, 
apple-m1, apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, 
ampere1a, ampere1b, cobalt

[clang] [llvm] [AArch64] Add support for Cortex-R82AE and improve Cortex-R82 (PR #90440)

2024-04-30 Thread Jonathan Thackray via cfe-commits


@@ -632,7 +632,18 @@ inline constexpr CpuInfo CpuInfos[] = {
AArch64::AEK_PAUTH, AArch64::AEK_SVE2BITPERM,
AArch64::AEK_FLAGM, AArch64::AEK_PERFMON,
AArch64::AEK_PREDRES, AArch64::AEK_PROFILE})},
-{"cortex-r82", ARMV8R, AArch64::ExtensionBitset({AArch64::AEK_LSE})},
+{"cortex-r82", ARMV8R,
+ AArch64::ExtensionBitset({AArch64::AEK_CRC, AArch64::AEK_DOTPROD,

jthackray wrote:

Ah yes. Now definitely enabled in the latest commit.

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


[clang] 2f9462e - [clang][Interp] Fix initializing vectors from a list of other vectors

2024-04-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-30T12:41:14+02:00
New Revision: 2f9462e9e4f2b2b493673c39d4ad665175eb0b59

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

LOG: [clang][Interp] Fix initializing vectors from a list of other vectors

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/opencl.cl

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 17f95e7f3cac0d..b07c57ab86d9ad 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1186,11 +1186,21 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
   if (!this->visit(Init))
 return false;
 
-  if (!this->emitInitElem(ElemT, InitIndex, E))
-return false;
-  ++InitIndex;
+  // If the initializer is of vector type itself, we have to deconstruct
+  // that and initialize all the target fields from the initializer fields.
+  if (const auto *InitVecT = Init->getType()->getAs()) {
+if (!this->emitCopyArray(ElemT, 0, InitIndex, 
InitVecT->getNumElements(), E))
+  return false;
+InitIndex += InitVecT->getNumElements();
+  } else {
+if (!this->emitInitElem(ElemT, InitIndex, E))
+  return false;
+++InitIndex;
+  }
 }
 
+assert(InitIndex <= NumVecElements);
+
 // Fill the rest with zeroes.
 for (; InitIndex != NumVecElements; ++InitIndex) {
   if (!this->visitZeroInitializer(ElemT, ElemQT, E))

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 2b650d684be9c4..66d30cc3fbaaba 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2090,6 +2090,24 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, 
uint32_t Index) {
   return true;
 }
 
+template ::T>
+inline bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex, 
uint32_t DestIndex, uint32_t Size) {
+  const auto &SrcPtr = S.Stk.pop();
+  const auto &DestPtr = S.Stk.peek();
+
+  for (uint32_t I = 0; I != Size; ++I) {
+const Pointer &SP = SrcPtr.atIndex(SrcIndex + I);
+
+if (!CheckLoad(S, OpPC, SP))
+  return false;
+
+const Pointer &DP = DestPtr.atIndex(DestIndex + I);
+DP.deref() = SP.deref();
+DP.initialize();
+  }
+  return true;
+}
+
 /// Just takes a pointer and checks if it's an incomplete
 /// array type.
 inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 2a97b978b52325..cfbd7f93c32de8 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -376,7 +376,11 @@ def ArrayElem : Opcode {
   let HasGroup = 1;
 }
 
-
+def CopyArray : Opcode {
+  let Args = [ArgUint32, ArgUint32, ArgUint32];
+  let Types = [AllTypeClass];
+  let HasGroup = 1;
+}
 
 
//===--===//
 // Direct field accessors

diff  --git a/clang/test/AST/Interp/opencl.cl b/clang/test/AST/Interp/opencl.cl
index e7b9ec5caf2b1e..fd7756fff7c11e 100644
--- a/clang/test/AST/Interp/opencl.cl
+++ b/clang/test/AST/Interp/opencl.cl
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify=ref,both %s
-// RUN: %clang_cc1 -fsyntax-only -verify=expected,both %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -fsyntax-only -cl-std=CL2.0 -verify=ref,both %s
+// RUN: %clang_cc1 -fsyntax-only -cl-std=CL2.0 -verify=expected,both %s 
-fexperimental-new-constant-interpreter
 
 // both-no-diagnostics
 
@@ -33,3 +33,6 @@ void foo(int3 arg1, int8 arg2) {
 void negativeShift32(int a,int b) {
   char array0[((int)1)<<40];
 }
+
+int2 A = {1,2};
+int4 B = {(int2)(1,2), (int2)(3,4)};



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


[clang] af5d41e - [clang][Interp] Support CXXScalarValueInitExprs of vector type

2024-04-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-30T12:41:14+02:00
New Revision: af5d41e0caf22536fbfb6e65aa10eff78118c822

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

LOG: [clang][Interp] Support CXXScalarValueInitExprs of vector type

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/CodeGenCXX/mangle-ms-vector-types.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b07c57ab86d9ad..f1a51e81a92c2d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2292,26 +2292,54 @@ bool 
ByteCodeExprGen::VisitCXXScalarValueInitExpr(
   if (std::optional T = classify(Ty))
 return this->visitZeroInitializer(*T, Ty, E);
 
-  assert(Ty->isAnyComplexType());
-  if (!Initializing) {
-std::optional LocalIndex = allocateLocal(E, 
/*IsExtended=*/false);
-if (!LocalIndex)
-  return false;
-if (!this->emitGetPtrLocal(*LocalIndex, E))
-  return false;
+  if (const auto *CT = Ty->getAs()) {
+if (!Initializing) {
+  std::optional LocalIndex =
+  allocateLocal(E, /*IsExtended=*/false);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, E))
+return false;
+}
+
+// Initialize both fields to 0.
+QualType ElemQT = CT->getElementType();
+PrimType ElemT = classifyPrim(ElemQT);
+
+for (unsigned I = 0; I != 2; ++I) {
+  if (!this->visitZeroInitializer(ElemT, ElemQT, E))
+return false;
+  if (!this->emitInitElem(ElemT, I, E))
+return false;
+}
+return true;
   }
 
-  // Initialize both fields to 0.
-  QualType ElemQT = Ty->getAs()->getElementType();
-  PrimType ElemT = classifyPrim(ElemQT);
+  if (const auto *VT = Ty->getAs()) {
+// FIXME: Code duplication with the _Complex case above.
+if (!Initializing) {
+  std::optional LocalIndex =
+  allocateLocal(E, /*IsExtended=*/false);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, E))
+return false;
+}
 
-  for (unsigned I = 0; I != 2; ++I) {
-if (!this->visitZeroInitializer(ElemT, ElemQT, E))
-  return false;
-if (!this->emitInitElem(ElemT, I, E))
-  return false;
+// Initialize all fields to 0.
+QualType ElemQT = VT->getElementType();
+PrimType ElemT = classifyPrim(ElemQT);
+
+for (unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
+  if (!this->visitZeroInitializer(ElemT, ElemQT, E))
+return false;
+  if (!this->emitInitElem(ElemT, I, E))
+return false;
+}
+return true;
   }
-  return true;
+
+  return false;
 }
 
 template 

diff  --git a/clang/test/CodeGenCXX/mangle-ms-vector-types.cpp 
b/clang/test/CodeGenCXX/mangle-ms-vector-types.cpp
index 6699c99deaec00..9a0c8896166222 100644
--- a/clang/test/CodeGenCXX/mangle-ms-vector-types.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-vector-types.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fms-extensions -fcxx-exceptions -ffreestanding 
-target-feature +avx -emit-llvm %s -o - -triple=i686-pc-win32 | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -fcxx-exceptions -ffreestanding 
-target-feature +avx -emit-llvm %s -o - -triple=i686-pc-win32 
-fexperimental-new-constant-interpreter | FileCheck %s
 
 #include 
 #include 



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


[clang] [clang][Interp] Report erroneous floating point results in _Complex math (PR #90588)

2024-04-30 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/90588

Use handleFloatFloatBinOp to properly diagnose NaN results and divisions by 
zero.

Fixes #84871

>From edb5cd5c610f112bca4c9d027a017e9e6dc9bf10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 30 Apr 2024 12:25:20 +0200
Subject: [PATCH] [clang][Interp] Report erroneous floating point results in
 _Complex math

Use handleFloatFloatBinOp to properly diagnose NaN results and divisions
by zero.
---
 clang/lib/AST/ExprConstant.cpp | 27 +++---
 clang/test/SemaCXX/complex-folding.cpp | 73 --
 2 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..86fb396fabe2d9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15209,11 +15209,21 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResI = Result.getComplexFloatImag();
   if (LHSReal) {
 assert(!RHSReal && "Cannot have two real operands for a complex op!");
-ResR = A * C;
-ResI = A * D;
+ResR = A;
+ResI = A;
+// ResR = A * C;
+// ResI = A * D;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, D))
+  return false;
   } else if (RHSReal) {
-ResR = C * A;
-ResI = C * B;
+// ResR = C * A;
+// ResI = C * B;
+ResR = C;
+ResI = C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, A) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, B))
+  return false;
   } else {
 // In the fully general case, we need to handle NaNs and infinities
 // robustly.
@@ -15289,8 +15299,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResR = Result.getComplexFloatReal();
   APFloat &ResI = Result.getComplexFloatImag();
   if (RHSReal) {
-ResR = A / C;
-ResI = B / C;
+ResR = A;
+ResI = B;
+// ResR = A / C;
+// ResI = B / C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Div, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Div, C))
+  return false;
   } else {
 if (LHSReal) {
   // No real optimizations we can do here, stub out with zero.
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 054f159e9ce0dd..d3e428f2b75cc2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -57,43 +57,58 @@ static_assert(((1.25 + 0.5j) / (0.25 - 0.75j)) == (-0.1 + 
1.7j));
 static_assert(((1.25 + 0.5j) / 0.25) == (5.0 + 2.0j));
 static_assert((1.25 / (0.25 - 0.75j)) == (0.5 + 1.5j));
 
-// Test that infinities are preserved, don't turn into NaNs, and do form zeros
-// when the divisor.
+
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 1.0)) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
1.0)) == 1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
1.0)) == 1); // expected-error {{static assertion}} \
+   
   // expected-note {{produces a NaN}}
 static_assert(__builtin_isinf_sign(__real__(1.0 * (__builtin_inf() + 1.0j))) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 
1.0j))) == 1);
-
+static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 
1.0j))) == 1); // expected-error {{static assertion}} \
+   
   // expected-note {{produces a NaN}}
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * (1.0 + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (__builtin_inf() + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 
(__builtin_inf() + 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == 1);
-static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + __builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + __builtin_inf() 
* 1.0j) * (__builtin_inf() + __builtin_inf() * 1.0j))) == -1);
-
+static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == -1);  // expected-erro

[clang] [clang]Report erroneous floating point results in _Complex math (PR #90588)

2024-04-30 Thread Timm Baeder via cfe-commits

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


[clang] [clang]Report erroneous floating point results in _Complex math (PR #90588)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Use handleFloatFloatBinOp to properly diagnose NaN results and divisions by 
zero.

Fixes #84871

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


2 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+21-6) 
- (modified) clang/test/SemaCXX/complex-folding.cpp (+44-29) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..86fb396fabe2d9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15209,11 +15209,21 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResI = Result.getComplexFloatImag();
   if (LHSReal) {
 assert(!RHSReal && "Cannot have two real operands for a complex op!");
-ResR = A * C;
-ResI = A * D;
+ResR = A;
+ResI = A;
+// ResR = A * C;
+// ResI = A * D;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, D))
+  return false;
   } else if (RHSReal) {
-ResR = C * A;
-ResI = C * B;
+// ResR = C * A;
+// ResI = C * B;
+ResR = C;
+ResI = C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, A) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, B))
+  return false;
   } else {
 // In the fully general case, we need to handle NaNs and infinities
 // robustly.
@@ -15289,8 +15299,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResR = Result.getComplexFloatReal();
   APFloat &ResI = Result.getComplexFloatImag();
   if (RHSReal) {
-ResR = A / C;
-ResI = B / C;
+ResR = A;
+ResI = B;
+// ResR = A / C;
+// ResI = B / C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Div, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Div, C))
+  return false;
   } else {
 if (LHSReal) {
   // No real optimizations we can do here, stub out with zero.
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 054f159e9ce0dd..d3e428f2b75cc2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -57,43 +57,58 @@ static_assert(((1.25 + 0.5j) / (0.25 - 0.75j)) == (-0.1 + 
1.7j));
 static_assert(((1.25 + 0.5j) / 0.25) == (5.0 + 2.0j));
 static_assert((1.25 / (0.25 - 0.75j)) == (0.5 + 1.5j));
 
-// Test that infinities are preserved, don't turn into NaNs, and do form zeros
-// when the divisor.
+
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 1.0)) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
1.0)) == 1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
1.0)) == 1); // expected-error {{static assertion}} \
+   
   // expected-note {{produces a NaN}}
 static_assert(__builtin_isinf_sign(__real__(1.0 * (__builtin_inf() + 1.0j))) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 
1.0j))) == 1);
-
+static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 
1.0j))) == 1); // expected-error {{static assertion}} \
+   
   // expected-note {{produces a NaN}}
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * (1.0 + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (__builtin_inf() + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 
(__builtin_inf() + 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == 1);
-static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + __builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + __builtin_inf() 
* 1.0j) * (__builtin_inf() + __builtin_inf() * 1.0j))) == -1);
-
+static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == -1);  // expected-error {{static assertion}} \
+   
  // expected-note {{produces a NaN}}
+static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == 1); // expected-error

[clang] [llvm] [AArch64] Add support for Cortex-R82AE and improve Cortex-R82 (PR #90440)

2024-04-30 Thread David Green via cfe-commits

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

Thanks. LGTM

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


[clang] Dev trunk (PR #90590)

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


[clang] Dev trunk (PR #90590)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yash-kumar8)


Changes

 Fix endline comment alignment, inline constructor definition alignment, 
variable name alignment with bit field

---

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


28 Files Affected:

- (modified) clang/include/clang/Format/Format.h (+7-2) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+27-1) 
- (modified) clang/lib/Format/Format.cpp (+4) 
- (modified) clang/lib/Format/FormatToken.cpp (+94-1) 
- (modified) clang/lib/Format/FormatToken.h (+859-1) 
- (modified) clang/lib/Format/FormatTokenLexer.cpp (+2) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+632-4) 
- (modified) clang/lib/Format/TokenAnnotator.h (+100-2) 
- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+125-9) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+17) 
- (modified) clang/lib/Format/WhitespaceManager.cpp (+1238-5) 
- (modified) clang/lib/Format/WhitespaceManager.h (+62) 
- (modified) clang/tools/clang-format/ClangFormat.cpp (+179) 
- (modified) clang/unittests/CMakeLists.txt (+1) 
- (added) clang/unittests/TWClangFormat/CMakeLists.txt (+15) 
- (added) clang/unittests/TWClangFormat/DummyTest.cpp (+45) 
- (added) clang/unittests/TWClangFormat/FormatTestBase.h (+179) 
- (added) clang/unittests/TWClangFormat/FormatTestUtils.h (+74) 
- (added) clang/unittests/TWClangFormat/TWClangTests.vcxproj (+139) 
- (added) clang/unittests/TWClangFormat/TWClangTests.vcxproj.filters (+25) 
- (added) clang/unittests/TWClangFormat/TWClangTests.vcxproj.user (+4) 
- (added) clang/unittests/TWClangFormat/TestLexer.h (+122) 
- (added) clang/unittests/TWClangFormat/x64/Debug/TWClangTests.log (+357) 
- (added) 
clang/unittests/TWClangFormat/x64/Debug/TWClangTests.tlog/CL.command.1.tlog 
(+1) 
- (added) 
clang/unittests/TWClangFormat/x64/Debug/TWClangTests.tlog/TWClangTests.lastbuildstate
 (+2) 
- (added) 
clang/unittests/TWClangFormat/x64/Debug/TWClangTests.tlog/unsuccessfulbuild () 
- (added) clang/unittests/TWClangFormat/x64/Debug/vc143.idb () 
- (added) clang/unittests/TWClangFormat/x64/Debug/vc143.pdb () 


``diff
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index e9b2160a7b9243..8b4facf9503663 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -31,7 +31,7 @@ class FileSystem;
 
 namespace clang {
 namespace format {
-
+
 enum class ParseError {
   Success = 0,
   Error,
@@ -2249,6 +2249,9 @@ struct FormatStyle {
   /// \version 3.7
   unsigned ColumnLimit;
 
+  /// TALLY: The extended column limit
+  unsigned ColumnLimitExtended = ;
+
   /// A regular expression that describes comments with special meaning,
   /// which should not be split into lines or otherwise changed.
   /// \code
@@ -5272,7 +5275,9 @@ inline StringRef 
getLanguageName(FormatStyle::LanguageKind Language) {
 
 bool isClangFormatOn(StringRef Comment);
 bool isClangFormatOff(StringRef Comment);
-
+llvm::ErrorOr>
+loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS,
+   FormatStyle *Style, bool AllowUnknownOptions);
 } // end namespace format
 } // end namespace clang
 
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 159d130cb67332..9aa7afcec7fe75 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -627,6 +627,30 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   if (State.NoContinuation)
 return true;
 
+  // TALLY : By default the newlines are honored. For few cases
+  //  like start of function definition and conditional
+  //  and loop expressions should have a rigid frame.
+  FormatToken *tokenlast;
+  FormatToken *tokenfirst;
+
+  if (State.Line)
+tokenlast = State.Line->Last;
+tokenfirst = State.Line->First;
+
+if (tokenfirst && tokenfirst->isOneOf(tok::kw_else, tok::kw_while, 
tok::kw_do, tok::kw_if, tok::kw_for))
+  return !(State.NextToken->LparenCount == State.NextToken->RparenCount);
+
+if (tokenlast && tokenlast->isTrailingComment())
+  tokenlast = tokenlast->getPreviousNonComment();
+
+if (tokenfirst && tokenfirst->is(tok::r_brace) &&
+tokenlast && tokenlast->isOneOf(tok::l_brace, tok::semi)) {
+
+  if (tokenfirst->getNextNonComment () &&
+  tokenfirst->getNextNonComment ()->isOneOf (tok::kw_else, 
tok::kw_while))
+return !(State.NextToken->LparenCount == State.NextToken->RparenCount);
+}
+
   return false;
 }
 
@@ -1392,6 +1416,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   return CurrentState.ColonPos - NextNonComment->ColumnWidth;
 return CurrentState.Indent;
   }
+  //if (NextNonComment->isOneOf(tok::colon, TT_CtorInitializerColon) && 
Current.is(tok::r_paren)) // TALLY
+  //return CurrentState

[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread Jeff Hammond via cfe-commits

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


[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread Jeff Hammond via cfe-commits

jeffhammond wrote:

This solves the problem that motivated my initial complaint on Slack.

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


[clang] [NFC][Clang] Update P2718R0 implementation status to partial supported (PR #90577)

2024-04-30 Thread via cfe-commits

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


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


[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread Jeff Hammond via cfe-commits

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


[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kiran Chandramohan (kiranchandramohan)


Changes

A quick and dirty implementation of the -w option. Filters the warning messages 
generated by the Frontend during emission.

TODO: Add more tests
TODO: Ignore MLIR, LLVM IR, Driver and pedantic Semantics warnings
TODO: Check whether we can avoid generating rather than filtering the warning 
options in the frontend
TODO: Check whether a ShouldWarn should precede each warning in the frontend as 
in the case of portability warnings.
TODO: Check the clang implementation of -w

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


11 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) 
- (modified) flang/include/flang/Frontend/FrontendOptions.h (+5-1) 
- (modified) flang/include/flang/Parser/message.h (+1-1) 
- (modified) flang/include/flang/Semantics/semantics.h (+1-1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3) 
- (modified) flang/lib/Frontend/FrontendAction.cpp (+5-2) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+8-3) 
- (modified) flang/lib/Parser/message.cpp (+6-2) 
- (modified) flang/lib/Semantics/semantics.cpp (+4-2) 
- (added) flang/test/Driver/w-option.f90 (+14) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 086aedefc11878..e73aee3f63fa47 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5680,7 +5680,7 @@ def whatsloaded : Flag<["-"], "whatsloaded">;
 def why_load : Flag<["-"], "why_load">;
 def whyload : Flag<["-"], "whyload">, Alias;
 def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoFlag>;
 def x : JoinedOrSeparate<["-"], "x">,
 Flags<[NoXarchOption]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6d93c1f3d7034a..6d1372152601e5 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -757,6 +757,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // Add other compile options
   addOtherOptions(Args, CmdArgs);
 
+  Args.AddLastArg(CmdArgs, options::OPT_w);
+
   // Forward flags for OpenMP. We don't do this if the current action is an
   // device offloading action other than OpenMP.
   if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
diff --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 06b1318f243b08..acbc55a75f9a11 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -232,7 +232,8 @@ class FrontendInputFile {
 struct FrontendOptions {
   FrontendOptions()
   : showHelp(false), showVersion(false), instrumentedParse(false),
-showColors(false), needProvenanceRangeToCharBlockMappings(false) {}
+showColors(false), needProvenanceRangeToCharBlockMappings(false),
+disableWarnings(false) {}
 
   /// Show the -help text.
   unsigned showHelp : 1;
@@ -251,6 +252,9 @@ struct FrontendOptions {
   /// compilation.
   unsigned needProvenanceRangeToCharBlockMappings : 1;
 
+  /// Disable warnings emitted by the Frontend
+  unsigned disableWarnings : 1;
+
   /// Input values from `-fget-definition`
   struct GetDefinitionVals {
 unsigned line;
diff --git a/flang/include/flang/Parser/message.h 
b/flang/include/flang/Parser/message.h
index 668559aeec9478..d1eb6e6f5aa52d 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -284,7 +284,7 @@ class Messages {
   void Copy(const Messages &);
   void ResolveProvenances(const AllCookedSources &);
   void Emit(llvm::raw_ostream &, const AllCookedSources &,
-  bool echoSourceLines = true) const;
+  bool echoSourceLines = true, bool disableWarnings = false) const;
   void AttachTo(Message &, std::optional = std::nullopt);
   bool AnyFatalError() const;
 
diff --git a/flang/include/flang/Semantics/semantics.h 
b/flang/include/flang/Semantics/semantics.h
index c8ee71945d8bde..456c2928f5b368 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -312,7 +312,7 @@ class Semantics {
 return context_.FindScope(where);
   }
   bool AnyFatalError() const { return context_.AnyFatalError(); }
-  void EmitMessages(llvm::raw_ostream &) const;
+  void EmitMessages(llvm::raw_ostream &, bool disableWarnings = false) const;
   void DumpSymbols(llvm::raw_ostream &);
   void DumpSymbolsSources(llvm::raw_ostream &) const;
 
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f1b7b53975398e..4a19592edf6ed8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Fronten

[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread Jeff Hammond via cfe-commits

jeffhammond wrote:

Sorry, I bumped the "Ready for Review" button on accident.

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


[clang] [OpenACC] Private Clause on Compute Constructs (PR #90521)

2024-04-30 Thread Alexey Bataev via cfe-commits


@@ -958,13 +931,14 @@ Parser::OpenACCClauseParseResult 
Parser::ParseOpenACCClauseParams(
 case OpenACCClauseKind::Link:
 case OpenACCClauseKind::NoCreate:
 case OpenACCClauseKind::Present:
-case OpenACCClauseKind::Private:
 case OpenACCClauseKind::UseDevice:
-  if (ParseOpenACCClauseVarList(ClauseKind)) {
-Parens.skipToEnd();
-return OpenACCCanContinue();
-  }
+  ParseOpenACCVarList();
+  break;
+case OpenACCClauseKind::Private: {
+  llvm::SmallVector Vars = ParseOpenACCVarList();
+  ParsedClause.setVarListDetails(std::move(Vars));

alexey-bataev wrote:

Why do you need std::move here?

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


[clang] [OpenACC] Private Clause on Compute Constructs (PR #90521)

2024-04-30 Thread Alexey Bataev via cfe-commits


@@ -112,6 +116,18 @@ class SemaOpenACC : public SemaBase {
   return const_cast(this)->getIntExprs();
 }
 
+// Non-const version that permits modifying of the VarList for the purposes
+// of Sema enforcement.
+SmallVector &getVarList() {

alexey-bataev wrote:

```suggestion
ArrayRef getVarList() {
```

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


[clang] [OpenACC] Private Clause on Compute Constructs (PR #90521)

2024-04-30 Thread Alexey Bataev via cfe-commits


@@ -11196,6 +11198,31 @@ void 
OpenACCClauseTransform::VisitNumGangsClause(
   ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
   ParsedClause.getEndLoc());
 }
+
+template 
+void OpenACCClauseTransform::VisitPrivateClause(
+const OpenACCPrivateClause &C) {
+  llvm::SmallVector InstantiatedVarList;
+
+  for (Expr *CurVar : C.getVarList()) {
+ExprResult Res = Self.TransformExpr(CurVar);
+
+if (!Res.isUsable())
+  return;
+
+Res = Self.getSema().OpenACC().ActOnVar(Res.get());
+
+if (Res.isUsable())
+  InstantiatedVarList.push_back(Res.get());
+  }
+  ParsedClause.setVarListDetails(std::move(InstantiatedVarList));

alexey-bataev wrote:

Why do you need std::move here?

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


[clang] [OpenACC] Private Clause on Compute Constructs (PR #90521)

2024-04-30 Thread Alexey Bataev via cfe-commits


@@ -423,6 +450,52 @@ ExprResult SemaOpenACC::ActOnIntExpr(OpenACCDirectiveKind 
DK,
   return IntExpr;
 }
 
+ExprResult SemaOpenACC::ActOnVar(Expr *VarExpr) {
+  // We still need to retain the array subscript/subarray exprs, so work on a
+  // copy.
+  Expr *CurVarExpr = VarExpr->IgnoreParenImpCasts();
+
+  // Sub-arrays/subscript-exprs are fine as long as the base is a
+  // VarExpr/MemberExpr. So strip all of those off.
+  while (isa(CurVarExpr)) {
+if (auto *SubScrpt = dyn_cast(CurVarExpr))
+  CurVarExpr = SubScrpt->getBase()->IgnoreParenImpCasts();
+else
+  CurVarExpr =
+  cast(CurVarExpr)->getBase()->IgnoreParenImpCasts();
+  }

alexey-bataev wrote:

What if the array is casted to a pointer, will this be supported?

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


[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread Jeff Hammond via cfe-commits

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


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


[clang] [Sema] Avoid an undesired pack expansion while transforming PackIndexingType (PR #90195)

2024-04-30 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [Sema] Avoid an undesired pack expansion while transforming PackIndexingType (PR #90195)

2024-04-30 Thread via cfe-commits


@@ -216,8 +216,14 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const 
Expr *E) {
 return ClassifyInternal(Ctx,
  cast(E)->getReplacement());
 
-  case Expr::PackIndexingExprClass:
+  case Expr::PackIndexingExprClass: {
+// A dependent pack-index-expression is now supposed to denote a function
+// parameter pack, an NTTP pack, or the pack introduced by a structured
+// binding. Consider it as an LValue expression.
+if (cast(E)->isInstantiationDependent())
+  return Cl::CL_LValue;

cor3ntin wrote:

```suggestion
  case Expr::PackIndexingExprClass: {
// A pack-index-expression always expand to an id-expression. 
Consider it as an LValue expression.
if (cast(E)->isInstantiationDependent())
  return Cl::CL_LValue;
```

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


[clang] [Sema] Avoid an undesired pack expansion while transforming PackIndexingType (PR #90195)

2024-04-30 Thread via cfe-commits

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


[clang] [NFC][Clang] Update P2718R0 implementation status to partial supported (PR #90577)

2024-04-30 Thread via cfe-commits

yronglin wrote:

Thanks for your review!

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


[clang] 6fab3f2 - [NFC][Clang] Update P2718R0 implementation status to partial supported (#90577)

2024-04-30 Thread via cfe-commits

Author: yronglin
Date: 2024-04-30T18:58:59+08:00
New Revision: 6fab3f2a2b04048aaa7d76d067f6cd4704bb4002

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

LOG: [NFC][Clang] Update P2718R0 implementation status to partial supported 
(#90577)

Once https://github.com/llvm/llvm-project/issues/85613 fixed, we can
mark this feature fully supported.

Signed-off-by: yronglin 

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 0996abc2405857..6db6ae57d12603 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -167,7 +167,7 @@ C++2c implementation status
  
   Disallow Binding a Returned Glvalue to a Temporary
   https://wg21.link/P2748R5";>P2748R5
-  Clang 19
+  Clang 19
  
  
   Clarifying rules for brace elision in aggregate initialization
@@ -462,7 +462,14 @@ C++23 implementation status
 
   Lifetime extension in range-based for loops
   https://wg21.link/P2718R0";>P2718R0
-  Clang 19
+  
+
+  Clang 19 (Partial)
+The lifetime extension of temporaries bound to member references
+by default member initializers in aggregate initialization was 
+not supported now.
+
+  
 
 
 



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


[clang] [NFC][Clang] Update P2718R0 implementation status to partial supported (PR #90577)

2024-04-30 Thread via cfe-commits

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


[clang] Dev trunk (PR #90590)

2024-04-30 Thread via cfe-commits

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


[clang] Dev trunk (PR #90590)

2024-04-30 Thread via cfe-commits

yash-kumar8 wrote:

not to be pushed in main branch

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


[clang] [flang] [Flang] RFC: Add support for -w option (PR #90420)

2024-04-30 Thread Kiran Chandramohan via cfe-commits

kiranchandramohan wrote:

Thanks @jeffhammond. I will wait for @klausler to submit 
https://github.com/llvm/llvm-project/pull/90518 which will make it easier for 
the driver and will provide more fine-grained control of warnings.

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-04-30 Thread via cfe-commits


@@ -2690,6 +2690,13 @@ bool Parser::ParseModuleName(
   return true;
 }
 
+// P3034R1: Module Declarations Shouldn’t be Macros
+if (!IsImport && Tok.getLocation().isMacroID()) {
+  Diag(Tok, diag::err_module_decl_cannot_be_macros);
+  SkipUntil(tok::semi);
+  return true;

cor3ntin wrote:

I think we can continue here

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-04-30 Thread via cfe-commits


@@ -1671,6 +1671,8 @@ def err_unexpected_module_decl : Error<
   "module declaration can only appear at the top level">;
 def err_module_expected_ident : Error<
   "expected a module name after '%select{module|import}0'">;
+def err_module_decl_cannot_be_macros : Error<
+  "module declaration cannot be a macro">;

cor3ntin wrote:

```suggestion
  "The name of a module|module partition declaration cannot contain a macro">;
```

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-04-30 Thread via cfe-commits


@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -triple 
x86_64-linux-gnu -DTEST=1 -verify
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -triple 
x86_64-linux-gnu -DTEST=2 -verify
+
+module;
+export module x;
+#include "version.h"
+#if TEST == 1
+export module VERSION;  // expected-error {{module declaration cannot be a 
macro}}
+#endif // TEST == 1
+
+#if TEST == 2
+export module A.B;  // expected-error {{module declaration cannot be a 
macro}}
+#endif // TEST == 2

cor3ntin wrote:

Can you add tests for module partitions?

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


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-30 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh updated 
https://github.com/llvm/llvm-project/pull/90048

>From c5e7b2d5936a7317ebc33159b4cb72bf2aa66cf9 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Thu, 25 Apr 2024 14:10:19 +0100
Subject: [PATCH 1/4] [OpenCL] Put constant initializer globals into constant
 addrspace

Place constant initializer globals into the constant address space.
Clang generates such globals for e.g. larger array member initializers
of classes and then emits copy operations from the global to the
object(s).  The globals are never written so they ought to be in the
constant address space.
---
 clang/lib/CodeGen/CGExprAgg.cpp| 2 ++
 clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp | 5 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 355fec42be4489..30cde245cc837c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule &CGM = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp 
b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
index 18d97a989a4364..a0ed03b25535c8 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
@@ -5,7 +5,7 @@
 // for constructors, member functions and destructors.
 // See also atexit.cl and global_init.cl for other specific tests.
 
-// CHECK: %struct.MyType = type { i32 }
+// CHECK: %struct.MyType = type { i32, [5 x i32] }
 struct MyType {
   MyType(int i) : i(i) {}
   MyType(int i) __constant : i(i) {}
@@ -14,6 +14,7 @@ struct MyType {
   int bar() { return i + 2; }
   int bar() __constant { return i + 1; }
   int i;
+  int a[5] = {42, 43, 44, 45, 46};
 };
 
 // CHECK: @const1 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
@@ -23,6 +24,8 @@ __constant MyType const2(2);
 // CHECK: @glob ={{.*}} addrspace(1) global %struct.MyType zeroinitializer
 MyType glob(1);
 
+// CHECK: @constinit ={{.*}} addrspace(2) constant [5 x i32] [i32 42, i32 43, 
i32 44, i32 45, i32 46]
+
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const1, i32 noundef 1)
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const2, i32 noundef 2)
 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} 
addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), i32 noundef 1)

>From 08936e55847bd866a1a602a2d7b7c7de5a603df8 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Fri, 26 Apr 2024 13:56:25 +0100
Subject: [PATCH 2/4] Address code review comment: set ArrayQTy addrspace

---
 clang/lib/CodeGen/CGExprAgg.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 30cde245cc837c..44514c830b09cf 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,9 +535,10 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule &CGM = CGF.CGM;
 ConstantEmitter Emitter(CGF);
+if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
+  ArrayQTy = CGM.getContext().getAddrSpaceQualType(ArrayQTy,
+   
LangAS::opencl_constant);
 LangAS AS = ArrayQTy.getAddressSpace();
-if (CGF.getLangOpts().OpenCL)
-  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(

>From ebefe4bf61db905748da330a22aeb8782ef8cebf Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Mon, 29 Apr 2024 13:18:53 +0100
Subject: [PATCH 3/4] Address review comment: use GetGlobalConstantAddressSpace
 and extract GVArrayQTy

---
 clang/lib/CodeGen/CGExprAgg.cpp | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 44514c830b09cf..41a183ac829949 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,12 +535,13 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule &CGM = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
-  ArrayQTy = CGM.getContext()

[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-30 Thread Sven van Haastregt via cfe-commits


@@ -535,20 +535,24 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule &CGM = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-LangAS AS = ArrayQTy.getAddressSpace();
+QualType GVArrayQTy = ArrayQTy;
+if (!GVArrayQTy.hasAddressSpace())
+  GVArrayQTy = CGM.getContext().getAddrSpaceQualType(

svenvh wrote:

Thanks, updated.

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


[clang] bb95f5d - [clang][Interp] Visit LabelStmt sub statements

2024-04-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-30T13:42:55+02:00
New Revision: bb95f5df732d9188b27c7cd34814ead8b2c4d4ce

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

LOG: [clang][Interp] Visit LabelStmt sub statements

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/AST/Interp/cxx23.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index ff91baf595f1b1..ff92bc117f9efb 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -292,8 +292,9 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
   case Stmt::GCCAsmStmtClass:
   case Stmt::MSAsmStmtClass:
   case Stmt::GotoStmtClass:
-  case Stmt::LabelStmtClass:
 return this->emitInvalid(S);
+  case Stmt::LabelStmtClass:
+return this->visitStmt(cast(S)->getSubStmt());
   default: {
 if (auto *Exp = dyn_cast(S))
   return this->discard(Exp);

diff  --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp
index 13cc9f43febc74..d1ec93e99803e5 100644
--- a/clang/test/AST/Interp/cxx23.cpp
+++ b/clang/test/AST/Interp/cxx23.cpp
@@ -157,3 +157,16 @@ namespace VirtualBases {
 D d;
   }
 }
+
+namespace LabelGoto {
+  constexpr int foo() { // all20-error {{never produces a constant expression}}
+a: // all20-warning {{use of this statement in a constexpr function is a 
C++23 extension}}
+goto a; // all20-note 2{{subexpression not valid in a constant 
expression}} \
+// ref23-note {{subexpression not valid in a constant expression}} 
\
+// expected23-note {{subexpression not valid in a constant 
expression}}
+
+return 1;
+  }
+  static_assert(foo() == 1, ""); // all-error {{not an integral constant 
expression}} \
+ // all-note {{in call to}}
+}



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


[clang] [Clang][Parse] Delay parsing of noexcept-specifiers in friend function declarations (PR #90517)

2024-04-30 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/90517

>From 3f5feb2b17c06f6e001e9324e90eef07fd720539 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 29 Apr 2024 15:34:40 -0400
Subject: [PATCH 1/2] [Clang][Parse] Delay parsing of noexcept-specifiers in
 friend function declarations

---
 clang/lib/Parse/ParseDecl.cpp | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a7846e102a43c7..93950e27a08f35 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7388,12 +7388,20 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
   std::optional ThisScope;
   InitCXXThisScopeForDeclaratorIfRelevant(D, DS, ThisScope);
 
-  // Parse exception-specification[opt].
-  // FIXME: Per [class.mem]p6, all exception-specifications at class scope
-  // should be delayed, including those for non-members (eg, friend
-  // declarations). But only applying this to member declarations is
-  // consistent with what other implementations do.
-  bool Delayed = D.isFirstDeclarationOfMember() &&
+  // C++ [class.mem.general]p8:
+  //   A complete-class context of a class (template) is a
+  // - function body,
+  // - default argument,
+  // - default template argument,
+  // - noexcept-specifier, or
+  // - default member initializer
+  //   within the member-specification of the class or class template.
+  //
+  // Parse exception-specification[opt]. If we are in the
+  // member-specification of a class or class template, this is a
+  // complete-class context and parsing of the noexcept-specifier should be
+  // delayed (even if this is a friend declaration).
+  bool Delayed = D.getContext() == DeclaratorContext::Member &&
  D.isFunctionDeclaratorAFunctionDeclaration();
   if (Delayed && Actions.isLibstdcxxEagerExceptionSpecHack(D) &&
   GetLookAheadToken(0).is(tok::kw_noexcept) &&

>From a68b48237edcc7023983fafd0849b0625a18ddbf Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 30 Apr 2024 07:44:22 -0400
Subject: [PATCH 2/2] [FOLD] fix delayed parsing of exception specification for
 friend functions

---
 clang/lib/Sema/SemaDeclCXX.cpp|  30 ++---
 clang/lib/Sema/SemaExceptionSpec.cpp  |  12 +-
 .../class/class.mem/class.mem.general/p8.cpp  | 105 ++
 3 files changed, 127 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/CXX/class/class.mem/class.mem.general/p8.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 338b0ec1e099c0..f0422f6717675b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -19172,21 +19172,21 @@ void Sema::checkExceptionSpecification(
   }
 }
 
-void Sema::actOnDelayedExceptionSpecification(Decl *MethodD,
+void Sema::actOnDelayedExceptionSpecification(Decl *D,
  ExceptionSpecificationType EST,
  SourceRange SpecificationRange,
  ArrayRef DynamicExceptions,
  ArrayRef DynamicExceptionRanges,
  Expr *NoexceptExpr) {
-  if (!MethodD)
+  if (!D)
 return;
 
-  // Dig out the method we're referring to.
-  if (FunctionTemplateDecl *FunTmpl = dyn_cast(MethodD))
-MethodD = FunTmpl->getTemplatedDecl();
+  // Dig out the function we're referring to.
+  if (FunctionTemplateDecl *FTD = dyn_cast(D))
+D = FTD->getTemplatedDecl();
 
-  CXXMethodDecl *Method = dyn_cast(MethodD);
-  if (!Method)
+  FunctionDecl *FD = dyn_cast(D);
+  if (!FD)
 return;
 
   // Check the exception specification.
@@ -19197,15 +19197,17 @@ void Sema::actOnDelayedExceptionSpecification(Decl 
*MethodD,
   ESI);
 
   // Update the exception specification on the function type.
-  Context.adjustExceptionSpec(Method, ESI, /*AsWritten*/true);
+  Context.adjustExceptionSpec(FD, ESI, /*AsWritten*/true);
 
-  if (Method->isStatic())
-checkThisInStaticMemberFunctionExceptionSpec(Method);
+  if (CXXMethodDecl *MD = dyn_cast(D)) {
+if (MD->isStatic())
+  checkThisInStaticMemberFunctionExceptionSpec(MD);
 
-  if (Method->isVirtual()) {
-// Check overrides, which we previously had to delay.
-for (const CXXMethodDecl *O : Method->overridden_methods())
-  CheckOverridingFunctionExceptionSpec(Method, O);
+if (MD->isVirtual()) {
+  // Check overrides, which we previously had to delay.
+  for (const CXXMethodDecl *O : MD->overridden_methods())
+CheckOverridingFunctionExceptionSpec(MD, O);
+}
   }
 }
 
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index c9dd6bb2413e38..776d911be17957 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -258,13 +258,13 @@ Sema::UpdateExceptionSpec(FunctionDe

[clang] [Clang][Parse] Delay parsing of noexcept-specifiers in friend function declarations (PR #90517)

2024-04-30 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 179e174945b6c0da462c534504720c9544aebf84 
a68b48237edcc7023983fafd0849b0625a18ddbf -- 
clang/test/CXX/class/class.mem/class.mem.general/p8.cpp 
clang/lib/Parse/ParseDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/lib/Sema/SemaExceptionSpec.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index f0422f6717..e7a8c9ed07 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -19172,12 +19172,10 @@ void Sema::checkExceptionSpecification(
   }
 }
 
-void Sema::actOnDelayedExceptionSpecification(Decl *D,
- ExceptionSpecificationType EST,
- SourceRange SpecificationRange,
- ArrayRef DynamicExceptions,
- ArrayRef DynamicExceptionRanges,
- Expr *NoexceptExpr) {
+void Sema::actOnDelayedExceptionSpecification(
+Decl *D, ExceptionSpecificationType EST, SourceRange SpecificationRange,
+ArrayRef DynamicExceptions,
+ArrayRef DynamicExceptionRanges, Expr *NoexceptExpr) {
   if (!D)
 return;
 
@@ -19197,7 +19195,7 @@ void Sema::actOnDelayedExceptionSpecification(Decl *D,
   ESI);
 
   // Update the exception specification on the function type.
-  Context.adjustExceptionSpec(FD, ESI, /*AsWritten*/true);
+  Context.adjustExceptionSpec(FD, ESI, /*AsWritten*/ true);
 
   if (CXXMethodDecl *MD = dyn_cast(D)) {
 if (MD->isStatic())
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index 776d911be1..41bf273d12 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -258,7 +258,8 @@ Sema::UpdateExceptionSpec(FunctionDecl *FD,
 }
 
 static bool exceptionSpecNotKnownYet(const FunctionDecl *FD) {
-  ExceptionSpecificationType EST = 
FD->getType()->castAs()->getExceptionSpecType();
+  ExceptionSpecificationType EST =
+  FD->getType()->castAs()->getExceptionSpecType();
   if (EST == EST_Unparsed)
 return true;
   else if (EST != EST_Unevaluated)

``




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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI core info (PR #85235)

2024-04-30 Thread Daniil Kovalev via cfe-commits

kovdan01 wrote:

@MaskRay I've addressed your latest comments in 
fdb26a14024f5f8297480a74982a37ee988cd30f - would be glad to see your feedback 
on the changes

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


  1   2   3   4   5   >