[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread David Li via cfe-commits


@@ -4401,13 +4413,18 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
+  -fprofile-generate[=]

david-xl wrote:

-fprofile-generate=  in GCC specifies a path which is a directory name (the 
reason is that GCC's profile data is dumped per module, so there is no single 
profile name).

When we introduced this option in Clang/LLVM, we just matched that behavior.

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread David Li via cfe-commits


@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
-  -fprofile-instr-generate=
-  Generate instrumented code to collect execution 
counts into 
+  -fprofile-generate=
+  Generate instrumented code to collect execution 
counts into a raw profile file in the directory specified by the argument. The 
filename uses the %m format. See :ref:`Profiling With Instrumentation 
`  section for details.

david-xl wrote:

Fixed.

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread David Li via cfe-commits


@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
-  -fprofile-instr-generate=
-  Generate instrumented code to collect execution 
counts into 
+  -fprofile-generate=
+  Generate instrumented code to collect execution 
counts into a raw profile file in the directory specified by the argument. The 
filename uses the %m format. See :ref:`Profiling With Instrumentation 
`  section for details.
+  (overridden by LLVM_PROFILE_FILE env var)
+  -fprofile-generate
+  Generate instrumented code to collect execution 
counts into default_%m.profraw file
+  (overridden by '=' form of option or 
LLVM_PROFILE_FILE env var)
+  -fprofile-instr-generate=

david-xl wrote:

done (-fprofile-instr-generate was there before. I added -fprofile-generate).

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread David Li via cfe-commits

https://github.com/david-xl updated 
https://github.com/llvm/llvm-project/pull/73845

>From 29b5b28f52c88ebd862163c4feb1573460c5c79e Mon Sep 17 00:00:00 2001
From: David Li 
Date: Wed, 29 Nov 2023 11:56:31 -0800
Subject: [PATCH] Fix PGO documentation in user manual

---
 clang/docs/UsersManual.rst | 54 +++---
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 2e658557b0e310c..17e52a715e79e86 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2348,9 +2348,10 @@ differences between the two:
 
 1. Profile data generated with one cannot be used by the other, and there is no
conversion tool that can convert one to the other. So, a profile generated
-   via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
-   Similarly, sampling profiles generated by external profilers must be
-   converted and used with ``-fprofile-sample-use``.
+   via ``-fprofile-generate`` or ``-fprofile-instr-generate`` must be used with
+   ``-fprofile-use`` or ``-fprofile-instr-use``.  Similarly, sampling profiles
+   generated by external profilers must be converted and used with 
``-fprofile-sample-use``
+   or ``-fauto-profile``.
 
 2. Instrumentation profile data can be used for code coverage analysis and
optimization.
@@ -2598,6 +2599,8 @@ Of those, 31,977 were spent inside the body of ``bar``. 
The last line
 of the profile (``2: 0``) corresponds to line 2 inside ``main``. No
 samples were collected there.
 
+.. _prof_instr:
+
 Profiling with Instrumentation
 ^^
 
@@ -2607,11 +2610,25 @@ overhead during the profiling, but it provides more 
detailed results than a
 sampling profiler. It also provides reproducible results, at least to the
 extent that the code behaves consistently across runs.
 
+Clang supports two types of instrumentation: frontend-based and IR-based.
+Frontend-based instrumentation can be enabled with the option 
``-fprofile-instr-generate``,
+and IR-based instrumentation can be enabled with the option 
``-fprofile-generate``.
+For best performance with PGO, IR-based instrumentation should be used. It has
+the benefits of lower instrumentation overhead, smaller raw profile size, and
+better runtime performance. Frontend-based instrumentation, on the other hand,
+has better source correlation, so it should be used with source line-based
+coverage testing.
+
+The flag ``-fcs-profile-generate`` also instruments programs using the same
+instrumentation method as ``-fprofile-generate``. However, it performs a
+post-inline late instrumentation and can produce context-sensitive profiles.
+
+
 Here are the steps for using profile guided optimization with
 instrumentation:
 
 1. Build an instrumented version of the code by compiling and linking with the
-   ``-fprofile-instr-generate`` option.
+   ``-fprofile-generate`` or ``-fprofile-instr-generate`` option.
 
.. code-block:: console
 
@@ -2674,8 +2691,8 @@ instrumentation:
Note that this step is necessary even when there is only one "raw" profile,
since the merge operation also changes the file format.
 
-4. Build the code again using the ``-fprofile-instr-use`` option to specify the
-   collected profile data.
+4. Build the code again using the ``-fprofile-use`` or ``-fprofile-instr-use``
+   option to specify the collected profile data.
 
.. code-block:: console
 
@@ -2685,13 +2702,10 @@ instrumentation:
profile. As you make changes to your code, clang may no longer be able to
use the profile data. It will warn you when this happens.
 
-Profile generation using an alternative instrumentation method can be
-controlled by the GCC-compatible flags ``-fprofile-generate`` and
-``-fprofile-use``. Although these flags are semantically equivalent to
-their GCC counterparts, they *do not* handle GCC-compatible profiles.
-They are only meant to implement GCC's semantics with respect to
-profile creation and use. Flag ``-fcs-profile-generate`` also instruments
-programs using the same instrumentation method as ``-fprofile-generate``.
+Note that ``-fprofile-use`` option is semantically equivalent to
+its GCC counterpart, it *does not* handle profile formats produced by GCC.
+Both ``-fprofile-use`` and ``-fprofile-instr-use`` accept profiles in the
+indexed format, regardeless whether it is produced by frontend or the IR pass.
 
 .. option:: -fprofile-generate[=]
 
@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
-  -fprofile-instr-generate=
-  Generate instrumented code to collect execution 
counts into 
+  -fprofi

[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread Petr Hosek via cfe-commits


@@ -4401,13 +4413,18 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
+  -fprofile-generate[=]

petrhosek wrote:

This is really surprising but I just tested this and you're correct. Do you 
know why that's the case, that is why `-fprofile-generate=` and 
`-fprofile-instr-generate=` have a different behavior?

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread Petr Hosek via cfe-commits


@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
-  -fprofile-instr-generate=
-  Generate instrumented code to collect execution 
counts into 
+  -fprofile-generate=
+  Generate instrumented code to collect execution 
counts into a raw profile file in the directory specified by the argument. The 
filename uses the %m format. See :ref:`Profiling With Instrumentation 
`  section for details.
+  (overridden by LLVM_PROFILE_FILE env var)
+  -fprofile-generate
+  Generate instrumented code to collect execution 
counts into default_%m.profraw file
+  (overridden by '=' form of option or 
LLVM_PROFILE_FILE env var)
+  -fprofile-instr-generate=

petrhosek wrote:

Can you also add `-fprofile-instr-generate` case below for consistency?

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread Petr Hosek via cfe-commits


@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
-  -fprofile-instr-generate=
-  Generate instrumented code to collect execution 
counts into 
+  -fprofile-generate=
+  Generate instrumented code to collect execution 
counts into a raw profile file in the directory specified by the argument. The 
filename uses the %m format. See :ref:`Profiling With Instrumentation 
`  section for details.

petrhosek wrote:

Should the second sentence say "The filename uses the default_%m.profraw."?

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-01 Thread David Li via cfe-commits

https://github.com/david-xl updated 
https://github.com/llvm/llvm-project/pull/73845

>From 4cf62b1b780edef9902b5ec50b56d676810c3922 Mon Sep 17 00:00:00 2001
From: David Li 
Date: Wed, 29 Nov 2023 11:56:31 -0800
Subject: [PATCH] Fix PGO documentation in user manual

---
 clang/docs/UsersManual.rst | 54 +++---
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 2e658557b0e310c..6e9a7cd4cc17064 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2348,9 +2348,10 @@ differences between the two:
 
 1. Profile data generated with one cannot be used by the other, and there is no
conversion tool that can convert one to the other. So, a profile generated
-   via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
-   Similarly, sampling profiles generated by external profilers must be
-   converted and used with ``-fprofile-sample-use``.
+   via ``-fprofile-generate`` or ``-fprofile-instr-generate`` must be used with
+   ``-fprofile-use`` or ``-fprofile-instr-use``.  Similarly, sampling profiles
+   generated by external profilers must be converted and used with 
``-fprofile-sample-use``
+   or ``-fauto-profile``.
 
 2. Instrumentation profile data can be used for code coverage analysis and
optimization.
@@ -2598,6 +2599,8 @@ Of those, 31,977 were spent inside the body of ``bar``. 
The last line
 of the profile (``2: 0``) corresponds to line 2 inside ``main``. No
 samples were collected there.
 
+.. _prof_instr:
+
 Profiling with Instrumentation
 ^^
 
@@ -2607,11 +2610,25 @@ overhead during the profiling, but it provides more 
detailed results than a
 sampling profiler. It also provides reproducible results, at least to the
 extent that the code behaves consistently across runs.
 
+Clang supports two types of instrumentation: frontend-based and IR-based.
+Frontend-based instrumentation can be enabled with the option 
``-fprofile-instr-generate``,
+and IR-based instrumentation can be enabled with the option 
``-fprofile-generate``.
+For best performance with PGO, IR-based instrumentation should be used. It has
+the benefits of lower instrumentation overhead, smaller raw profile size, and
+better runtime performance. Frontend-based instrumentation, on the other hand,
+has better source correlation, so it should be used with source line-based
+coverage testing.
+
+The flag ``-fcs-profile-generate`` also instruments programs using the same
+instrumentation method as ``-fprofile-generate``. However, it performs a
+post-inline late instrumentation and can produce context-sensitive profiles.
+
+
 Here are the steps for using profile guided optimization with
 instrumentation:
 
 1. Build an instrumented version of the code by compiling and linking with the
-   ``-fprofile-instr-generate`` option.
+   ``-fprofile-generate`` or ``-fprofile-instr-generate`` option.
 
.. code-block:: console
 
@@ -2674,8 +2691,8 @@ instrumentation:
Note that this step is necessary even when there is only one "raw" profile,
since the merge operation also changes the file format.
 
-4. Build the code again using the ``-fprofile-instr-use`` option to specify the
-   collected profile data.
+4. Build the code again using the ``-fprofile-use`` or ``-fprofile-instr-use``
+   option to specify the collected profile data.
 
.. code-block:: console
 
@@ -2685,13 +2702,10 @@ instrumentation:
profile. As you make changes to your code, clang may no longer be able to
use the profile data. It will warn you when this happens.
 
-Profile generation using an alternative instrumentation method can be
-controlled by the GCC-compatible flags ``-fprofile-generate`` and
-``-fprofile-use``. Although these flags are semantically equivalent to
-their GCC counterparts, they *do not* handle GCC-compatible profiles.
-They are only meant to implement GCC's semantics with respect to
-profile creation and use. Flag ``-fcs-profile-generate`` also instruments
-programs using the same instrumentation method as ``-fprofile-generate``.
+Note that ``-fprofile-use`` option is semantically equivalent to
+its GCC counterpart, it *does not* handle profile formats produced by GCC.
+Both ``-fprofile-use`` and ``-fprofile-instr-use`` accept profiles in the
+indexed format, regardeless whether it is produced by frontend or the IR pass.
 
 .. option:: -fprofile-generate[=]
 
@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument only functions from files where names 
match any regex separated by a semi-colon
-  -fprofile-instr-generate=
-  Generate instrumented code to collect execution 
counts into 
+  -fprofi

[flang] [clang] [flang][Driver] Support -nodefaultlibs, -nostartfiles and -nostdlib (PR #72601)

2023-12-01 Thread Fangrui Song via cfe-commits




MaskRay wrote:

Perhaps `nostdlib.c` since nostdlib encompasses nodefaultlibs/nostartfiles. 
However, if we need another test for a `-no*` style option that is less related 
to `-nostdlib`, reusing `nostdlib.c` maybe slightly strange.

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


[clang] [clang] Reject incomplete type arguments for __builtin_dump_struct (PR #72749)

2023-12-01 Thread Shafik Yaghmour via cfe-commits

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

LGTM you should put the bug report in the problem description so it 
automatically links the PR and closes it when you merge it.

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits


@@ -2130,6 +2130,15 @@ void Generic_GCC::GCCInstallationDetector::init(
 return;
   }
 
+  // If --gcc-triple is specified use this instead of trying to
+  // auto-detect a triple.
+  if (const Arg *A =
+  Args.getLastArg(clang::driver::options::OPT_gcc_triple_EQ)) {
+StringRef GCCTriple = A->getValue();
+CandidateTripleAliases.clear();
+CandidateTripleAliases.push_back(GCCTriple);
+  }
+
   // Compute the set of prefixes for our search.

MaskRay wrote:

When `--gcc-triple=` is specified, should `--gcc-toolchain=` or configure-time 
`GCC_INSTALL_PREFIX` be ignored? (Shall we continue the effort to deprecate 
`GCC_INSTALL_PREFIX` even if `DEFAULT_SYSROOT` is to be retained as we don't 
have a replacement yet? https://reviews.llvm.org/D158218)

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang][ASTImporter] Fix import of variable template redeclarations. (PR #72841)

2023-12-01 Thread Shafik Yaghmour via cfe-commits
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= 
Message-ID:
In-Reply-To: 



@@ -5050,6 +5050,59 @@ TEST_P(ImportFriendClasses, RecordVarTemplateDecl) {
   EXPECT_EQ(ToTUX, ToX);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateDeclConflict) {
+  getToTuDecl(
+  R"(
+  template 
+  constexpr int X = 1;
+  )",
+  Lang_CXX14);
+
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  constexpr int X = 2;
+  )",
+  Lang_CXX14, "input1.cc");
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, varTemplateDecl(hasName("X")));
+  auto *ToX = Import(FromX, Lang_CXX11);
+  // FIXME: This import should fail.
+  EXPECT_TRUE(ToX);
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateStaticDefinition) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  struct A {
+template 
+static int X;
+  };
+  )",
+  Lang_CXX14);
+  auto *ToX = FirstDeclMatcher().match(
+  ToTU, varTemplateDecl(hasName("X")));
+  ASSERT_FALSE(ToX->isThisDeclarationADefinition());
+
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct A {
+template 

shafik wrote:

Did you mean to drop the `class V` here? 

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,8 @@
+// UNSUPPORTED: system-windows
+//
+// RUN: %clang --target=x86_64-redhat-linux-gnu \
+// RUN: --sysroot=%S/Inputs/fedora_39_tree --gcc-triple=x86_64-redhat-linux -v 
2>&1 | \
+// RUN: FileCheck %s
+//

MaskRay wrote:

Add another test when `--gcc-triple=` specifies a triple where the associated 
path does not exist.

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,8 @@
+// UNSUPPORTED: system-windows
+//
+// RUN: %clang --target=x86_64-redhat-linux-gnu \
+// RUN: --sysroot=%S/Inputs/fedora_39_tree --gcc-triple=x86_64-redhat-linux -v 
2>&1 | \

MaskRay wrote:

Indent continuation lines.

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,8 @@
+// UNSUPPORTED: system-windows
+//

MaskRay wrote:

Drop `^//$` lines. The conventional style doesn't add these markers for 
otherwise blank lines. Without them, we can navigate among the tests using 
vim-style `{` `}` .

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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-12-01 Thread Fangrui Song via cfe-commits

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


[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2023-12-01 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Can you add a little more details in the description on the root cause of the 
bug?

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


[clang] [Clang] Remove NetBSD/i386 workaround for FP eval method with older versions (PR #74025)

2023-12-01 Thread Brad Smith via cfe-commits

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


[clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-01 Thread Kees Cook via cfe-commits

kees wrote:

> ```
> int foo(struct s *p, int index) {
>   return __builtin_dynamic_object_size((++p)->array[index], 1);
> }
> ```
> 
> This _shouldn't_ increment `p`, but we need to get the array size of the 
> element _after_ `p`. I suspect that this is probably a horrible security 
> violation in the making, but we at least need to handle such an eventuality 
> gracefully. For a first pass, I think returning `-1` or `0` (depending on the 
> default return value) for _any_ pointer arithmetic is probably okay...maybe 
> even the best option?
> 
> @kees Thoughts?

Owch. That really shouldn't be legal: we can't have arrays of structs ending in 
a FAM, so the `++p` isn't sane. That said, I guess pointer arithmetic must 
follow `sizeof`, so `++p` isn't illegal; it's just awful. FWIW, GCC just 
returns `SIZE_MAX` for this sort of "aaah, where are you going?!" insanity for 
non-FAM structs. But Clang appears to just go along for the ride:
https://godbolt.org/z/Pss1oz7sW

So that needs to be fixed in Clang too.

But for doing a FAM struct like this ... my instinct is to say it should return 
0, much like requesting an out of bounds array index. (Rather than `SIZE_MAX`.)

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-12-01 Thread Tom Ritter via cfe-commits

tomrittervg wrote:

This sounds crazy, but I think I found a bug in this patchset.  I applied it on 
top of the 17.0.2 tag, and then ran the whole analysis on mozilla-central.  I 
got segfaults on about 4000 executions, all with the same stack trace:

```
1.   parser at end of file
2.  While analyzing stack: 
#0 Calling mozilla::FailureLatch::SetFailureFrom(const FailureLatch &) 
at line 
/home/tom/Documents/moz/static-analysis/mozilla-unified/objdir/dist/include/mozilla/BaseProfileJSONWriter.h:151:5
#1 Calling 
mozilla::baseprofiler::ChunkedJSONWriteFunc::ChangeFailureLatchAndForwardState(FailureLatch
 &) at line 
/home/tom/Documents/moz/static-analysis/mozilla-unified/objdir/dist/include/mozilla/BaseProfileJSONWriter.h:465:12
#2 Calling 
mozilla::baseprofiler::SpliceableChunkedJSONWriter::ChangeFailureLatchAndForwardState(FailureLatch
 &) at line 
/home/tom/Documents/moz/static-analysis/mozilla-unified/objdir/dist/include/mozilla/BaseProfileJSONWriter.h:570:5
#3 Calling 
mozilla::baseprofiler::UniqueJSONStrings::ChangeFailureLatchAndForwardState(FailureLatch
 &)
3.  
/home/tom/Documents/moz/static-analysis/mozilla-unified/objdir/dist/include/mozilla/FailureLatch.h:65:36:
 Error evaluating statement
4.  
/home/tom/Documents/moz/static-analysis/mozilla-unified/objdir/dist/include/mozilla/FailureLatch.h:65:36:
 Error evaluating statement
 #0 0x7f9378f09cb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libLLVM-17.so+0x2782cb8)
 #1 0x7f9378f09813 llvm::sys::CleanupOnSignal(unsigned long) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libLLVM-17.so+0x2782813)
 #2 0x7f9378ea11fe (anonymous 
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
CrashRecoveryContext.cpp:0:0
 #3 0x7f9378ea13ae CrashRecoverySignalHandler(int) 
CrashRecoveryContext.cpp:0:0
 #4 0x7f937626c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x7f937da6ed08 clang::ento::CXXInstanceCall::getRuntimeDefinition() 
const 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f09d08)
 #6 0x7f937da6f038 clang::ento::CXXMemberCall::getRuntimeDefinition() const 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f0a038)
 #7 0x7f937daa9796 
clang::ento::ExprEngine::defaultEvalCall(clang::ento::NodeBuilder&, 
clang::ento::ExplodedNode*, clang::ento::CallEvent const&, 
clang::ento::EvalCallOptions const&) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f44796)
 #8 0x7f937da776ea 
clang::ento::CheckerManager::runCheckersForEvalCall(clang::ento::ExplodedNodeSet&,
 clang::ento::ExplodedNodeSet const&, clang::ento::CallEvent const&, 
clang::ento::ExprEngine&, clang::ento::EvalCallOptions const&) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f126ea)
 #9 0x7f937daa7c64 
clang::ento::ExprEngine::evalCall(clang::ento::ExplodedNodeSet&, 
clang::ento::ExplodedNode*, clang::ento::CallEvent const&) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f42c64)
#10 0x7f937daa7a67 clang::ento::ExprEngine::VisitCallExpr(clang::CallExpr 
const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f42a67)
#11 0x7f937da8d503 clang::ento::ExprEngine::Visit(clang::Stmt const*, 
clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f28503)
#12 0x7f937da8abec clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, 
clang::ento::ExplodedNode*) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f25bec)
#13 0x7f937da8a9bd 
clang::ento::ExprEngine::processCFGElement(clang::CFGElement, 
clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f259bd)
#14 0x7f937da7bb7c clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock 
const*, unsigned int, clang::ento::ExplodedNode*) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f16b7c)
#15 0x7f937da7ae62 
clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, 
unsigned int, llvm::IntrusiveRefCntPtr) 
(/home/tom/Documents/moz/static-analysis/clang-17-2023-11-22-patches-from-tc/bin/../lib/libclang-cpp.so.17+0x2f15e62)
#16 0x7f937dcf3206 (anonymous 
namespace)::AnalysisConsumer::Han

[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

2023-12-01 Thread Fangrui Song via cfe-commits

MaskRay wrote:

At this point, it does seem that changing `addLTOOption` to accept `Inputs` 
instead of `Input` will eliminate duplication and ensure consistency among 
targets.

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


[llvm] [clang] Revert HWASAN failure (#74163) (PR #74180)

2023-12-01 Thread Kirill Stoimenov via cfe-commits

kstoimenov wrote:

I pushed it manually: b6d0ee056d247e1ecfd4ecd3f97fb2d31740d79b. 

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


[llvm] [clang] Revert HWASAN failure (#74163) (PR #74180)

2023-12-01 Thread Kirill Stoimenov via cfe-commits

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


[clang] b6d0ee0 - Revert HWASAN failure (#74163)

2023-12-01 Thread Kirill Stoimenov via cfe-commits

Author: Kirill Stoimenov
Date: 2023-12-02T04:39:14Z
New Revision: b6d0ee056d247e1ecfd4ecd3f97fb2d31740d79b

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

LOG: Revert HWASAN failure (#74163)

This is the failure:
https://lab.llvm.org/buildbot/#/builders/236/builds/7728/steps/10/logs/stdio

This started with eef8e1d206dc01c081a0ca29b7f9e0c39d33446e, but because
there were a couple of patches that came after that I had to revert all
3 of them because of merge conflicts.

Added: 


Modified: 
clang/test/Driver/aarch64-v95a.c
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64InstrFormats.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
llvm/lib/Target/AArch64/AArch64SchedA64FX.td
llvm/lib/Target/AArch64/AArch64SchedNeoverseN2.td
llvm/lib/Target/AArch64/AArch64SchedNeoverseV1.td
llvm/lib/Target/AArch64/AArch64SchedNeoverseV2.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/AArch64/SVEInstrFormats.td
llvm/test/MC/AArch64/basic-a64-diagnostics.s
llvm/test/MC/AArch64/basic-a64-instructions.s
llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 
llvm/test/MC/AArch64/SVE/armv9.5a-cpa.s
llvm/test/MC/AArch64/armv9.5a-cpa.s
llvm/test/MC/Disassembler/AArch64/armv9.5a-cpa.txt



diff  --git a/clang/test/Driver/aarch64-v95a.c 
b/clang/test/Driver/aarch64-v95a.c
index 366cade86a9fb71..6044a4f155db02c 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -13,8 +13,3 @@
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.5-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A-BE %s
 // GENERICV95A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9.5a"
 
-// = Features supported on aarch64 =
-
-// RUN: %clang -target aarch64 -march=armv9.5a+cpa -### -c %s 2>&1 | FileCheck 
-check-prefix=V95A-CPA %s
-// RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-CPA %s
-// V95A-CPA: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+cpa"

diff  --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 0711f013a377909..17cafd146b0e75d 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -173,7 +173,6 @@ enum ArchExtKind : unsigned {
   AEK_SMEF8F16 =  69, // FEAT_SME_F8F16
   AEK_SMEF8F32 =  70, // FEAT_SME_F8F32
   AEK_SMEFA64 =   71, // FEAT_SME_FA64
-  AEK_CPA =   72, // FEAT_CPA
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -296,7 +295,6 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-f8f16", AArch64::AEK_SMEF8F16, "+sme-f8f16", "-sme-f8f16", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-f8f32", AArch64::AEK_SMEF8F32, "+sme-f8f32", "-sme-f8f32", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
-{"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };
@@ -380,8 +378,7 @@ inline constexpr ArchInfo ARMV9_3A  = { VersionTuple{9, 3}, 
AProfile, "armv9.3-a
 
AArch64::ExtensionBitset({AArch64::AEK_MOPS, AArch64::AEK_HBC}))};
 inline constexpr ArchInfo ARMV9_4A  = { VersionTuple{9, 4}, AProfile, 
"armv9.4-a", "+v9.4a", (ARMV9_3A.DefaultExts |
 
AArch64::ExtensionBitset({AArch64::AEK_SPECRES2, AArch64::AEK_CSSC, 
AArch64::AEK_RASv2}))};
-inline constexpr ArchInfo ARMV9_5A  = { VersionTuple{9, 5}, AProfile, 
"armv9.5-a", "+v9.5a", (ARMV9_4A.DefaultExts |
-
AArch64::ExtensionBitset({AArch64::AEK_CPA}))};
+inline constexpr ArchInfo ARMV9_5A  = { VersionTuple{9, 5}, AProfile, 
"armv9.5-a", "+v9.5a", (ARMV9_4A.DefaultExts)};
 // For v8-R, we do not enable crypto and align with GCC that enables a more 
minimal set of optional architecture extensions.
 inline constexpr ArchInfo ARMV8R= { VersionTuple{8, 0}, RProfile, 
"armv8-r", "+v8r", (ARMV8_5A.DefaultExts |
 
AArch64::ExtensionBitset({AArch64::AEK_SSBS,

diff  --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index d1dbced2466eae3..ff256c9a8ccdf46 100644
--- a/llvm/lib/Target/AArch64/

[llvm] [clang] Revert HWASAN failure (#74163) (PR #74180)

2023-12-01 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 28eead018d80a5384b8be6f259c3d2e2b849e8cf 
ef876c72f3d828055ce58d0f22ec40c7468bc6c1 -- clang/test/Driver/aarch64-v95a.c 
llvm/include/llvm/TargetParser/AArch64TargetParser.h 
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp 
llvm/unittests/TargetParser/TargetParserTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp 
b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index fbe1bf3c52..77963f895d 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -3663,7 +3663,7 @@ static const struct Extension {
 {"sme-lutv2", {AArch64::FeatureSME_LUTv2}},
 {"sme-f8f16", {AArch64::FeatureSMEF8F16}},
 {"sme-f8f32", {AArch64::FeatureSMEF8F32}},
-{"sme-fa64",  {AArch64::FeatureSMEFA64}},
+{"sme-fa64", {AArch64::FeatureSMEFA64}},
 };
 
 static void setRequiredFeatureString(FeatureBitset FBS, std::string &Str) {

``




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


[llvm] [clang] Revert HWASAN failure (#74163) (PR #74180)

2023-12-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kirill Stoimenov (kstoimenov)


Changes

This is the failure:
https://lab.llvm.org/buildbot/#/builders/236/builds/7728/steps/10/logs/stdio

This started with eef8e1d206dc01c081a0ca29b7f9e0c39d33446e, but because there 
were a couple of patches that came after that I had to revert all 3 of them 
because of merge conflicts.

---

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


19 Files Affected:

- (modified) clang/test/Driver/aarch64-v95a.c (-5) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+1-4) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+1-4) 
- (modified) llvm/lib/Target/AArch64/AArch64InstrFormats.td (-52) 
- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.td (-19) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (-21) 
- (modified) llvm/lib/Target/AArch64/AArch64SchedA64FX.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64SchedNeoverseN2.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64SchedNeoverseV1.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64SchedNeoverseV2.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (-18) 
- (modified) llvm/lib/Target/AArch64/SVEInstrFormats.td (-31) 
- (removed) llvm/test/MC/AArch64/SVE/armv9.5a-cpa.s (-69) 
- (removed) llvm/test/MC/AArch64/armv9.5a-cpa.s (-50) 
- (modified) llvm/test/MC/AArch64/basic-a64-diagnostics.s (-8) 
- (modified) llvm/test/MC/AArch64/basic-a64-instructions.s (-4) 
- (removed) llvm/test/MC/Disassembler/AArch64/armv9.5a-cpa.txt (-42) 
- (modified) llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt (-2) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+1-3) 


``diff
diff --git a/clang/test/Driver/aarch64-v95a.c b/clang/test/Driver/aarch64-v95a.c
index 366cade86a9fb71..6044a4f155db02c 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -13,8 +13,3 @@
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.5-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A-BE %s
 // GENERICV95A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9.5a"
 
-// = Features supported on aarch64 =
-
-// RUN: %clang -target aarch64 -march=armv9.5a+cpa -### -c %s 2>&1 | FileCheck 
-check-prefix=V95A-CPA %s
-// RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-CPA %s
-// V95A-CPA: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+cpa"
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 0711f013a377909..17cafd146b0e75d 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -173,7 +173,6 @@ enum ArchExtKind : unsigned {
   AEK_SMEF8F16 =  69, // FEAT_SME_F8F16
   AEK_SMEF8F32 =  70, // FEAT_SME_F8F32
   AEK_SMEFA64 =   71, // FEAT_SME_FA64
-  AEK_CPA =   72, // FEAT_CPA
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -296,7 +295,6 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-f8f16", AArch64::AEK_SMEF8F16, "+sme-f8f16", "-sme-f8f16", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-f8f32", AArch64::AEK_SMEF8F32, "+sme-f8f32", "-sme-f8f32", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
-{"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };
@@ -380,8 +378,7 @@ inline constexpr ArchInfo ARMV9_3A  = { VersionTuple{9, 3}, 
AProfile, "armv9.3-a
 
AArch64::ExtensionBitset({AArch64::AEK_MOPS, AArch64::AEK_HBC}))};
 inline constexpr ArchInfo ARMV9_4A  = { VersionTuple{9, 4}, AProfile, 
"armv9.4-a", "+v9.4a", (ARMV9_3A.DefaultExts |
 
AArch64::ExtensionBitset({AArch64::AEK_SPECRES2, AArch64::AEK_CSSC, 
AArch64::AEK_RASv2}))};
-inline constexpr ArchInfo ARMV9_5A  = { VersionTuple{9, 5}, AProfile, 
"armv9.5-a", "+v9.5a", (ARMV9_4A.DefaultExts |
-
AArch64::ExtensionBitset({AArch64::AEK_CPA}))};
+inline constexpr ArchInfo ARMV9_5A  = { VersionTuple{9, 5}, AProfile, 
"armv9.5-a", "+v9.5a", (ARMV9_4A.DefaultExts)};
 // For v8-R, we do not enable crypto and align with GCC that enables a more 
minimal set of optional architecture extensions.
 inline constexpr ArchInfo ARMV8R= { VersionTuple{8, 0}, RProfile, 
"armv8-r", "+v8r", (ARMV8_5A.DefaultExts |
 
AArch64::ExtensionBitset({AArch64::AEK_SSBS,
diff --git a/llvm/lib/Target/AArch64/AArch64.td 
b

[llvm] [clang] Revert HWASAN failure (#74163) (PR #74180)

2023-12-01 Thread Kirill Stoimenov via cfe-commits

https://github.com/kstoimenov created 
https://github.com/llvm/llvm-project/pull/74180

This is the failure:
https://lab.llvm.org/buildbot/#/builders/236/builds/7728/steps/10/logs/stdio

This started with eef8e1d206dc01c081a0ca29b7f9e0c39d33446e, but because there 
were a couple of patches that came after that I had to revert all 3 of them 
because of merge conflicts.

>From ef876c72f3d828055ce58d0f22ec40c7468bc6c1 Mon Sep 17 00:00:00 2001
From: Kirill Stoimenov <87100199+kstoime...@users.noreply.github.com>
Date: Fri, 1 Dec 2023 19:26:46 -0800
Subject: [PATCH] Revert HWASAN failure (#74163)

This is the failure:
https://lab.llvm.org/buildbot/#/builders/236/builds/7728/steps/10/logs/stdio

This started with eef8e1d206dc01c081a0ca29b7f9e0c39d33446e, but because
there were a couple of patches that came after that I had to revert all
3 of them because of merge conflicts.
---
 clang/test/Driver/aarch64-v95a.c  |  5 --
 .../llvm/TargetParser/AArch64TargetParser.h   |  5 +-
 llvm/lib/Target/AArch64/AArch64.td|  5 +-
 .../lib/Target/AArch64/AArch64InstrFormats.td | 52 --
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   | 19 -
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td | 21 --
 llvm/lib/Target/AArch64/AArch64SchedA64FX.td  |  2 +-
 .../Target/AArch64/AArch64SchedNeoverseN2.td  |  2 +-
 .../Target/AArch64/AArch64SchedNeoverseV1.td  |  2 +-
 .../Target/AArch64/AArch64SchedNeoverseV2.td  |  2 +-
 .../AArch64/AsmParser/AArch64AsmParser.cpp| 18 -
 llvm/lib/Target/AArch64/SVEInstrFormats.td| 31 -
 llvm/test/MC/AArch64/SVE/armv9.5a-cpa.s   | 69 ---
 llvm/test/MC/AArch64/armv9.5a-cpa.s   | 50 --
 llvm/test/MC/AArch64/basic-a64-diagnostics.s  |  8 ---
 llvm/test/MC/AArch64/basic-a64-instructions.s |  4 --
 .../MC/Disassembler/AArch64/armv9.5a-cpa.txt  | 42 ---
 .../AArch64/basic-a64-instructions.txt|  2 -
 .../TargetParser/TargetParserTest.cpp |  4 +-
 19 files changed, 7 insertions(+), 336 deletions(-)
 delete mode 100644 llvm/test/MC/AArch64/SVE/armv9.5a-cpa.s
 delete mode 100644 llvm/test/MC/AArch64/armv9.5a-cpa.s
 delete mode 100644 llvm/test/MC/Disassembler/AArch64/armv9.5a-cpa.txt

diff --git a/clang/test/Driver/aarch64-v95a.c b/clang/test/Driver/aarch64-v95a.c
index 366cade86a9fb71..6044a4f155db02c 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -13,8 +13,3 @@
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.5-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A-BE %s
 // GENERICV95A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9.5a"
 
-// = Features supported on aarch64 =
-
-// RUN: %clang -target aarch64 -march=armv9.5a+cpa -### -c %s 2>&1 | FileCheck 
-check-prefix=V95A-CPA %s
-// RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-CPA %s
-// V95A-CPA: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+cpa"
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 0711f013a377909..17cafd146b0e75d 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -173,7 +173,6 @@ enum ArchExtKind : unsigned {
   AEK_SMEF8F16 =  69, // FEAT_SME_F8F16
   AEK_SMEF8F32 =  70, // FEAT_SME_F8F32
   AEK_SMEFA64 =   71, // FEAT_SME_FA64
-  AEK_CPA =   72, // FEAT_CPA
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -296,7 +295,6 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-f8f16", AArch64::AEK_SMEF8F16, "+sme-f8f16", "-sme-f8f16", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-f8f32", AArch64::AEK_SMEF8F32, "+sme-f8f32", "-sme-f8f32", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
-{"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };
@@ -380,8 +378,7 @@ inline constexpr ArchInfo ARMV9_3A  = { VersionTuple{9, 3}, 
AProfile, "armv9.3-a
 
AArch64::ExtensionBitset({AArch64::AEK_MOPS, AArch64::AEK_HBC}))};
 inline constexpr ArchInfo ARMV9_4A  = { VersionTuple{9, 4}, AProfile, 
"armv9.4-a", "+v9.4a", (ARMV9_3A.DefaultExts |
 
AArch64::ExtensionBitset({AArch64::AEK_SPECRES2, AArch64::AEK_CSSC, 
AArch64::AEK_RASv2}))};
-inline constexpr ArchInfo ARMV9_5A  = { VersionTuple{9, 5}, AProfile, 
"armv9.5-a", "+v9.5a", (ARMV9_4A.DefaultExts |
-
AArch64::ExtensionBitset({AArch64::AEK_CPA}))};
+inline constexpr ArchInfo ARMV9_5A  = { VersionTuple{9, 5}, AProfile,

[clang] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC) (PR #74179)

2023-12-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Youngsuk Kim (JOE1994)


Changes

Remove ptr-to-ptr bitcast which was added back in 
939352b6ec31db4e8defe07856868438fbc5340d . With opaque pointers, the bitcast is 
now redundant.

Opaque ptr cleanup effort.

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


1 Files Affected:

- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (-3) 


``diff
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index cf731e8414a3b83..1fb41805a0473dd 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -180,13 +180,10 @@ void emitCodeGenSwitchBody(const RVVIntrinsic *RVVI, 
raw_ostream &OS) {
 return;
   }
 
-  // Cast pointer operand of vector load intrinsic.
   for (const auto &I : enumerate(RVVI->getInputTypes())) {
 if (I.value()->isPointer()) {
   assert(RVVI->getIntrinsicTypes().front() == -1 &&
  "RVVI should be vector load intrinsic.");
-  OS << "  Ops[" << I.index() << "] = Builder.CreateBitCast(Ops[";
-  OS << I.index() << "], ResultType->getPointerTo());\n";
 }
   }
 

``




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


[clang] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC) (PR #74179)

2023-12-01 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/74179

Remove ptr-to-ptr bitcast which was added back in 
939352b6ec31db4e8defe07856868438fbc5340d . With opaque pointers, the bitcast is 
now redundant.

Opaque ptr cleanup effort.

>From 56eb182b28277cc6160e6916d98a02b1ee12fadb Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 1 Dec 2023 21:59:59 -0600
Subject: [PATCH] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC)

Remove ptr-to-ptr bitcast which was added back in 
939352b6ec31db4e8defe07856868438fbc5340d .
With opaque pointers, the bitcast is now redundant.

Opaque ptr cleanup effort.
---
 clang/utils/TableGen/RISCVVEmitter.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index cf731e8414a3b83..1fb41805a0473dd 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -180,13 +180,10 @@ void emitCodeGenSwitchBody(const RVVIntrinsic *RVVI, 
raw_ostream &OS) {
 return;
   }
 
-  // Cast pointer operand of vector load intrinsic.
   for (const auto &I : enumerate(RVVI->getInputTypes())) {
 if (I.value()->isPointer()) {
   assert(RVVI->getIntrinsicTypes().front() == -1 &&
  "RVVI should be vector load intrinsic.");
-  OS << "  Ops[" << I.index() << "] = Builder.CreateBitCast(Ops[";
-  OS << I.index() << "], ResultType->getPointerTo());\n";
 }
   }
 

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


[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

2023-12-01 Thread Brad Smith via cfe-commits

brad0 wrote:

@MaskRay

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


[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

2023-12-01 Thread Brad Smith via cfe-commits

brad0 wrote:

> Why couldn't you have put this logic in `addLTOOptions`? Seems like it's 
> copy-pasted verbatim at every site now.
> 
> AMD should handle very similarly to Linux here. They both compile down to 
> LLVM-IR and get sent to `ld.lld`.

It's not my area, but I was thinking that would make more sense. I am just 
trying to ensure consistency with the various targets.

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


[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

2023-12-01 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 commented:

Why couldn't you have put this logic in `addLTOOptions`? Seems like it's 
copy-pasted verbatim at every site now.

AMD should handle very similarly to Linux here. They both compile down to 
LLVM-IR and get sent to `ld.lld`.

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2023-12-01 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

ping ..

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


[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

2023-12-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Brad Smith (brad0)


Changes

Copying 
https://github.com/llvm/llvm-project/commit/1881832994840baa6e42f908b8822ce4d15ab632
 to the last of the targets that use LTO.

But I am not sure about tests for these targets, especially the AMD toolchains.

Could the respective AMD and MinGW commiters please help here?

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


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+12-3) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+9-1) 
- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+9-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index cad206ea4df1bc5..3776d3bbac811b9 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -611,10 +611,19 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
-  if (C.getDriver().isUsingLTO())
-addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
+  if (C.getDriver().isUsingLTO()) {
+assert(!Inputs.empty() && "Must have at least one input.");
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(getToolChain(), Args, CmdArgs, Output, *Input,
   C.getDriver().getLTOMode() == LTOK_Thin);
-  else if (Args.hasArg(options::OPT_mcpu_EQ))
+  } else if (Args.hasArg(options::OPT_mcpu_EQ))
 CmdArgs.push_back(Args.MakeArgString(
 "-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
   CmdArgs.push_back("-o");
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index ccb36a6c846c806..24f3db9001e1dd6 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -119,8 +119,16 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, 
const JobAction &JA,
   auto &TC = getToolChain();
   auto &D = TC.getDriver();
   assert(!Inputs.empty() && "Must have at least one input.");
+  // Find the first filename InputInfo object.
+  auto Input = llvm::find_if(
+  Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+  if (Input == Inputs.end())
+// For a very rare case, all of the inputs to the linker are
+// InputArg. If that happens, just use the first InputInfo.
+Input = Inputs.begin();
+
   bool IsThinLTO = D.getLTOMode(/*IsOffload=*/true) == LTOK_Thin;
-  addLTOOptions(TC, Args, LldArgs, Output, Inputs[0], IsThinLTO);
+  addLTOOptions(TC, Args, LldArgs, Output, *Input, IsThinLTO);
 
   // Extract all the -m options
   std::vector Features;
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5d7f8675daf8d28..066566eb02e4983 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -243,7 +243,15 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(TC, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(TC, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

``




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


[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

2023-12-01 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/74178

Copying 
https://github.com/llvm/llvm-project/commit/1881832994840baa6e42f908b8822ce4d15ab632
 to the last of the targets that use LTO.

But I am not sure about tests for these targets, especially the AMD toolchains.

Could the respective AMD and MinGW commiters please help here?

>From e475c3e4c3fdcb3fa869279ec65a2cf866b7d48e Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 11 Nov 2023 20:02:40 -0500
Subject: [PATCH] [Driver][LTO] Copy fix empty stats filename to AMDGPU,
 HIPAMD, MinGW

---
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 15 ---
 clang/lib/Driver/ToolChains/HIPAMD.cpp | 10 +-
 clang/lib/Driver/ToolChains/MinGW.cpp  | 10 +-
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index cad206ea4df1bc5..3776d3bbac811b9 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -611,10 +611,19 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
-  if (C.getDriver().isUsingLTO())
-addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
+  if (C.getDriver().isUsingLTO()) {
+assert(!Inputs.empty() && "Must have at least one input.");
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(getToolChain(), Args, CmdArgs, Output, *Input,
   C.getDriver().getLTOMode() == LTOK_Thin);
-  else if (Args.hasArg(options::OPT_mcpu_EQ))
+  } else if (Args.hasArg(options::OPT_mcpu_EQ))
 CmdArgs.push_back(Args.MakeArgString(
 "-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
   CmdArgs.push_back("-o");
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index ccb36a6c846c806..24f3db9001e1dd6 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -119,8 +119,16 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, 
const JobAction &JA,
   auto &TC = getToolChain();
   auto &D = TC.getDriver();
   assert(!Inputs.empty() && "Must have at least one input.");
+  // Find the first filename InputInfo object.
+  auto Input = llvm::find_if(
+  Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+  if (Input == Inputs.end())
+// For a very rare case, all of the inputs to the linker are
+// InputArg. If that happens, just use the first InputInfo.
+Input = Inputs.begin();
+
   bool IsThinLTO = D.getLTOMode(/*IsOffload=*/true) == LTOK_Thin;
-  addLTOOptions(TC, Args, LldArgs, Output, Inputs[0], IsThinLTO);
+  addLTOOptions(TC, Args, LldArgs, Output, *Input, IsThinLTO);
 
   // Extract all the -m options
   std::vector Features;
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5d7f8675daf8d28..066566eb02e4983 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -243,7 +243,15 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(TC, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(TC, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

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


[clang] [clang-format] Fix a bug in `git-clang-format --binary` (PR #74176)

2023-12-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixed #74165.

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


1 Files Affected:

- (modified) clang/tools/clang-format/git-clang-format (+1) 


``diff
diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 0f33b5339ec14cb..6e827e17b4ee291 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -153,6 +153,7 @@ def main():
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
+  opts.binary=os.path.abspath(opts.binary)
   changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)

``




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


[clang] [clang-format] Fix a bug in `git-clang-format --binary` (PR #74176)

2023-12-01 Thread Owen Pan via cfe-commits

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

Fixed #74165.

>From 462a93a59b236fd6f6750ed69c8629db12cd32a9 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 1 Dec 2023 18:31:05 -0800
Subject: [PATCH] [clang-format] Fix a bug in `git-clang-format --binary`

Fixed #74165.
---
 clang/tools/clang-format/git-clang-format | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 0f33b5339ec14cb..6e827e17b4ee291 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -153,6 +153,7 @@ def main():
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
+  opts.binary=os.path.abspath(opts.binary)
   changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)

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


[flang] [clang-tools-extra] [llvm] [libcxx] [libc] [lld] [lldb] [clang] [compiler-rt] [mlir] [libunwind] Fix clang to recognize new C23 modifiers %w and %wf when printing and scanning (PR #71771)

2023-12-01 Thread via cfe-commits

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


[flang] [clang-tools-extra] [llvm] [libcxx] [libc] [lld] [lldb] [clang] [compiler-rt] [mlir] [libunwind] Fix clang to recognize new C23 modifiers %w and %wf when printing (PR #71771)

2023-12-01 Thread via cfe-commits

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

>From 06c4cf02dfb4b20c8349c5f3c7209276f6d56edf Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 9 Nov 2023 02:21:46 +
Subject: [PATCH 1/4] Fix clang to recognize new C23 modifiers %w and %wf when
 printing

---
 clang/include/clang/AST/FormatString.h | 16 +++-
 clang/lib/AST/FormatString.cpp | 52 +-
 clang/lib/AST/PrintfFormatString.cpp   | 19 ++
 clang/test/Sema/format-strings-ms.c| 28 ++
 4 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef608c..6a886854650f1d9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -81,8 +81,10 @@ class LengthModifier {
 AsLongDouble, // 'L'
 AsAllocate,   // for '%as', GNU extension to C90 scanf
 AsMAllocate,  // for '%ms', GNU extension to scanf
-AsWide,   // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
-AsWideChar = AsLong // for '%ls', only makes sense for printf
+AsWide,   // 'w' (1. MSVCRT, like l but only for c, C, s, S, or Z on 
windows
+  // 2. for b, d, i, o, u, x, or X when a size followed(like 
8, 16, 32 or 64)
+AsWideFast,   // 'wf' (for b, d, i, o, u, x, or X)
+AsWideChar = AsLong, // for '%ls', only makes sense for printf
   };
 
   LengthModifier()
@@ -417,6 +419,7 @@ class FormatSpecifier {
   ///  http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
   bool UsesPositionalArg;
   unsigned argIndex;
+  unsigned size;
 public:
   FormatSpecifier(bool isPrintf)
 : CS(isPrintf), VectorNumElts(false),
@@ -460,6 +463,15 @@ class FormatSpecifier {
 FieldWidth = Amt;
   }
 
+  void setSize(unsigned s) {
+size = s;
+  }
+
+  unsigned getSize() const {
+return size;
+  }
+
+
   bool usesPositionalArg() const { return UsesPositionalArg; }
 
   bool hasValidLengthModifier(const TargetInfo &Target,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a243..ebc136e780717e4 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -286,7 +286,33 @@ 
clang::analyze_format_string::ParseLengthModifier(FormatSpecifier &FS,
   lmKind = LengthModifier::AsInt3264;
   break;
 case 'w':
-  lmKind = LengthModifier::AsWide; ++I; break;
+  ++I;
+  if (I == E) return false;
+  if (*I == 'f') {
+lmKind = LengthModifier::AsWideFast;
+++I;
+  } else {
+lmKind = LengthModifier::AsWide;
+  }
+
+  if (I == E) return false;
+  int s = 0;
+  while (unsigned(*I - '0') <= 9) {
+s = 10 * s + unsigned(*I - '0');
+++I;
+  }
+
+  // s == 0 is MSVCRT case, like l but only for c, C, s, S, or Z on windows
+  // s != 0 for b, d, i, o, u, x, or X when a size followed(like 8, 16, 32 
or 64)
+  if (s != 0) {
+std::set supported_list {8, 16, 32, 64};
+if (supported_list.count(s) == 0) {
+  return false;
+}
+FS.setSize(s);
+  }
+
+  break;
   }
   LengthModifier lm(lmPosition, lmKind);
   FS.setLengthModifier(lm);
@@ -703,6 +729,8 @@ analyze_format_string::LengthModifier::toString() const {
 return "m";
   case AsWide:
 return "w";
+  case AsWideFast:
+return "wf";
   case None:
 return "";
   }
@@ -970,6 +998,27 @@ bool FormatSpecifier::hasValidLengthModifier(const 
TargetInfo &Target,
 case ConversionSpecifier::SArg:
 case ConversionSpecifier::ZArg:
   return Target.getTriple().isOSMSVCRT();
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::dArg:
+case ConversionSpecifier::iArg:
+case ConversionSpecifier::oArg:
+case ConversionSpecifier::uArg:
+case ConversionSpecifier::xArg:
+case ConversionSpecifier::XArg:
+  return true;
+default:
+  return false;
+  }
+case LengthModifier::AsWideFast:
+  switch (CS.getKind()) {
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::dArg:
+case ConversionSpecifier::iArg:
+case ConversionSpecifier::oArg:
+case ConversionSpecifier::uArg:
+case ConversionSpecifier::xArg:
+case ConversionSpecifier::XArg:
+  return true;
 default:
   return false;
   }
@@ -996,6 +1045,7 @@ bool FormatSpecifier::hasStandardLengthModifier() const {
 case LengthModifier::AsInt3264:
 case LengthModifier::AsInt64:
 case LengthModifier::AsWide:
+case LengthModifier::AsWideFast:
 case LengthModifier::AsShortLong: // ???
   return false;
   }
diff --git a/clang/lib/AST/PrintfFormatString.cpp 
b/clang/lib/AST/PrintfFormatString.cpp
index f0b9d0ecaf23461..4b9111e8bcf509a 100644
--- a/clang/lib/AST/PrintfFormatString.cpp
+++ b/clang/l

[clang] c45a66e - [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-12-01 Thread Owen Pan via cfe-commits

Author: Jared Grubb
Date: 2023-12-01T17:41:30-08:00
New Revision: c45a66ecd4cb8f351298ca987d6086cf02b77bfb

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

LOG: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

Add a style option to specify the order that property attributes should
appear in ObjC property declarations (property attributes are things like
`nonatomic, strong, nullable`).

Closes #71323.

Differential Revision: https://reviews.llvm.org/D150083

Added: 
clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
clang/lib/Format/ObjCPropertyAttributeOrderFixer.h
clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp

Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/CMakeLists.txt
clang/lib/Format/Format.cpp
clang/unittests/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 37d76d5c2dd58c0..3d42571e82d8a07 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4211,6 +4211,32 @@ the configuration (without a prefix: ``Auto``).
  }]
  }
 
+.. _ObjCPropertyAttributeOrder:
+
+**ObjCPropertyAttributeOrder** (``List of Strings``) 
:versionbadge:`clang-format 18` :ref:`¶ `
+  The order in which ObjC property attributes should appear.
+
+  Attributes in code will be sorted in the order specified. Any attributes
+  encountered that are not mentioned in this array will be sorted last, in
+  stable order. Comments between attributes will leave the attributes
+  untouched.
+
+  .. warning::
+
+   Using this option could lead to incorrect code formatting due to
+   clang-format's lack of complete semantic information. As such, extra
+   care should be taken to review code changes made by this option.
+
+  .. code-block:: yaml
+
+ObjCPropertyAttributeOrder: [
+class, direct,
+atomic, nonatomic,
+assign, retain, strong, copy, weak, unsafe_unretained,
+readonly, readwrite, getter, setter,
+nullable, nonnull, null_resettable, null_unspecified
+]
+
 .. _ObjCSpaceAfterProperty:
 
 **ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8733bb93f5708ae..06796780f3224a7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -984,6 +984,8 @@ clang-format
 - Add ``AllowShortCompoundRequirementOnASingleLine`` option.
 - Change ``BreakAfterAttributes`` from ``Never`` to ``Leave`` in LLVM style.
 - Add ``BreakAdjacentStringLiterals`` option.
+- Add ``ObjCPropertyAttributeOrder`` which can be used to sort ObjC property
+  attributes (like ``nonatomic, strong, nullable``).
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fbcc4ef0705b6a..8604dea689f9371 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3264,6 +3264,29 @@ struct FormatStyle {
   /// \version 11
   bool ObjCBreakBeforeNestedBlockParam;
 
+  /// The order in which ObjC property attributes should appear.
+  ///
+  /// Attributes in code will be sorted in the order specified. Any attributes
+  /// encountered that are not mentioned in this array will be sorted last, in
+  /// stable order. Comments between attributes will leave the attributes
+  /// untouched.
+  /// \warning
+  ///  Using this option could lead to incorrect code formatting due to
+  ///  clang-format's lack of complete semantic information. As such, extra
+  ///  care should be taken to review code changes made by this option.
+  /// \endwarning
+  /// \code{.yaml}
+  ///   ObjCPropertyAttributeOrder: [
+  ///   class, direct,
+  ///   atomic, nonatomic,
+  ///   assign, retain, strong, copy, weak, unsafe_unretained,
+  ///   readonly, readwrite, getter, setter,
+  ///   nullable, nonnull, null_resettable, null_unspecified
+  ///   ]
+  /// \endcode
+  /// \version 18
+  std::vector ObjCPropertyAttributeOrder;
+
   /// Add a space after ``@property`` in Objective-C, i.e. use
   /// ``@property (readonly)`` instead of ``@property(readonly)``.
   /// \version 3.7
@@ -4821,6 +4844,7 @@ struct FormatStyle {
ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
ObjCBreakBeforeNestedBlockParam ==
R.ObjCBreakBeforeNestedBlockParam &&
+   ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
 

[flang] [clang-tools-extra] [llvm] [libcxx] [libc] [lld] [lldb] [clang] [compiler-rt] [mlir] [libunwind] Fix clang to recognize new C23 modifiers %w and %wf when printing (PR #71771)

2023-12-01 Thread via cfe-commits

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

>From 06c4cf02dfb4b20c8349c5f3c7209276f6d56edf Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 9 Nov 2023 02:21:46 +
Subject: [PATCH 1/3] Fix clang to recognize new C23 modifiers %w and %wf when
 printing

---
 clang/include/clang/AST/FormatString.h | 16 +++-
 clang/lib/AST/FormatString.cpp | 52 +-
 clang/lib/AST/PrintfFormatString.cpp   | 19 ++
 clang/test/Sema/format-strings-ms.c| 28 ++
 4 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef608c..6a886854650f1d9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -81,8 +81,10 @@ class LengthModifier {
 AsLongDouble, // 'L'
 AsAllocate,   // for '%as', GNU extension to C90 scanf
 AsMAllocate,  // for '%ms', GNU extension to scanf
-AsWide,   // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
-AsWideChar = AsLong // for '%ls', only makes sense for printf
+AsWide,   // 'w' (1. MSVCRT, like l but only for c, C, s, S, or Z on 
windows
+  // 2. for b, d, i, o, u, x, or X when a size followed(like 
8, 16, 32 or 64)
+AsWideFast,   // 'wf' (for b, d, i, o, u, x, or X)
+AsWideChar = AsLong, // for '%ls', only makes sense for printf
   };
 
   LengthModifier()
@@ -417,6 +419,7 @@ class FormatSpecifier {
   ///  http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
   bool UsesPositionalArg;
   unsigned argIndex;
+  unsigned size;
 public:
   FormatSpecifier(bool isPrintf)
 : CS(isPrintf), VectorNumElts(false),
@@ -460,6 +463,15 @@ class FormatSpecifier {
 FieldWidth = Amt;
   }
 
+  void setSize(unsigned s) {
+size = s;
+  }
+
+  unsigned getSize() const {
+return size;
+  }
+
+
   bool usesPositionalArg() const { return UsesPositionalArg; }
 
   bool hasValidLengthModifier(const TargetInfo &Target,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a243..ebc136e780717e4 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -286,7 +286,33 @@ 
clang::analyze_format_string::ParseLengthModifier(FormatSpecifier &FS,
   lmKind = LengthModifier::AsInt3264;
   break;
 case 'w':
-  lmKind = LengthModifier::AsWide; ++I; break;
+  ++I;
+  if (I == E) return false;
+  if (*I == 'f') {
+lmKind = LengthModifier::AsWideFast;
+++I;
+  } else {
+lmKind = LengthModifier::AsWide;
+  }
+
+  if (I == E) return false;
+  int s = 0;
+  while (unsigned(*I - '0') <= 9) {
+s = 10 * s + unsigned(*I - '0');
+++I;
+  }
+
+  // s == 0 is MSVCRT case, like l but only for c, C, s, S, or Z on windows
+  // s != 0 for b, d, i, o, u, x, or X when a size followed(like 8, 16, 32 
or 64)
+  if (s != 0) {
+std::set supported_list {8, 16, 32, 64};
+if (supported_list.count(s) == 0) {
+  return false;
+}
+FS.setSize(s);
+  }
+
+  break;
   }
   LengthModifier lm(lmPosition, lmKind);
   FS.setLengthModifier(lm);
@@ -703,6 +729,8 @@ analyze_format_string::LengthModifier::toString() const {
 return "m";
   case AsWide:
 return "w";
+  case AsWideFast:
+return "wf";
   case None:
 return "";
   }
@@ -970,6 +998,27 @@ bool FormatSpecifier::hasValidLengthModifier(const 
TargetInfo &Target,
 case ConversionSpecifier::SArg:
 case ConversionSpecifier::ZArg:
   return Target.getTriple().isOSMSVCRT();
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::dArg:
+case ConversionSpecifier::iArg:
+case ConversionSpecifier::oArg:
+case ConversionSpecifier::uArg:
+case ConversionSpecifier::xArg:
+case ConversionSpecifier::XArg:
+  return true;
+default:
+  return false;
+  }
+case LengthModifier::AsWideFast:
+  switch (CS.getKind()) {
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::dArg:
+case ConversionSpecifier::iArg:
+case ConversionSpecifier::oArg:
+case ConversionSpecifier::uArg:
+case ConversionSpecifier::xArg:
+case ConversionSpecifier::XArg:
+  return true;
 default:
   return false;
   }
@@ -996,6 +1045,7 @@ bool FormatSpecifier::hasStandardLengthModifier() const {
 case LengthModifier::AsInt3264:
 case LengthModifier::AsInt64:
 case LengthModifier::AsWide:
+case LengthModifier::AsWideFast:
 case LengthModifier::AsShortLong: // ???
   return false;
   }
diff --git a/clang/lib/AST/PrintfFormatString.cpp 
b/clang/lib/AST/PrintfFormatString.cpp
index f0b9d0ecaf23461..4b9111e8bcf509a 100644
--- a/clang/lib/AST/PrintfFormatString.cpp
+++ b/clang/l

[flang] [clang-tools-extra] [llvm] [libcxx] [libc] [lld] [lldb] [clang] [compiler-rt] [libunwind] Fix clang to recognize new C23 modifiers %w and %wf when printing (PR #71771)

2023-12-01 Thread Matthias Springer via cfe-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/71771

Sorry, this diff is unavailable.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-01 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

My CI detected some significant regressions caused by this patch:
https://github.com/dtcxzyw/llvm-ci/pull/839#issuecomment-1836976355

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


[llvm] [clang] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-01 Thread Mingming Liu via cfe-commits


@@ -300,12 +316,8 @@ getIRPGONameForGlobalObject(const GlobalObject &GO,
 GlobalValue::LinkageTypes Linkage,
 StringRef FileName) {
   SmallString<64> Name;
-  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
-Name.append(FileName.empty() ? "" : FileName);
-Name.append(";");
-  }
   Mangler().getNameWithPrefix(Name, &GO, /*CannotUsePrivateLabel=*/true);

minglotus-6 wrote:

>I think we can only generate the linkage name at compile time because we need 
>to know the linkage, which llvm-profdata doesn't have.

Yep, but my original question is more about why using linkage-name in 
IRPGOFuncName (early in the pipeline) rather than storing it at a later phase 
of the pipeline. I read the code and 
[rfc](https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068)
 again to make sense of why 'linkage-name' is needed in IRPGOFunc names.

> Was PGO broken in general before D156569? Or is this specific to 
> -symbol-ordering-file and -order_file?
> It wasn't broken in general, but it's needed to get -order_file working 
> correctly.

My understanding is that the specific data flow requires linkage-name to be 
stored in raw profiles. `llvm-profdata order` takes a profile and generates an 
order file (https://llvm.org/docs/CommandGuide/llvm-profdata.html#order); this 
file is used by `-symbol-ordering-file` directly.  Correct me if I miss 
anything.

A similar ELF option to `symbol-ordering-file` is 
[call-graph-ordering](https://github.com/llvm/llvm-project/blob/005c83380a907becbf5a6b4522fc43652c9536cd/lld/ELF/Driver.cpp#L1675-L1676),
 but with a different data flow. At a very high level, the edge ( is passed in ELF sections, where linkage-name is already used.

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


[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-01 Thread Yingwei Zheng via cfe-commits

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

The implementation looks good to me. Waiting for the result of my CI.
https://github.com/dtcxzyw/llvm-ci/actions/runs/7066692655

@goldsteinn Any comments?


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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Juergen Ributzka via cfe-commits


@@ -4770,9 +4770,20 @@ std::string CompilerInvocation::getModuleHash() const {
 
   // When compiling with -gmodules, also hash -fdebug-prefix-map as it
   // affects the debug info in the PCM.
-  if (getCodeGenOpts().DebugTypeExtRefs)
+  if (getHeaderSearchOpts().ModuleFormat == "obj") {

ributzka wrote:

CC: @adrian-prantl to confirm my understanding

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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Jan Svoboda via cfe-commits


@@ -4770,9 +4770,20 @@ std::string CompilerInvocation::getModuleHash() const {
 
   // When compiling with -gmodules, also hash -fdebug-prefix-map as it
   // affects the debug info in the PCM.
-  if (getCodeGenOpts().DebugTypeExtRefs)
+  if (getHeaderSearchOpts().ModuleFormat == "obj") {

jansvoboda11 wrote:

Could we extract this into a separate patch then? Seems like this change is 
mostly orthogonal to option pruning and could be done in a prep patch.

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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Jan Svoboda via cfe-commits


@@ -515,6 +430,8 @@ ENUM_CODEGENOPT(ZeroCallUsedRegs, 
llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
 /// non-deleting destructors. (No effect on Microsoft ABI.)
 CODEGENOPT(CtorDtorReturnThis, 1, 0)
 
+#include "DebugOptions.def"

jansvoboda11 wrote:

Got it. In that case I suggest leaving a FIXME behind.

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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Juergen Ributzka via cfe-commits


@@ -515,6 +430,8 @@ ENUM_CODEGENOPT(ZeroCallUsedRegs, 
llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
 /// non-deleting destructors. (No effect on Microsoft ABI.)
 CODEGENOPT(CtorDtorReturnThis, 1, 0)
 
+#include "DebugOptions.def"

ributzka wrote:

That was my initial idea, but it ballooned into a lot of code changes. Turns 
out the debug options are used in a lot of places. It could be done, but it 
would be a lot of churn.

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


[clang] [Clang] Remove NetBSD/i386 workaround for FP eval method with older versions (PR #74025)

2023-12-01 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/74025

>From 68942fe871a37e59c686c177aa43e63f08d730aa Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Thu, 30 Nov 2023 20:50:01 -0500
Subject: [PATCH] [Clang] Remove NetBSD/i386 workaround for FP eval method with
 older versions

NetBSD 7.x is long EoL. Make 8.x the minimum.
---
 clang/lib/Basic/Targets/X86.h | 9 -
 1 file changed, 9 deletions(-)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 99a64501d263ce4..f03edccf7a13c57 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -507,15 +507,6 @@ class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo
 public:
   NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : NetBSDTargetInfo(Triple, Opts) {}
-
-  LangOptions::FPEvalMethodKind getFPEvalMethod() const override {
-VersionTuple OsVersion = getTriple().getOSVersion();
-// New NetBSD uses the default rounding mode.
-if (OsVersion >= VersionTuple(6, 99, 26) || OsVersion.getMajor() == 0)
-  return X86_32TargetInfo::getFPEvalMethod();
-// NetBSD before 6.99.26 defaults to "double" rounding.
-return LangOptions::FPEvalMethodKind::FEM_Double;
-  }
 };
 
 class LLVM_LIBRARY_VISIBILITY OpenBSDI386TargetInfo

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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Juergen Ributzka via cfe-commits


@@ -4770,9 +4770,20 @@ std::string CompilerInvocation::getModuleHash() const {
 
   // When compiling with -gmodules, also hash -fdebug-prefix-map as it
   // affects the debug info in the PCM.
-  if (getCodeGenOpts().DebugTypeExtRefs)
+  if (getHeaderSearchOpts().ModuleFormat == "obj") {

ributzka wrote:

There was a test case that only passed the module format, but not 
DebugTypeExtRefs. DebugTypeExtRefs was used as a proxy for `-gmodules`, but 
that doesn't always work. From my understanding the driving factor should be 
the ModuleFormat, because that decides if debug options make a difference in 
the PCM.

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


[openmp] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits

pizzud wrote:

> I noticed a problem with your matcher, so I reviewed the rest of it while I 
> was at it.
> 
> The problem is that you do not consider a type-dependent `std::shared_ptr` 
> and the following test case fails:
> 
> ```c++
> template 
> void dependentType() {
>   std::shared_ptr p;
>   T y = std::move(*p);
>   // CHECK-FIXES: *std::move(p)
> }
> // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: don't move the contents out of a 
> shared pointer, as other accessors expect them to remain in a determinate 
> state [bugprone-move-shared-pointer-contents]
> ```
> 
> In this case, your `callee` is no longer a `functionDecl` but an 
> `unresolvedLookupExpr` and the `*` operator is a `UnaryOperator` instead of a 
> `cxxOperatorCallExpr`.
> 
> Otherwise, looks like a good check to have.

I'm really struggling with this, and also with getting the git history right 
after three months oops. The UnaryOperator is matchable without much 
difficulty, but there appears to be no way to introspect the 
UnresolvedLookupExpr to ensure I'm matching calls to `std::move`.

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


[clang] 357b8b4 - [Driver] Remove tests for NetBSD 7. No longer supported.

2023-12-01 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-12-01T18:56:22-05:00
New Revision: 357b8b46b125810c5c383c485b1fb3f3db233759

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

LOG: [Driver] Remove tests for NetBSD 7. No longer supported.

Added: 


Modified: 
clang/test/CodeGen/X86/fp-eval-method.c
clang/test/Driver/netbsd.c
clang/test/Driver/netbsd.cpp

Removed: 




diff  --git a/clang/test/CodeGen/X86/fp-eval-method.c 
b/clang/test/CodeGen/X86/fp-eval-method.c
index d74f88b9fe255a1..c1d8f617400d517 100644
--- a/clang/test/CodeGen/X86/fp-eval-method.c
+++ b/clang/test/CodeGen/X86/fp-eval-method.c
@@ -1,7 +1,4 @@
-// RUN: %clang_cc1 -triple i386-unknown-netbsd6 -emit-llvm -o - %s \
-// RUN: | FileCheck %s -check-prefixes=CHECK
-
-// RUN: %clang_cc1 -triple i386-unknown-netbsd7 -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple i386-unknown-netbsd -emit-llvm -o - %s \
 // RUN: | FileCheck %s -check-prefixes=CHECK-EXT
 
 // RUN: %clang_cc1 -triple i386--linux -emit-llvm -o - %s \

diff  --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 1452e9e2dc6e3c0..73777e7a3e38fa3 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -14,21 +14,12 @@
 // RUN: %clang --target=x86_64-unknown-netbsd \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=X86_64 %s
-// RUN: %clang --target=x86_64-unknown-netbsd7.0.0 \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=X86_64-7 %s
 // RUN: %clang --target=aarch64-unknown-netbsd \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=AARCH64 %s
-// RUN: %clang --target=aarch64-unknown-netbsd7.0.0 \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=AARCH64-7 %s
 // RUN: %clang --target=aarch64_be-unknown-netbsd \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=AARCH64_BE %s
-// RUN: %clang --target=aarch64_be-unknown-netbsd7.0.0 \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=AARCH64_BE-7 %s
 // RUN: %clang --target=arm-unknown-netbsd-eabi \
 // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=ARM %s
@@ -56,9 +47,6 @@
 // RUN: %clang --target=thumbeb-unknown-netbsd-eabi \
 // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=THUMBEB %s
-// RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=ARM-7 %s
 // RUN: %clang --target=riscv32-unknown-netbsd \
 // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=RISCV32 %s
@@ -81,42 +69,18 @@
 // RUN: %clang --target=x86_64-unknown-netbsd -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-X86_64 %s
-// RUN: %clang --target=x86_64-unknown-netbsd7.0.0 -static \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-X86_64-7 %s
 // RUN: %clang --target=aarch64-unknown-netbsd -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-AARCH64 %s
-// RUN: %clang --target=aarch64-unknown-netbsd7.0.0 -static \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-AARCH64-7 %s
 // RUN: %clang --target=aarch64_be-unknown-netbsd -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-AARCH64_BE %s
-// RUN: %clang --target=aarch64_be-unknown-netbsd7.0.0 -static \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-AARCH64_BE-7 %s
 // RUN: %clang --target=arm-unknown-netbsd-eabi -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-ARM %s
 // RUN: %clang --target=armeb-unknown-netbsd-eabi -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-ARMEB %s
-// RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi -static \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-ARM-7 %s
-// RUN: %clang --target=riscv32-unknown-netbsd7.0.0 -static \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-RISCV32-7 %s
-// RUN: %clang --target=riscv64-unknown-netbsd7.0.0 -static \
-// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefi

[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Jan Svoboda via cfe-commits


@@ -515,6 +430,8 @@ ENUM_CODEGENOPT(ZeroCallUsedRegs, 
llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
 /// non-deleting destructors. (No effect on Microsoft ABI.)
 CODEGENOPT(CtorDtorReturnThis, 1, 0)
 
+#include "DebugOptions.def"

jansvoboda11 wrote:

Do you think it would make sense to eventually treat these as separate 
top-level `.def` files?

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


[clang-tools-extra] [openmp] [llvm] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,17 @@
+.. title:: clang-tidy - bugprone-move-shared-pointer-contents
+
+bugprone-move-shared-pointer-contents
+=
+
+Detects calls to move the contents out of a ``std::shared_ptr`` rather than
+moving the pointer itself. In other words, calling ``std::move(*p)``. Other
+reference holders may not be expecting the move and suddenly getting empty or
+otherwise indeterminate states can cause issues.
+
+Options
+---
+
+.. option :: SharedPointerClasses
+
+   A semicolon-separated list of class names that should be treated as shared
+   pointers. By default only `std::shared_ptr` is included.

pizzud wrote:

Done.

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


[clang-tools-extra] [openmp] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,37 @@
+//===--- MoveSharedPointerContentsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include 
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/move-shared-pointer-contents.html
+class MoveSharedPointerContentsCheck : public ClangTidyCheck {
+public:
+  MoveSharedPointerContentsCheck(StringRef Name, ClangTidyContext *Context);
+  ~MoveSharedPointerContentsCheck() override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool
+  isLanguageVersionSupported(const LangOptions &LangOptions) const override;
+
+private:
+  const std::vector SharedPointerClasses;

pizzud wrote:

Done.

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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Jan Svoboda via cfe-commits


@@ -4770,9 +4770,20 @@ std::string CompilerInvocation::getModuleHash() const {
 
   // When compiling with -gmodules, also hash -fdebug-prefix-map as it
   // affects the debug info in the PCM.
-  if (getCodeGenOpts().DebugTypeExtRefs)
+  if (getHeaderSearchOpts().ModuleFormat == "obj") {

jansvoboda11 wrote:

Why did this change?

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


[openmp] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,37 @@
+//===--- MoveSharedPointerContentsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include 
+

pizzud wrote:

Done. Along with some unexpected shuffles by clang-format.

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


[clang-tools-extra] [openmp] [llvm] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;

pizzud wrote:

Done.

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


[llvm] [openmp] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(

pizzud wrote:

Done.

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


[clang-tools-extra] [openmp] [llvm] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,37 @@
+//===--- MoveSharedPointerContentsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include 
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.

pizzud wrote:

Done.

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


[llvm] [openmp] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits

https://github.com/pizzud updated 
https://github.com/llvm/llvm-project/pull/67467

>From 6d5d35e1273f595e8a0382053d5183cbce7a9d8a Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 26 Sep 2023 10:45:42 -0700
Subject: [PATCH 1/3] [clang-tidy] Add bugprone-move-shared-pointer-contents
 check.

This check detects moves of the contents of a shared pointer rather than the
pointer itself. Other code with a reference to the shared pointer is probably
not expecting the move.

The set of shared pointer classes is configurable via options to allow 
individual
projects to cover additional types.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  2 +
 .../MoveSharedPointerContentsCheck.cpp| 60 
 .../bugprone/MoveSharedPointerContentsCheck.h | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/move-shared-pointer-contents.rst | 17 +
 .../docs/clang-tidy/checks/list.rst   |  2 +
 .../bugprone/move-shared-pointer-contents.cpp | 68 +++
 8 files changed, 195 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/move-shared-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/move-shared-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a67a91eedd10482..7f4a504f9930f17 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "MisplacedPointerArithmeticInAllocCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
+#include "MoveSharedPointerContentsCheck.h"
 #include "MultiLevelImplicitPointerConversionCheck.h"
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
@@ -125,6 +126,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-move-shared-pointer-contents");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 3c768021feb1502..c017f0c0cc52021 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
@@ -35,6 +36,7 @@ add_clang_library(clangTidyBugproneModule
   MisplacedPointerArithmeticInAllocCheck.cpp
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   MultiLevelImplicitPointerConversionCheck.cpp
   MultipleNewInOneExpressionCheck.cpp
   MultipleStatementMacroCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
new file mode 100644
index 000..b4a393b7f2f2000
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions &LangOptions) const {
+  return

[openmp] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits


@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions &LangOptions) const {
+  return LangOptions.CPlusPlus11;
+}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("std::move"))),
+  hasArgument(0, cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
+ callee(cxxMethodDecl(ofClass(
+ 
matchers::matchesAnyListedName(
+ SharedPointerClasses)
+ .bind("op")))
+  .bind("call"),
+  this);
+}
+
+void MoveSharedPointerContentsCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Call = Result.Nodes.getNodeAs("call");
+  const auto *Op = Result.Nodes.getNodeAs("op");
+
+  if (Op) {

pizzud wrote:

Done.

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


[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Juergen Ributzka (ributzka)


Changes

CodeGen options do not affect the AST, so they usually can be ignored.
The only exception to the rule is when a PCM is created with `-gmodules`.
In that case the Clang module format is switched to object file
container and contains also serialized debug information that can be
affected by debug options. There the following approach was choosen:

1.) Split out all the debug options into a separate `DebugOptions.def`
file. The file is included by `CodeGenOptions.def`, so the change is
transparent to all existing users of `CodeGenOptions.def`.
2.) Reset all CodeGen options, but excluding affecting debug options.
3.) Conditionally reset debug options that can affect the PCM.

This fixes rdar://113135909.

---

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


7 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.def (+2-85) 
- (modified) clang/include/clang/Basic/CodeGenOptions.h (+4) 
- (added) clang/include/clang/Basic/DebugOptions.def (+146) 
- (modified) clang/include/module.modulemap (+1) 
- (modified) clang/lib/Basic/CodeGenOptions.cpp (+35) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+13-1) 
- (added) clang/test/ClangScanDeps/strip-codegen-args.m (+58) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 675645cd534ed76..506db4068f490a8 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -28,12 +28,8 @@ CODEGENOPT(Name, Bits, Default)
 #endif
 
 CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
-ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
-llvm::DebugCompressionType::None)
 CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
 CODEGENOPT(AsmVerbose, 1, 0) ///< -dA, -fverbose-asm.
-CODEGENOPT(Dwarf64   , 1, 0) ///< -gdwarf64.
-CODEGENOPT(Dwarf32   , 1, 1) ///< -gdwarf32.
 CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
 CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) 
operator new
 CODEGENOPT(AssumeUniqueVTables , 1, 1) ///< Assume a class has only one vtable.
@@ -73,10 +69,6 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug 
information for the new
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
 CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
///< '-g' + 'O>0' level.
-CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
- ///< each (it means check
- ///< the original debug info
- ///< metadata preservation).
 CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
  ///< is specified.
 CODEGENOPT(DisableTailCalls  , 1, 0) ///< Do not emit tail calls.
@@ -113,16 +105,10 @@ CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if 
-mindirect-branch-cs-prefix
 CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
///< enabled.
 CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when -fstack-size-section is 
enabled.
-CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is
-  ///< enabled.
 
 ///< Set when -femit-compact-unwind-non-canonical is enabled.
 CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0)
 
-///< Set when -femit-dwarf-unwind is passed.
-ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
-llvm::EmitDwarfUnwindType::Default)
-
 ///< Set when -fxray-always-emit-customevents is enabled.
 CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)
 
@@ -178,8 +164,6 @@ CODEGENOPT(IncrementalLinkerCompatible, 1, 0) ///< Emit an 
object file which can
 CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
 CODEGENOPT(MergeFunctions, 1, 0) ///< Set when -fmerge-functions is 
enabled.
 CODEGENOPT(NoCommon  , 1, 0) ///< Set when -fno-common or C++ is 
enabled.
-CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm 
is
-   ///< enabled.
 CODEGENOPT(NoExecStack   , 1, 0) ///< Set when -Wa,--noexecstack is 
enabled.
 CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
  ///< enabled.
@@ -187,8 +171,6 @@ CODEGENOPT(NoWarn, 1, 0) ///< Set when 
-Wa,--no-warn is enabled.
 CODEGENOPT(NoTypeCheck   , 1, 0) ///< Set when -Wa,--no-type-check is 
enabled.
 CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect 

[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Juergen Ributzka via cfe-commits

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


[clang-tools-extra] [openmp] [llvm] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 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 d22944d1cc54a3384a88d654d144ef62a693df16 
528146e8d1fae56d2d4cc2d32a0823aa1f9cbc2b -- 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h 
clang-tools-extra/test/clang-tidy/checkers/bugprone/move-shared-pointer-contents.cpp
 clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
index 71b826596f..681dfe7f42 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
@@ -9,9 +9,9 @@
 #ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
 #define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
 
-#include 
 #include "../ClangTidyCheck.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang::tidy::bugprone {
 

``




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


[clang-tools-extra] [openmp] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits

https://github.com/pizzud updated 
https://github.com/llvm/llvm-project/pull/67467

>From 6d5d35e1273f595e8a0382053d5183cbce7a9d8a Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 26 Sep 2023 10:45:42 -0700
Subject: [PATCH 1/2] [clang-tidy] Add bugprone-move-shared-pointer-contents
 check.

This check detects moves of the contents of a shared pointer rather than the
pointer itself. Other code with a reference to the shared pointer is probably
not expecting the move.

The set of shared pointer classes is configurable via options to allow 
individual
projects to cover additional types.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  2 +
 .../MoveSharedPointerContentsCheck.cpp| 60 
 .../bugprone/MoveSharedPointerContentsCheck.h | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/move-shared-pointer-contents.rst | 17 +
 .../docs/clang-tidy/checks/list.rst   |  2 +
 .../bugprone/move-shared-pointer-contents.cpp | 68 +++
 8 files changed, 195 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/move-shared-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/move-shared-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a67a91eedd10482..7f4a504f9930f17 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "MisplacedPointerArithmeticInAllocCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
+#include "MoveSharedPointerContentsCheck.h"
 #include "MultiLevelImplicitPointerConversionCheck.h"
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
@@ -125,6 +126,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-move-shared-pointer-contents");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 3c768021feb1502..c017f0c0cc52021 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
@@ -35,6 +36,7 @@ add_clang_library(clangTidyBugproneModule
   MisplacedPointerArithmeticInAllocCheck.cpp
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   MultiLevelImplicitPointerConversionCheck.cpp
   MultipleNewInOneExpressionCheck.cpp
   MultipleStatementMacroCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
new file mode 100644
index 000..b4a393b7f2f2000
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions &LangOptions) const {
+  return

[clang-tools-extra] [llvm] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread via cfe-commits

https://github.com/pizzud updated 
https://github.com/llvm/llvm-project/pull/67467

>From 6d5d35e1273f595e8a0382053d5183cbce7a9d8a Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 26 Sep 2023 10:45:42 -0700
Subject: [PATCH 1/2] [clang-tidy] Add bugprone-move-shared-pointer-contents
 check.

This check detects moves of the contents of a shared pointer rather than the
pointer itself. Other code with a reference to the shared pointer is probably
not expecting the move.

The set of shared pointer classes is configurable via options to allow 
individual
projects to cover additional types.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  2 +
 .../MoveSharedPointerContentsCheck.cpp| 60 
 .../bugprone/MoveSharedPointerContentsCheck.h | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/move-shared-pointer-contents.rst | 17 +
 .../docs/clang-tidy/checks/list.rst   |  2 +
 .../bugprone/move-shared-pointer-contents.cpp | 68 +++
 8 files changed, 195 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/move-shared-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/move-shared-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a67a91eedd10482..7f4a504f9930f17 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "MisplacedPointerArithmeticInAllocCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
+#include "MoveSharedPointerContentsCheck.h"
 #include "MultiLevelImplicitPointerConversionCheck.h"
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
@@ -125,6 +126,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-move-shared-pointer-contents");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 3c768021feb1502..c017f0c0cc52021 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
@@ -35,6 +36,7 @@ add_clang_library(clangTidyBugproneModule
   MisplacedPointerArithmeticInAllocCheck.cpp
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   MultiLevelImplicitPointerConversionCheck.cpp
   MultipleNewInOneExpressionCheck.cpp
   MultipleStatementMacroCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
new file mode 100644
index 000..b4a393b7f2f2000
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions &LangOptions) const {
+  return

[clang] [llvm] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-01 Thread Ellis Hoag via cfe-commits


@@ -300,12 +316,8 @@ getIRPGONameForGlobalObject(const GlobalObject &GO,
 GlobalValue::LinkageTypes Linkage,
 StringRef FileName) {
   SmallString<64> Name;
-  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
-Name.append(FileName.empty() ? "" : FileName);
-Name.append(";");
-  }
   Mangler().getNameWithPrefix(Name, &GO, /*CannotUsePrivateLabel=*/true);

ellishg wrote:

> Was PGO broken in general before D156569? Or is this specific to 
> -symbol-ordering-file and -order_file?

It wasn't broken in general, but it's needed to get `-order_file` working 
correctly.

> Also, it looks like some of the main changes here by the mangler for 
> objective C are to strip the "\01" prefix. Is this different than the support 
> to remove the '\1' mangling escape in getGlobalIdentifier()?

I think both remove the `\01` prefix. But the mangler might also prepend 
`_`/`l_` depending on the linkage, and `getGlobalIdentifier()` does not do this.

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


[llvm] [flang] [clang] [compiler-rt] [clang-tools-extra] [BPI] Reuse the AsmWriter's BB naming scheme in BranchProbabilityPrinterPass (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

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


[clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [BPI] Reuse the AsmWriter's BB naming scheme in BranchProbabilityPrinterPass (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-01 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan created 
https://github.com/llvm/llvm-project/pull/74155

This implements -Wstrict-aliasing(=[123])? along the same lines as GCC. It's 
not 100% the same for reasons expanded on below. The default is level 3, and I 
have verified that bootstrapping does not trigger any warnings (just like 
building with GCC).

As with GCC, higher levels result in fewer warnings, reducing the number of 
false positives at the cost of missing (some) potential cases. Unlike GCC, this 
is entirely in the FE, we do not propagate any checking into the IR (so there 
are cases GCC will detect we do not, I have not encountered any). GCC's 
documentation is not very specific about which cases are detected. I examined 
GCC's source code to reverse engineer the algorithm[*], and as can be seen from 
the testcases, noted GCC's behaviour.

The strict aliasing check relies on TBAA. LLVM's representation is semantically 
different to GCCs for structured types. I have tried to keep with the spirit of 
the warning.

The warning checks reinterpret_casts that are CK_BitCast or CK_LValueBitCast. 
It also checks C-style casts that are equivalent (to the extent available, as a 
C-style bitcast could be a well-formed static cast).

level=1 looks for reinterpret casts from T * to U * (or an lvalue of type T to 
U &), where T and U are not TBAA compatible.

level=2 requires the src expression be an lvalue something of known(ish) static 
type. I.e a variable, array dereference or member access.

level=3 requires level 2 and that the resultant pointer is actually referenced 
(lvalue->rvalue or lvalue written). Here we can do better than GCC, which 
doesn't represent this in the IR -- we merely get a dereference (and reference 
types are modeled as pointers with auto-dereference semantics). There is one 
exception to this, which is by-value aggregate arguments. These end up invoking 
a copy constructor (passing a reference of course), but are IMHO morally an 
rvalue -- so should trigger.

The warning hooks into clang's code-generator's TBAA machinery. For scalar 
types the TBAA is straight forwards, comparing LLVM's MDNode representaion. For 
record & union types we check if one of the types is (recursively) the same (or 
TBAA compatible) as the first direct base or a field(s) of the record at offset 
zero (i.e. the first member of a record, or any members of a union). This 
covers both C++ and C-Style inheritance. Also. the member maybe alias_any, or 
in ubiquitous-char's alias set, which is also permissible.

The warning is similar to the alignment check that 
CheckCompatibleReinterpretCast does, perhaps some merging could occur if this 
is accepted?

[*] I implemented what turned into GCC's level=1 way back when.

WIP: adjust tests

>From 89c05618bb75fd073343046f3b54bde5f2254719 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Wed, 15 Nov 2023 15:27:16 -0500
Subject: [PATCH] [clang] Strict aliasing warning ala GCC [PR50066]

This implements -Wstrict-aliasing(=[123])? along the same lines as
GCC. It's not 100% the same for reasons expanded on below. The default
is level 3, and I have verified that bootstrapping does not trigger
any warnings (just like building with GCC).

As with GCC, higher levels result in fewer warnings, reducing the
number of false positives at the cost of missing (some) potential
cases. Unlike GCC, this is entirely in the FE, we do not propagate any
checking into the IR (so there are cases GCC will detect we do not, I
have not encountered any). GCC's documentation is not very specific
about which cases are detected. I examined GCC's source code to reverse
engineer the algorithm[*], and as can be seen from the testcases, noted
GCC's behaviour.

The strict aliasing check relies on TBAA. LLVM's representation is
semantically different to GCCs for structured types. I have tried to
keep with the spirit of the warning.

The warning checks reinterpret_casts that are CK_BitCast or
CK_LValueBitCast. It also checks C-style casts that are equivalent (to
the extent available, as a C-style bitcast could be a well-formed
static cast).

level=1 looks for reinterpret casts from T * to U * (or an lvalue of
type T to U &), where T and U are not TBAA compatible.

level=2 requires the src expression be an lvalue something of
known(ish) static type. I.e a variable, array dereference or member
access.

level=3 requires level 2 and that the resultant pointer is actually
referenced (lvalue->rvalue or lvalue written). Here we can do better
than GCC, which doesn't represent this in the IR -- we merely get a
dereference (and reference types are modeled as pointers with
auto-dereference semantics). There is one exception to this, which is
by-value aggregate arguments. These end up invoking a copy constructor
(passing a reference of course), but are IMHO morally an rvalue -- so
should trigger.

The warning hooks into clang's code-generator's TBAA machinery. For
scalar types the TBAA is straight forwards, comparing LLVM's MD

[clang] [clang][modules] Reset codegen options. (PR #74006)

2023-12-01 Thread Adrian Prantl via cfe-commits

https://github.com/adrian-prantl approved this pull request.


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


[clang-tools-extra] [llvm] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-01 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert updated 
https://github.com/llvm/llvm-project/pull/67467

>From 6d5d35e1273f595e8a0382053d5183cbce7a9d8a Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 26 Sep 2023 10:45:42 -0700
Subject: [PATCH] [clang-tidy] Add bugprone-move-shared-pointer-contents check.

This check detects moves of the contents of a shared pointer rather than the
pointer itself. Other code with a reference to the shared pointer is probably
not expecting the move.

The set of shared pointer classes is configurable via options to allow 
individual
projects to cover additional types.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  2 +
 .../MoveSharedPointerContentsCheck.cpp| 60 
 .../bugprone/MoveSharedPointerContentsCheck.h | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/move-shared-pointer-contents.rst | 17 +
 .../docs/clang-tidy/checks/list.rst   |  2 +
 .../bugprone/move-shared-pointer-contents.cpp | 68 +++
 8 files changed, 195 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/move-shared-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/move-shared-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a67a91eedd10482..7f4a504f9930f17 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "MisplacedPointerArithmeticInAllocCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
+#include "MoveSharedPointerContentsCheck.h"
 #include "MultiLevelImplicitPointerConversionCheck.h"
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
@@ -125,6 +126,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-move-shared-pointer-contents");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 3c768021feb1502..c017f0c0cc52021 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
@@ -35,6 +36,7 @@ add_clang_library(clangTidyBugproneModule
   MisplacedPointerArithmeticInAllocCheck.cpp
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   MultiLevelImplicitPointerConversionCheck.cpp
   MultipleNewInOneExpressionCheck.cpp
   MultipleStatementMacroCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
new file mode 100644
index 000..b4a393b7f2f2000
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions &LangOptions) const {
+  return L

[clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [bpi] Reuse the AsmWriter's BB naming scheme (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> Consider using `utils/update_analyze_test_checks.py` to create the check 
> lines...

Ack - I did for the new test, and updated the remaining tests - since now all 
the BB names have a preceding `%`.

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


[clang] [llvm] [clang-tools-extra] Fix #41439: Update the documentation with the correct information. (PR #69377)

2023-12-01 Thread Piotr Zegar via cfe-commits

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

LGTM.
Unless you want it merged as "57949090+da-vi...@users.noreply.github.com", 
please update your github config.

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


[clang] [CUDA] work around more __noinline__ conflicts with libc++ (PR #74123)

2023-12-01 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B updated 
https://github.com/llvm/llvm-project/pull/74123

>From 71e24fc704c82c11162313613691d09b9a653bd5 Mon Sep 17 00:00:00 2001
From: Artem Belevich 
Date: Fri, 1 Dec 2023 10:37:08 -0800
Subject: [PATCH 1/3] [CUDA] work around more __noinline__ conflicts with
 libc++

https://github.com/llvm/llvm-project/pull/73838
---
 clang/lib/Headers/CMakeLists.txt |  2 ++
 clang/lib/Headers/cuda_wrappers/__config | 10 ++
 clang/lib/Headers/cuda_wrappers/string   | 10 ++
 3 files changed, 22 insertions(+)
 create mode 100644 clang/lib/Headers/cuda_wrappers/__config
 create mode 100644 clang/lib/Headers/cuda_wrappers/string

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index fdd54c05eedf825..f562c354327f2fb 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -283,10 +283,12 @@ set(files
   )
 
 set(cuda_wrapper_files
+  cuda_wrappers/__config
   cuda_wrappers/algorithm
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/string
 )
 
 set(cuda_wrapper_bits_files
diff --git a/clang/lib/Headers/cuda_wrappers/__config 
b/clang/lib/Headers/cuda_wrappers/__config
new file mode 100644
index 000..04038b0fa3437ee
--- /dev/null
+++ b/clang/lib/Headers/cuda_wrappers/__config
@@ -0,0 +1,10 @@
+// CUDA headers define __noinline__ which interferes with libc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#define __noinline__ __noinline__
+#include_next "__config"
+
+#pragma pop_macro("__noinline__")
diff --git a/clang/lib/Headers/cuda_wrappers/string 
b/clang/lib/Headers/cuda_wrappers/string
new file mode 100644
index 000..d612710393623b5
--- /dev/null
+++ b/clang/lib/Headers/cuda_wrappers/string
@@ -0,0 +1,10 @@
+// CUDA headers define __noinline__ which interferes with libc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#define __noinline__ __noinline__
+#include_next "string"
+
+#pragma pop_macro("__noinline__")

>From 0f67fcd9bc1da6149dc2bde9b3524d219c957112 Mon Sep 17 00:00:00 2001
From: Artem Belevich 
Date: Fri, 1 Dec 2023 12:12:46 -0800
Subject: [PATCH 2/3] libstdc++ -> libc++ in the comments.

---
 clang/lib/Headers/cuda_wrappers/__config | 2 +-
 clang/lib/Headers/cuda_wrappers/string   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/cuda_wrappers/__config 
b/clang/lib/Headers/cuda_wrappers/__config
index 04038b0fa3437ee..92e9a27eec2d8e5 100644
--- a/clang/lib/Headers/cuda_wrappers/__config
+++ b/clang/lib/Headers/cuda_wrappers/__config
@@ -1,6 +1,6 @@
 // CUDA headers define __noinline__ which interferes with libc++'s use of
 // `__attribute((__noinline__))`. In order to avoid compilation error,
-// temporarily unset __noinline__ when we include affected libstdc++ header.
+// temporarily unset __noinline__ when we include affected libc++ header.
 
 #pragma push_macro("__noinline__")
 #undef __noinline__
diff --git a/clang/lib/Headers/cuda_wrappers/string 
b/clang/lib/Headers/cuda_wrappers/string
index d612710393623b5..1a969fd065c21a7 100644
--- a/clang/lib/Headers/cuda_wrappers/string
+++ b/clang/lib/Headers/cuda_wrappers/string
@@ -1,6 +1,6 @@
 // CUDA headers define __noinline__ which interferes with libc++'s use of
 // `__attribute((__noinline__))`. In order to avoid compilation error,
-// temporarily unset __noinline__ when we include affected libstdc++ header.
+// temporarily unset __noinline__ when we include affected libc++ header.
 
 #pragma push_macro("__noinline__")
 #undef __noinline__

>From 3e5fee705f1203cbaef0d347492d9fd5f433f4c9 Mon Sep 17 00:00:00 2001
From: Artem Belevich 
Date: Fri, 1 Dec 2023 14:25:42 -0800
Subject: [PATCH 3/3] Use `#include <...>`

---
 clang/lib/Headers/cuda_wrappers/__config | 2 +-
 clang/lib/Headers/cuda_wrappers/string   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/cuda_wrappers/__config 
b/clang/lib/Headers/cuda_wrappers/__config
index 92e9a27eec2d8e5..c9966bdc7ef9bff 100644
--- a/clang/lib/Headers/cuda_wrappers/__config
+++ b/clang/lib/Headers/cuda_wrappers/__config
@@ -5,6 +5,6 @@
 #pragma push_macro("__noinline__")
 #undef __noinline__
 #define __noinline__ __noinline__
-#include_next "__config"
+#include_next <__config>
 
 #pragma pop_macro("__noinline__")
diff --git a/clang/lib/Headers/cuda_wrappers/string 
b/clang/lib/Headers/cuda_wrappers/string
index 1a969fd065c21a7..b63647055f01ce4 100644
--- a/clang/lib/Headers/cuda_wrappers/string
+++ b/clang/lib/Headers/cuda_wrappers/string
@@ -5,6 +5,6 @@
 #pragma push_macro("__noinline__")
 #undef __noinline__
 #define __noinline__ 

[clang] [CUDA] work around more __noinline__ conflicts with libc++ (PR #74123)

2023-12-01 Thread Artem Belevich via cfe-commits

Artem-B wrote:

> FWIW I am not thrilled about using `__config` here. That header is an 
> implementation detail of libc++ and defining it and relying on it is somewhat 
> brittle.

I'm all for having it fixed in libc++ or in CUDA SDK. Barring that, working 
around the specific implementation details is all I can do here.  I'm open to 
other ideas on how this conflict can be worked around or solved in a better way.



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


[libcxx] [libunwind] [llvm] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-12-01 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/68753

>From 5e53337f16aa446d6a2dc764d347ea37b22c3a56 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Tue, 10 Oct 2023 16:35:11 -0700
Subject: [PATCH 1/4] [libc++] Allow running the test suite with optimizations

This patch adds a configuration of the libc++ test suite that enables
optimizations when building the tests. It also adds a new CI configuration
to exercise this on a regular basis. This is added in the context of [1],
which requires building with optimizations in order to hit the bug.

[1]: https://github.com/llvm/llvm-project/issues/68552
---
 .github/workflows/libcxx-build-and-test.yaml  |  2 +-
 .../caches/Generic-optimized-speed.cmake  |  4 +++
 .../support.dynamic/libcpp_deallocate.sh.cpp  | 17 +--
 .../path.member/path.assign/move.pass.cpp |  2 +-
 .../path.member/path.construct/move.pass.cpp  |  2 +-
 .../new.size.replace.indirect.pass.cpp|  3 +-
 .../new.size.replace.pass.cpp |  3 +-
 .../new.size_align.replace.indirect.pass.cpp  |  7 +++--
 ...ze_align_nothrow.replace.indirect.pass.cpp |  7 +++--
 .../new.size_align_nothrow.replace.pass.cpp   |  7 +++--
 ...new.size_nothrow.replace.indirect.pass.cpp |  3 +-
 .../new.size_nothrow.replace.pass.cpp |  3 +-
 .../new.size.replace.pass.cpp |  3 +-
 ...ze_align_nothrow.replace.indirect.pass.cpp |  7 +++--
 ...new.size_nothrow.replace.indirect.pass.cpp |  3 +-
 .../func.wrap.func.alg/swap.pass.cpp  | 16 +--
 .../func.wrap.func.con/F.pass.cpp |  2 +-
 .../func.wrap.func.con/copy_assign.pass.cpp   |  8 +++---
 .../func.wrap.func.con/copy_move.pass.cpp |  8 +++---
 .../nullptr_t_assign.pass.cpp |  2 +-
 .../func.wrap.func.mod/swap.pass.cpp  | 12 
 .../make_shared.pass.cpp  |  4 +--
 libcxx/test/support/count_new.h   |  5 
 libcxx/test/support/do_not_optimize.h | 28 +++
 libcxx/utils/ci/run-buildbot  |  5 
 libcxx/utils/libcxx/test/params.py| 28 ++-
 libunwind/test/libunwind_02.pass.cpp  | 26 +
 libunwind/test/unw_resume.pass.cpp|  2 +-
 libunwind/test/unwind_leaffunction.pass.cpp   | 20 +++--
 29 files changed, 169 insertions(+), 70 deletions(-)
 create mode 100644 libcxx/cmake/caches/Generic-optimized-speed.cmake
 create mode 100644 libcxx/test/support/do_not_optimize.h

diff --git a/.github/workflows/libcxx-build-and-test.yaml 
b/.github/workflows/libcxx-build-and-test.yaml
index 018f0e45a2441ef..9c7adb808bcb34f 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -162,6 +162,7 @@ jobs:
   'generic-no-tzdb',
   'generic-no-unicode',
   'generic-no-wide-characters',
+  'generic-optimized-speed',
   'generic-static',
   'generic-with_llvm_unwinder',
   # TODO Find a better place for the benchmark and bootstrapping 
builds to live. They're either very expensive
@@ -209,4 +210,3 @@ jobs:
 **/CMakeError.log
 **/CMakeOutput.log
 **/crash_diagnostics/*
-  
diff --git a/libcxx/cmake/caches/Generic-optimized-speed.cmake 
b/libcxx/cmake/caches/Generic-optimized-speed.cmake
new file mode 100644
index 000..577a5de9f34c539
--- /dev/null
+++ b/libcxx/cmake/caches/Generic-optimized-speed.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "")
+set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
+set(LIBUNWIND_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
diff --git 
a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp 
b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
index fb56ce4518a7182..6e6229b752a7a6e 100644
--- 
a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
+++ 
b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
@@ -34,6 +34,7 @@
 #include 
 #include 
 
+#include "do_not_optimize.h"
 #include "test_macros.h"
 
 TEST_DIAGNOSTIC_PUSH
@@ -187,13 +188,13 @@ void test_allocator_and_new_match() {
   stats.reset();
 #if defined(NO_SIZE) && defined(NO_ALIGN)
   {
-int* x = new int(42);
+int* x = support::do_not_optimize(new int(42));
 delete x;
 assert(stats.expect_plain());
   }
   stats.reset();
   {
-AlignedType* a = new AlignedType();
+AlignedType* a = support::do_not_optimize(new AlignedType());
 delete a;
 assert(stats.expect_plain());
   }
@@ -202,14 +203,14 @@ void test_allocator_and_new_match() {
   stats.reset();
 #if TEST_STD_VER >= 11
   {
-int* x = new int(42);
+int* x = support::do_not_optimize(new int(42));
 delete x;
 assert(stats.expect_plain());
   }
 #endif
   stats.

[clang-tools-extra] [clang-tidy] Add new modernize-use-starts-ends-with check (PR #72385)

2023-12-01 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

@nicovank I run check on llvm, reported 3 issues, no false-positives. There is 
warning reported for FindFun variable because is used only in assert, check if 
you could do something with it, maybe add if for checking agains null, to 
silent warning or removing this variable and assert.
Check your github config (email privacy) otherwise this PR will be merged as 
nicov...@users.noreply.github.com

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


[clang] 2b76e20 - [CUDA][HIP] allow trivial ctor/dtor in device var init (#73140)

2023-12-01 Thread via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-12-01T16:24:01-05:00
New Revision: 2b76e20ea782790a78ec58d5f94ce88a173bab7f

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

LOG: [CUDA][HIP] allow trivial ctor/dtor in device var init (#73140)

Treat ctor/dtor in device var init as host device function
so that they can be used to initialize file-scope
device variables to match nvcc behavior. If they are non-trivial
they will be diagnosed.

We cannot add implicit host device attrs to non-trivial
ctor/dtor since determining whether they are non-trivial
needs to know whether they have a trivial body and all their
member and base classes' ctor/dtor have trivial body, which
is affected by where their bodies are defined or instantiated.

Fixes: #72261

Fixes: SWDEV-432412

Added: 
clang/test/SemaCUDA/trivial-ctor-dtor.cu

Modified: 
clang/lib/Sema/SemaCUDA.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 318174f7be8fa95..6a66ecf6f94c178 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -225,6 +225,15 @@ Sema::CUDAFunctionPreference
 Sema::IdentifyCUDAPreference(const FunctionDecl *Caller,
  const FunctionDecl *Callee) {
   assert(Callee && "Callee must be valid.");
+
+  // Treat ctor/dtor as host device function in device var initializer to allow
+  // trivial ctor/dtor without device attr to be used. Non-trivial ctor/dtor
+  // will be diagnosed by checkAllowedCUDAInitializer.
+  if (Caller == nullptr && CurCUDATargetCtx.Kind == CTCK_InitGlobalVar &&
+  CurCUDATargetCtx.Target == CFT_Device &&
+  (isa(Callee) || isa(Callee)))
+return CFP_HostDevice;
+
   CUDAFunctionTarget CallerTarget = IdentifyCUDATarget(Caller);
   CUDAFunctionTarget CalleeTarget = IdentifyCUDATarget(Callee);
 

diff  --git a/clang/test/SemaCUDA/trivial-ctor-dtor.cu 
b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
new file mode 100644
index 000..34142bcc621200f
--- /dev/null
+++ b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -isystem %S/Inputs  -fsyntax-only -verify %s
+// RUN: %clang_cc1 -isystem %S/Inputs -fcuda-is-device -fsyntax-only -verify %s
+
+#include 
+
+// Check trivial ctor/dtor
+struct A {
+  int x;
+  A() {}
+  ~A() {}
+};
+
+__device__ A a;
+
+// Check trivial ctor/dtor of template class
+template
+struct TA {
+  T x;
+  TA() {}
+  ~TA() {}
+};
+
+__device__ TA ta;
+
+// Check non-trivial ctor/dtor in parent template class
+template
+struct TB {
+  T x;
+  TB() { static int nontrivial_ctor = 1; }
+  ~TB() {}
+};
+
+template
+struct TC : TB {
+  T x;
+  TC() {}
+  ~TC() {}
+};
+
+template class TC;
+
+__device__ TC tc; //expected-error {{dynamic initialization is not 
supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+// Check trivial ctor specialization
+template 
+struct C {
+explicit C() {};
+};
+
+template <> C::C() {};
+__device__ C ci_d;
+C ci_h;
+
+// Check non-trivial ctor specialization
+template <> C::C() { static int nontrivial_ctor = 1; }
+__device__ C cf_d; //expected-error {{dynamic initialization is not 
supported for __device__, __constant__, __shared__, and __managed__ variables}}
+C cf_h;



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


[clang] [CUDA][HIP] allow trivial ctor/dtor in device var init (PR #73140)

2023-12-01 Thread Yaxun Liu via cfe-commits

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


[clang] [HIP] fix stack marking for -fgpu-rdc (PR #72782)

2023-12-01 Thread Yaxun Liu via cfe-commits

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


[clang] a4d8549 - [HIP] fix stack marking for -fgpu-rdc (#72782)

2023-12-01 Thread via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-12-01T16:22:16-05:00
New Revision: a4d85490e029e797d22881b37d476c2050d0d6a2

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

LOG: [HIP] fix stack marking for -fgpu-rdc (#72782)

HIP toolchain uses llvm-mc to generate a host object embedding device
binary for -fgpu-rdc. Due to lack of .note.GNU-stack section, the
generated relocatable has executable stack marking, which disables
protection from executable stack for any HIP programs compiled with
-fgpu-rdc.

This patch adds .note.GNU-stack section to the input to llvm-mc to fix
the executable stack marking.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/HIPUtility.cpp
clang/test/Driver/hip-toolchain-rdc.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 04efdcba20ea740..f692458b775de2b 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -150,6 +150,8 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   ObjStream << "  .incbin ";
   llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
   ObjStream << "\n";
+  if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
+ObjStream << "  .section .note.GNU-stack, \"\", @progbits\n";
   ObjStream.flush();
 
   // Dump the contents of the temp object file gen if the user requested that.

diff  --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index fa30bb8a9f5f576..1827531f9cab7a3 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -32,6 +32,8 @@
 // CHECK: .p2align 12
 // CHECK: __hip_fatbin:
 // CHECK: .incbin "[[BUNDLE:.*hipfb]]"
+// LNX: .section .note.GNU-stack, "", @progbits
+// MSVC-NOT: .note.GNU-stack
 
 // emit objects for host side path
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" [[HOST:"x86_64-[^"]+"]]



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


[clang] [clang] Better bitfield access units (PR #65742)

2023-12-01 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

You knew this ping was coming, right?

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


[flang] [clang] [flang][driver][RFC] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-01 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/74139

>From 2e41335a7de3d2efa88eacee659172a3b9525e45 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 21:41:44 +0100
Subject: [PATCH 1/4] Add -fno-fortran-main driver option

---
 clang/include/clang/Driver/Options.td | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d68..aa26344f67b3132 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6345,6 +6345,10 @@ def J : JoinedOrSeparate<["-"], "J">,
   Group,
   Alias;
 
+def no_fortran_main : Flag<["-"], "fno-fortran-main">,
+  Visibility<[FlangOption]>, Group,
+  HelpText<"Don't link in Fortran main">;
+
 
//===--===//
 // FC1 Options
 
//===--===//

>From 44b684ae43a6da37bb56c5b699628c6807257ad9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 21:42:09 +0100
Subject: [PATCH 2/4] Skip linking Fortran_main.a if -fno-fortran-main is
 present

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 46 --
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 0ae8e2dce32e94a..2899f07cb7490ca 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1116,33 +1116,37 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, 
const ToolChain &TC,
   return true;
 }
 
+// TODO: add -fno-fortran-main option and check it in this function.
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-// The --whole-archive option needs to be part of the link line to
-// make sure that the main() function from Fortran_main.a is pulled
-// in by the linker.  Determine if --whole-archive is active when
-// flang will try to link Fortran_main.a.  If it is, don't add the
-// --whole-archive flag to the link line.  If it's not, add a proper
-// --whole-archive/--no-whole-archive bracket to the link line.
-bool WholeArchiveActive = false;
-for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
-  if (Arg)
-for (StringRef ArgValue : Arg->getValues()) {
-  if (ArgValue == "--whole-archive")
-WholeArchiveActive = true;
-  if (ArgValue == "--no-whole-archive")
-WholeArchiveActive = false;
-}
-
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lFortran_main");
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--no-whole-archive");
+// if -fno-fortran-main has been passed, skip linking Fortran_main.a
+bool DontLinkFortranMain = Args.getLastArg(options::OPT_no_fortran_main) 
!= nullptr;
+if (!DontLinkFortranMain) {
+  // The --whole-archive option needs to be part of the link line to
+  // make sure that the main() function from Fortran_main.a is pulled
+  // in by the linker.  Determine if --whole-archive is active when
+  // flang will try to link Fortran_main.a.  If it is, don't add the
+  // --whole-archive flag to the link line.  If it's not, add a proper
+  // --whole-archive/--no-whole-archive bracket to the link line.
+  bool WholeArchiveActive = false;
+  for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
+if (Arg)
+  for (StringRef ArgValue : Arg->getValues()) {
+if (ArgValue == "--whole-archive")
+  WholeArchiveActive = true;
+if (ArgValue == "--no-whole-archive")
+  WholeArchiveActive = false;
+  }
 
+  if (!WholeArchiveActive)
+CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lFortran_main");
+  if (!WholeArchiveActive)
+CmdArgs.push_back("--no-whole-archive");
+}
 // Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");

>From e1a472fa914ea9405be6589e89fbe8201448600f Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 15:10:29 -0600
Subject: [PATCH 3/4] Cleanup and simplify the code a bit

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2899f07cb7490ca..f0e3df2a63ae989 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/

[clang] [analyzer] Let the checkers query upper and lower bounds on symbols (PR #74141)

2023-12-01 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (DonatNagyE)


Changes

This commit extends the class `SValBuilder` with the methods `getMinValue()` 
and `getMaxValue()` to that work like `SValBuilder::getKnownValue()` but return 
the minimal/maximal possible value the `SVal` is not perfectly constrained.

This extension of the ConstraintManager API is discussed at: 
https://discourse.llvm.org/t/expose-the-inferred-range-information-in-warning-messages/75192

As a simple proof-of-concept application of this new API, this commit extends a 
message from `core.BitwiseShift` with some range information that reports the 
assumptions of the analyzer.

My main motivation for adding these methods is that I'll also want to use them 
in `ArrayBoundCheckerV2` to make the error messages less awkward, but I'm 
starting with this simpler and less important usecase because I want to avoid 
merge conflicts with my other commit 
https://github.com/llvm/llvm-project/pull/72107 which is currently under review.

The testcase `too_large_right_operand_compound()` shows a situation where 
querying the range information does not work (and the extra information is not 
added to the error message). This also affects the debug utility 
`clang_analyzer_value()`, so the problem isn't in the fresh code. I'll do some 
investigations to resolve this, but I think that this commit is a step forward 
even with this limitation.

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


6 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h (+16) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h (+8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp (+11-5) 
- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+22) 
- (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+50-6) 
- (modified) clang/test/Analysis/bitwise-shift-common.c (+11-3) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
index 4e94ad49a783360..4de04bc4d397ac4 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -110,6 +110,22 @@ class ConstraintManager {
 return nullptr;
   }
 
+  /// Attempt to return the minimal possible value for a given symbol. Note
+  /// that a ConstraintManager is not obligated to return a lower bound, it may
+  /// also return nullptr.
+  virtual const llvm::APSInt *getSymMinVal(ProgramStateRef state,
+   SymbolRef sym) const {
+return nullptr;
+  }
+
+  /// Attempt to return the minimal possible value for a given symbol. Note
+  /// that a ConstraintManager is not obligated to return a lower bound, it may
+  /// also return nullptr.
+  virtual const llvm::APSInt *getSymMaxVal(ProgramStateRef state,
+   SymbolRef sym) const {
+return nullptr;
+  }
+
   /// Scan all symbols referenced by the constraints. If the symbol is not
   /// alive, remove it.
   virtual ProgramStateRef removeDeadBindings(ProgramStateRef state,
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
index a64cf7ae4efcb82..d7cff49036cb810 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -110,6 +110,14 @@ class SValBuilder {
   /// that value is returned. Otherwise, returns NULL.
   virtual const llvm::APSInt *getKnownValue(ProgramStateRef state, SVal val) = 
0;
 
+  /// Tries to get the minimal possible (integer) value of a given SVal. If the
+  /// constraint manager cannot provide an useful answer, this returns NULL.
+  virtual const llvm::APSInt *getMinValue(ProgramStateRef state, SVal val) = 0;
+
+  /// Tries to get the maximal possible (integer) value of a given SVal. If the
+  /// constraint manager cannot provide an useful answer, this returns NULL.
+  virtual const llvm::APSInt *getMaxValue(ProgramStateRef state, SVal val) = 0;
+
   /// Simplify symbolic expressions within a given SVal. Return an SVal
   /// that represents the same value, but is hopefully easier to work with
   /// than the original SVal.
diff --git a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
index 8a933d124d7700d..d4aa9fa1339f47c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
@@ -172,18 +172,24 @@ BugReportPtr BitwiseShiftValidator::checkOvershift() {
 
   const SVal Right = Ctx.getSVal(operandExpr(Op

[clang] [clang][NFC] Adjust TBAA Base Info API (PR #73263)

2023-12-01 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

sure, like so?

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


[clang] [clang][NFC] Adjust TBAA Base Info API (PR #73263)

2023-12-01 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan updated 
https://github.com/llvm/llvm-project/pull/73263

>From 2a312ddadae91ea52b184edaa0d19495c6e0f4a3 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Wed, 22 Nov 2023 20:45:38 -0500
Subject: [PATCH 1/2] [clang][NFC] Adjust TBAA Base Info API

I noticed a couple of minor issues with CodeGenTBAA::getBaseTypeInfo.

1) isValidBaseType explicitly checks for a reference type to return
false, but then also returns false for all non-record types. Just
remove that reference check.

2) All uses of CodeGenTBAA::getBaseTypeInfo from within that class are
when we've already checked the type isValidBaseType. The only case
where this isn't true is from outside the class. It seems better to
have two entry points in this case.  Adding a new
'maybeGetBaseTypeInfo' entry point for external uses that returns
nullptr for non valid base types.  (Open to other names?)

[This is part one of a pair of changes.]
---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +-
 clang/lib/CodeGen/CodeGenTBAA.cpp   |  9 +
 clang/lib/CodeGen/CodeGenTBAA.h | 11 ---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7cdf50a281cd278..e01fdc3579d88b8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1318,7 +1318,7 @@ llvm::MDNode *CodeGenModule::getTBAAStructInfo(QualType 
QTy) {
 llvm::MDNode *CodeGenModule::getTBAABaseTypeInfo(QualType QTy) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getBaseTypeInfo(QTy);
+  return TBAA->maybeGetBaseTypeInfo(QTy);
 }
 
 llvm::MDNode *CodeGenModule::getTBAAAccessTagInfo(TBAAAccessInfo Info) {
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..9b45a644937b8d9 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -95,8 +95,6 @@ static bool TypeHasMayAlias(QualType QTy) {
 
 /// Check if the given type is a valid base type to be used in access tags.
 static bool isValidBaseType(QualType QTy) {
-  if (QTy->isReferenceType())
-return false;
   if (const RecordType *TTy = QTy->getAs()) {
 const RecordDecl *RD = TTy->getDecl()->getDefinition();
 // Incomplete types are not valid base access types.
@@ -414,8 +412,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
 }
 
 llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
-  if (!isValidBaseType(QTy))
-return nullptr;
+  assert(isValidBaseType(QTy) && "Must be a valid base type");
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
   if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
@@ -428,6 +425,10 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
   return BaseTypeMetadataCache[Ty] = TypeNode;
 }
 
+llvm::MDNode *CodeGenTBAA::maybeGetBaseTypeInfo(QualType QTy) {
+  return isValidBaseType(QTy) ? getBaseTypeInfo(QTy) : nullptr;
+}
+
 llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {
   assert(!Info.isIncomplete() && "Access to an object of an incomplete type!");
 
diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h
index a65963596fe9def..53d77e1fefc4352 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.h
+++ b/clang/lib/CodeGen/CodeGenTBAA.h
@@ -166,6 +166,10 @@ class CodeGenTBAA {
   /// used to describe accesses to objects of the given base type.
   llvm::MDNode *getBaseTypeInfoHelper(const Type *Ty);
 
+  /// getBaseTypeInfo - Return metadata that describes the given base access
+  /// type. The type must be suitable.
+  llvm::MDNode *getBaseTypeInfo(QualType QTy);
+
 public:
   CodeGenTBAA(ASTContext &Ctx, llvm::Module &M, const CodeGenOptions &CGO,
   const LangOptions &Features, MangleContext &MContext);
@@ -187,9 +191,10 @@ class CodeGenTBAA {
   /// the given type.
   llvm::MDNode *getTBAAStructInfo(QualType QTy);
 
-  /// getBaseTypeInfo - Get metadata that describes the given base access type.
-  /// Return null if the type is not suitable for use in TBAA access tags.
-  llvm::MDNode *getBaseTypeInfo(QualType QTy);
+  /// maybeGetBaseTypeInfo - Get metadata that describes the given base access
+  /// type. Return null if the type is not suitable for use in TBAA access
+  /// tags.
+  llvm::MDNode *maybeGetBaseTypeInfo(QualType QTy);
 
   /// getAccessTagInfo - Get TBAA tag for a given memory access.
   llvm::MDNode *getAccessTagInfo(TBAAAccessInfo Info);

>From f4755f32880748100d0a3aa93836341033418f4d Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Fri, 1 Dec 2023 16:08:04 -0500
Subject: [PATCH 2/2] Rename internal getter to getValidBaseTypeInfo

---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +-
 clang/lib/CodeGen/CodeGenTBAA.cpp   | 18 ++
 clang/lib/CodeGen/CodeGenTBAA.h | 10 +-
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e01f

[clang-tools-extra] [clang-tidy] Fix false-positives in readability-container-size-empty (PR #74140)

2023-12-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Added support for size-like method returning signed type, and corrected false 
positive caused by always-false check for size bellow zero.

Closes #72619

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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (+28-4) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp 
(+52-6) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index f0357fb49eff331..19307b4cdcbe3ce 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -291,10 +291,14 @@ void ContainerSizeEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
OpCode == BinaryOperatorKind::BO_NE))
   return;
 
-// Always true, no warnings for that.
-if ((OpCode == BinaryOperatorKind::BO_GE && Value == 0 && ContainerIsLHS) 
||
-(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && !ContainerIsLHS))
-  return;
+// Always true/false, no warnings for that.
+if (Value == 0) {
+  if ((OpCode == BinaryOperatorKind::BO_GT && !ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_LT && ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_LE && !ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_GE && ContainerIsLHS))
+return;
+}
 
 // Do not warn for size > 1, 1 < size, size <= 1, 1 >= size.
 if (Value == 1) {
@@ -306,12 +310,32 @@ void ContainerSizeEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 }
 
+// Do not warn for size < 1, 1 > size, size <= 0, 0 >= size for non signed
+// types
+if ((OpCode == BinaryOperatorKind::BO_GT && Value == 1 &&
+ !ContainerIsLHS) ||
+(OpCode == BinaryOperatorKind::BO_LT && Value == 1 && ContainerIsLHS) 
||
+(OpCode == BinaryOperatorKind::BO_GE && Value == 0 &&
+ !ContainerIsLHS) ||
+(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && ContainerIsLHS)) 
{
+  const Expr *Container = ContainerIsLHS
+  ? BinaryOp->getLHS()->IgnoreImpCasts()
+  : BinaryOp->getRHS()->IgnoreImpCasts();
+  if (Container->getType()
+  .getCanonicalType()
+  .getNonReferenceType()
+  ->isSignedIntegerType())
+return;
+}
+
 if (OpCode == BinaryOperatorKind::BO_NE && Value == 0)
   Negation = true;
+
 if ((OpCode == BinaryOperatorKind::BO_GT ||
  OpCode == BinaryOperatorKind::BO_GE) &&
 ContainerIsLHS)
   Negation = true;
+
 if ((OpCode == BinaryOperatorKind::BO_LT ||
  OpCode == BinaryOperatorKind::BO_LE) &&
 !ContainerIsLHS)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc0625451..02b57f77132e369 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -402,7 +402,9 @@ Changes in existing checks
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals and support
-  ``length()`` method as an alternative to ``size()``.
+  ``length()`` method as an alternative to ``size()``. Resolved false positives
+  tied to negative values from size-like methods, and one triggered by size
+  checks below zero.
 
 - Improved :doc:`readability-function-size
   ` check configuration to use
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index 29ac86cf1b369c2..f010c2c665b1086 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -33,7 +33,7 @@ class TemplatedContainer {
 public:
   bool operator==(const TemplatedContainer& other) const;
   bool operator!=(const TemplatedContainer& other) const;
-  int size() const;
+  unsigned long size() const;
   bool empty() const;
 };
 
@@ -42,7 +42,7 @@ class PrivateEmpty {
 public:
   bool operator==(const PrivateEmpty& other) const;
   bool operator!=(const PrivateEmpty& other) const;
-  int size() const;
+  unsigned long size() const;
 private:
   bool empty() const;
 };
@@ -61,7 +61,7 @@ struct EnumSize {
 class Container {
 public:
   bool operator==(const Container& other) const;
-  int size() const;
+  unsigned long size() const;
   bool empty() const;
 };
 
@@ -70,13 +70,13 @@ class Derived : public 

[clang-tools-extra] [clang-tidy] Fix false-positives in readability-container-size-empty (PR #74140)

2023-12-01 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/74140

Added support for size-like method returning signed type, and corrected false 
positive caused by always-false check for size bellow zero.

Closes #72619

>From 2770caf83fe210cbff94e776c52593920a4cbf8d Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Fri, 1 Dec 2023 20:59:01 +
Subject: [PATCH] [clang-tidy] Fix false-positives in
 readability-container-size-empty

Added support for size-like method returning signed type,
and corrected false positive caused by always-false check
for size bellow zero.
---
 .../readability/ContainerSizeEmptyCheck.cpp   | 32 --
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +-
 .../readability/container-size-empty.cpp  | 58 +--
 3 files changed, 83 insertions(+), 11 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index f0357fb49eff331..19307b4cdcbe3ce 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -291,10 +291,14 @@ void ContainerSizeEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
OpCode == BinaryOperatorKind::BO_NE))
   return;
 
-// Always true, no warnings for that.
-if ((OpCode == BinaryOperatorKind::BO_GE && Value == 0 && ContainerIsLHS) 
||
-(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && !ContainerIsLHS))
-  return;
+// Always true/false, no warnings for that.
+if (Value == 0) {
+  if ((OpCode == BinaryOperatorKind::BO_GT && !ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_LT && ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_LE && !ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_GE && ContainerIsLHS))
+return;
+}
 
 // Do not warn for size > 1, 1 < size, size <= 1, 1 >= size.
 if (Value == 1) {
@@ -306,12 +310,32 @@ void ContainerSizeEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 }
 
+// Do not warn for size < 1, 1 > size, size <= 0, 0 >= size for non signed
+// types
+if ((OpCode == BinaryOperatorKind::BO_GT && Value == 1 &&
+ !ContainerIsLHS) ||
+(OpCode == BinaryOperatorKind::BO_LT && Value == 1 && ContainerIsLHS) 
||
+(OpCode == BinaryOperatorKind::BO_GE && Value == 0 &&
+ !ContainerIsLHS) ||
+(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && ContainerIsLHS)) 
{
+  const Expr *Container = ContainerIsLHS
+  ? BinaryOp->getLHS()->IgnoreImpCasts()
+  : BinaryOp->getRHS()->IgnoreImpCasts();
+  if (Container->getType()
+  .getCanonicalType()
+  .getNonReferenceType()
+  ->isSignedIntegerType())
+return;
+}
+
 if (OpCode == BinaryOperatorKind::BO_NE && Value == 0)
   Negation = true;
+
 if ((OpCode == BinaryOperatorKind::BO_GT ||
  OpCode == BinaryOperatorKind::BO_GE) &&
 ContainerIsLHS)
   Negation = true;
+
 if ((OpCode == BinaryOperatorKind::BO_LT ||
  OpCode == BinaryOperatorKind::BO_LE) &&
 !ContainerIsLHS)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc0625451..02b57f77132e369 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -402,7 +402,9 @@ Changes in existing checks
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals and support
-  ``length()`` method as an alternative to ``size()``.
+  ``length()`` method as an alternative to ``size()``. Resolved false positives
+  tied to negative values from size-like methods, and one triggered by size
+  checks below zero.
 
 - Improved :doc:`readability-function-size
   ` check configuration to use
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index 29ac86cf1b369c2..f010c2c665b1086 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -33,7 +33,7 @@ class TemplatedContainer {
 public:
   bool operator==(const TemplatedContainer& other) const;
   bool operator!=(const TemplatedContainer& other) const;
-  int size() const;
+  unsigned long size() const;
   bool empty() const;
 };
 
@@ -42,7 +42,7 @@ class PrivateEmpty {
 public:
   bool operator==(const PrivateEmpty& other) const;
   bool operator!=(const PrivateEmpty& other) const;
-  int size() const;
+  unsigned long size() const;
 private:
   bool empty() const;
 };
@@ -61,7

[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-12-01 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

The capability is more important than the naming. `__llvm_atomic_scoped_load` 
would be fine, with string literals or enum or macro controlling the scope. I 
also don't mind if it's a scoped argument or if we end up with 
`__llvm_atomic_seqcst_device_load`, embedding all of it in the symbol name. 
Clang can't currently instantiate IR atomics with scopes and it would be useful 
to do so.

If GCC picks a different set of names - maybe they go with defines for scope 
and we go with strings, and the names differ - we get to pick between renaming 
ours, adding aliases, ignoring the divergence.

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


[clang] [clang] Avoid recalculating TBAA base type info (PR #73264)

2023-12-01 Thread Nathan Sidwell via cfe-commits


@@ -418,14 +418,20 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
 return nullptr;
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-  if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
-return N;
 
-  // Note that the following helper call is allowed to add new nodes to the
-  // cache, which invalidates all its previously obtained iterators. So we
-  // first generate the node for the type and then add that node to the cache.
+  // nullptr is a valid value in the cache, so use find rather than []
+  auto I = BaseTypeMetadataCache.find(Ty);
+  if (I != BaseTypeMetadataCache.end())
+return I->second;
+
+  // First calculate the metadata, before recomputing the insertion point, as
+  // the helper can recursively call us.
   llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
-  return BaseTypeMetadataCache[Ty] = TypeNode;
+  LLVM_ATTRIBUTE_UNUSED auto inserted =
+  BaseTypeMetadataCache.try_emplace(Ty, TypeNode);

urnathan wrote:

done, will push when tests complete

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


[clang] [clang] Avoid recalculating TBAA base type info (PR #73264)

2023-12-01 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan updated 
https://github.com/llvm/llvm-project/pull/73264

>From e4c92cd687782743ba939becf7ea8862eea6a108 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Thu, 23 Nov 2023 11:30:12 -0500
Subject: [PATCH 1/2] [clang] Avoid recalculating TBAA base type info

I noticed that TBAA BaseTypeMetadataCache can legitimately store null
values, but it also uses that to mean 'no entry'. Thus nullptr entries
get continually recalculated. (AFAICT null entries can never become
non-null.)  This changes the hash lookup/insertion to use find and
try_emplace rather than the subscript operator.

While there, getBaseTypeInfoHelper will insert non-null values into
the hashtable itself, but simply return nullptr values.  The only
caller, getBaseTypeInfo unconditionally inserts the value anyway. It
seems clearer to let getBaseTypeInfo do the insertion and
getBaseTypeInfoHelper merely computes.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..94dc304bfc243b9 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -342,7 +342,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
   // field. Virtual bases are more complex and omitted, but avoid an
   // incomplete view for NewStructPathTBAA.
   if (CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases() != 0)
-return BaseTypeMetadataCache[Ty] = nullptr;
+return nullptr;
   for (const CXXBaseSpecifier &B : CXXRD->bases()) {
 if (B.isVirtual())
   continue;
@@ -354,7 +354,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
  ? getBaseTypeInfo(BaseQTy)
  : getTypeInfo(BaseQTy);
 if (!TypeNode)
-  return BaseTypeMetadataCache[Ty] = nullptr;
+  return nullptr;
 uint64_t Offset = Layout.getBaseClassOffset(BaseRD).getQuantity();
 uint64_t Size =
 Context.getASTRecordLayout(BaseRD).getDataSize().getQuantity();
@@ -378,7 +378,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
   llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
   getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
   if (!TypeNode)
-return BaseTypeMetadataCache[Ty] = nullptr;
+return nullptr;
 
   uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
   uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
@@ -418,14 +418,20 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
 return nullptr;
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-  if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
-return N;
 
-  // Note that the following helper call is allowed to add new nodes to the
-  // cache, which invalidates all its previously obtained iterators. So we
-  // first generate the node for the type and then add that node to the cache.
+  // nullptr is a valid value in the cache, so use find rather than []
+  auto I = BaseTypeMetadataCache.find(Ty);
+  if (I != BaseTypeMetadataCache.end())
+return I->second;
+
+  // First calculate the metadata, before recomputing the insertion point, as
+  // the helper can recursively call us.
   llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
-  return BaseTypeMetadataCache[Ty] = TypeNode;
+  LLVM_ATTRIBUTE_UNUSED auto inserted =
+  BaseTypeMetadataCache.try_emplace(Ty, TypeNode);
+  assert(inserted.second && "BaseType metadata was already inserted");
+
+  return TypeNode;
 }
 
 llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {

>From fee3b7407ab6fe73476eed82e387cceb9b6ef88c Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Fri, 1 Dec 2023 15:58:51 -0500
Subject: [PATCH 2/2] Use insert not try_emplace

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

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 94dc304bfc243b9..5906b14dd93cf08 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -428,7 +428,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
   // the helper can recursively call us.
   llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
   LLVM_ATTRIBUTE_UNUSED auto inserted =
-  BaseTypeMetadataCache.try_emplace(Ty, TypeNode);
+  BaseTypeMetadataCache.insert({Ty, TypeNode});
   assert(inserted.second && "BaseType metadata was already inserted");
 
   return TypeNode;

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


[llvm] [clang] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-01 Thread Teresa Johnson via cfe-commits


@@ -300,12 +316,8 @@ getIRPGONameForGlobalObject(const GlobalObject &GO,
 GlobalValue::LinkageTypes Linkage,
 StringRef FileName) {
   SmallString<64> Name;
-  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
-Name.append(FileName.empty() ? "" : FileName);
-Name.append(";");
-  }
   Mangler().getNameWithPrefix(Name, &GO, /*CannotUsePrivateLabel=*/true);

teresajohnson wrote:

Was PGO broken in general before D156569? Or is this specific to 
`-symbol-ordering-file` and `-order_file`?

Also, it looks like some of the main changes here by the mangler for objective 
C are to strip the "\01" prefix. Is this different than the support to remove 
the '\1' mangling escape in getGlobalIdentifier()?

Trying to figure out how we keep these interfaces in sync to avoid more issues 
with ICP...

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


[llvm] [clang] [compiler-rt] [clang-tools-extra] [flang] [bpi] Reuse the AsmWriter's BB naming scheme (PR #73593)

2023-12-01 Thread Matthias Braun via cfe-commits

https://github.com/MatzeB commented:

Consider using `utils/update_analyze_test_checks.py` to create the check 
lines...

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


[clang] [flang][driver][RFC] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-01 Thread Michael Klemm via cfe-commits

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


[clang] [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-01 Thread Michael Klemm via cfe-commits

mjklemm wrote:

This WIP for now, as I still have to make the changes for MSVC.  But it's good 
enough to discuss if this is a viable solution.

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


  1   2   3   4   >