[clang-tools-extra] [clangd] Add `HeaderInsertion` yaml config option (PR #128503)

2025-04-23 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> unfortunately, LLVM's command-line argument framework doesn't allow us to 
> distinguish between "the option's value is `IWYU` because the flag 
> `--header-insertion=iwyu` appeared in the command line" and "the option's 
> value is `IWYU` because no `--header-insertion` flag appeared in the command 
> line and `IWYU` is the default"

It looks like I was mistaken about this: there is an 
[`Option::getNumOccurrences()`](https://searchfox.org/llvm/rev/3d91a71223801bb73ab3e4ff8ab3f883639ed79f/llvm/include/llvm/Support/CommandLine.h#399)
 method that allows us to distinguish between these two cases.

So, if you'd like, we could revisit this and make the behaviour more consistent 
(e.g. so that `--header-insertion` always overrides `HeaderInsertion` if it was 
actually passed, or vice versa).

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


[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)

2025-04-23 Thread via cfe-commits

jeremyd2019 wrote:

I'm fighting the tests on Windows - the hurd test I started from had `// 
UNSUPPORTED: system-windows` at the top, probably because they weren't 
interested in messing around with backslashes and .exe extensions.  I don't 
know if the cross test will work right for the path to the cross as, is there 
some way to annotate just one test in the file as unsupported on Windows?

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


[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)

2025-04-23 Thread via cfe-commits

https://github.com/jeremyd2019 updated 
https://github.com/llvm/llvm-project/pull/135691

>From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001
From: Jeremy Drake 
Date: Mon, 14 Apr 2025 10:37:59 -0700
Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain

Add a new Cygwin toolchain that just goes through the motions to
initialize the Generic_GCC base properly.  This allows removing some
old, almost certainly wrong hard-coded paths from
Lex/InitHeaderSearch.cpp

Signed-off-by: Jeremy Drake 
---
 clang/lib/Driver/CMakeLists.txt|   1 +
 clang/lib/Driver/Driver.cpp|   4 +
 clang/lib/Driver/ToolChains/Cygwin.cpp | 109 +
 clang/lib/Driver/ToolChains/Cygwin.h   |  36 
 clang/lib/Driver/ToolChains/Gnu.cpp|  21 +
 clang/lib/Lex/InitHeaderSearch.cpp |  86 +--
 6 files changed, 174 insertions(+), 83 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp
 create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h

diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 5bdb6614389cf..e72525e99d517 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -51,6 +51,7 @@ add_clang_library(clangDriver
   ToolChains/CrossWindows.cpp
   ToolChains/CSKYToolChain.cpp
   ToolChains/Cuda.cpp
+  ToolChains/Cygwin.cpp
   ToolChains/Darwin.cpp
   ToolChains/DragonFly.cpp
   ToolChains/Flang.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 90d8e823d1d02..9b2264bbc9eaa 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -17,6 +17,7 @@
 #include "ToolChains/Clang.h"
 #include "ToolChains/CrossWindows.h"
 #include "ToolChains/Cuda.h"
+#include "ToolChains/Cygwin.h"
 #include "ToolChains/Darwin.h"
 #include "ToolChains/DragonFly.h"
 #include "ToolChains/FreeBSD.h"
@@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   case llvm::Triple::GNU:
 TC = std::make_unique(*this, Target, Args);
 break;
+  case llvm::Triple::Cygnus:
+TC = std::make_unique(*this, Target, Args);
+break;
   case llvm::Triple::Itanium:
 TC = std::make_unique(*this, Target,
   Args);
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp 
b/clang/lib/Driver/ToolChains/Cygwin.cpp
new file mode 100644
index 0..c310f096a5d74
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -0,0 +1,109 @@
+//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- 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
+//
+//===--===//
+
+#include "Cygwin.h"
+#include "CommonArgs.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+using tools::addPathIfExists;
+
+Cygwin::Cygwin(const Driver &D, const llvm::Triple &Triple, const ArgList 
&Args)
+: Generic_GCC(D, Triple, Args) {
+  GCCInstallation.init(Triple, Args);
+  std::string SysRoot = computeSysRoot();
+  ToolChain::path_list &PPaths = getProgramPaths();
+
+  Generic_GCC::PushPPaths(PPaths);
+
+  path_list &Paths = getFilePaths();
+
+  Generic_GCC::AddMultiarchPaths(D, SysRoot, "lib", Paths);
+
+  // Similar to the logic for GCC above, if we are currently running Clang
+  // inside of the requested system root, add its parent library path to those
+  // searched.
+  // FIXME: It's not clear whether we should use the driver's installed
+  // directory ('Dir' below) or the ResourceDir.
+  if (StringRef(D.Dir).starts_with(SysRoot))
+addPathIfExists(D, D.Dir + "/../lib", Paths);
+
+  addPathIfExists(D, SysRoot + "/lib", Paths);
+  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  addPathIfExists(D, SysRoot + "/usr/lib/w32api", Paths);
+}
+
+llvm::ExceptionHandling Cygwin::GetExceptionModel(const ArgList &Args) const {
+  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 
||
+  getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
+return llvm::ExceptionHandling::WinEH;
+  return llvm::ExceptionHandling::DwarfCFI;
+}
+
+void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+   ArgStringList &CC1Args) const {
+  const Driver &D = getDriver();
+  std::string SysRoot = computeSysRoot();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
+addSystemInclude(D

[clang] [docs] Fix the use of word "dependent" and other typos in the C++ Modules Doc (PR #136719)

2025-04-23 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -477,21 +476,21 @@ When the ``-fmodules-embed-all-files`` flag are enabled, 
Clang explicitly emits
 code into the BMI file, the contents of the BMI file contain a sufficiently 
verbose
 representation to reproduce the original source file.
 
-:sup:`1`` Input files: The source files which took part in the compilation of 
the BMI.
-For example:
+.. [1] Input files: The source files which took part in the compilation of the 
BMI.

necto wrote:

Here is how it looks like:
![2025-04-23T09:13:50,035090911+02:00](https://github.com/user-attachments/assets/3e096ff3-6dbe-4848-8b1c-b79de555275e)

And when clicked:
![2025-04-23T09:14:08,105023675+02:00](https://github.com/user-attachments/assets/dd1a1b97-7282-4430-93fd-c65ec815d8b0)

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


[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)

2025-04-23 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> I'm fighting the tests on Windows - the hurd test I started from had `// 
> UNSUPPORTED: system-windows` at the top, probably because they weren't 
> interested in messing around with backslashes and .exe extensions. I don't 
> know if the cross test will work right for the path to the cross as, is there 
> some way to annotate just one test in the file as unsupported or expected 
> fail or something on Windows?
> 
> (Locally, I ran the tests on Cygwin and they worked fine)
> 
> Looking at the output, it looks like maybe just a slash vs backslash again, 
> so maybe it can be made to match on Windows

If it's just a slash issue, then applying copious amounts of regexes (e.g. 
`{{/}}` to match both) may help.

For skipping smaller sections of tests, you can apply `%if !system-windows %{ 
... %}` around a bit of the RUN commands, see 
f5a93c5f2a4d0916c975bbf028768d58a29b6b73 for an example of that. If it's a 
bigger issue and relevant to most of a test file, it may be worth splitting 
into a separate file which can be marked `// UNSUPPORTED: system-windows`.

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


[clang] [docs] Fix the use of word "dependent" and other typos in the C++ Modules Doc (PR #136719)

2025-04-23 Thread Chuanqi Xu via cfe-commits


@@ -477,21 +476,21 @@ When the ``-fmodules-embed-all-files`` flag are enabled, 
Clang explicitly emits
 code into the BMI file, the contents of the BMI file contain a sufficiently 
verbose
 representation to reproduce the original source file.
 
-:sup:`1`` Input files: The source files which took part in the compilation of 
the BMI.
-For example:
+.. [1] Input files: The source files which took part in the compilation of the 
BMI.

ChuanqiXu9 wrote:

Fine enough. Thanks.

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


[clang] da8f2d5 - Revert "[clang-format] Allow breaking before kw___attribute (#128623)"

2025-04-23 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2025-04-22T23:49:26-07:00
New Revision: da8f2d52423bb82b5d4e75cff3018704effe044f

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

LOG: Revert "[clang-format] Allow breaking before kw___attribute (#128623)"

This reverts commit 8fc8a84e23471fe56214e68706addc712b5a2949, which caused a
regression.

Fixes #136675.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 6d861d19117e2..3e17c688dbcce 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -6242,8 +6242,6 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
 TT_ClassHeadName, tok::kw_operator)) {
 return true;
   }
-  if (Right.isAttribute())
-return true;
   if (Left.is(TT_PointerOrReference))
 return false;
   if (Right.isTrailingComment()) {
@@ -6388,6 +6386,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
   tok::less, tok::coloncolon);
   }
 
+  if (Right.isAttribute())
+return true;
+
   if (Right.is(tok::l_square) && Right.is(TT_AttributeSquare))
 return Left.isNot(TT_AttributeSquare);
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f1b3b7dd8c0c3..8543c1b565d6d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12645,9 +12645,6 @@ TEST_F(FormatTest, UnderstandsAttributes) {
   verifyFormat("a __attribute__((unused))\n"
"aaa(int i);");
   verifyFormat("__attribute__((nodebug)) ::qualified_type f();");
-  verifyFormat(
-  "RenderWidgetHostViewCocoa *\n"
-  "__attribute__((objc_precise_lifetime)) keepSelfAlive = self;");
   FormatStyle AfterType = getLLVMStyle();
   AfterType.BreakAfterReturnType = FormatStyle::RTBS_All;
   verifyFormat("__attribute__((nodebug)) void\n"



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


[clang] [docs] Fix the use of word "dependent" and other typos in the C++ Modules Doc (PR #136719)

2025-04-23 Thread Arseniy Zaostrovnykh via cfe-commits

https://github.com/necto updated 
https://github.com/llvm/llvm-project/pull/136719

>From 095e00202104240797e21c941be7f6256850c534 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Tue, 22 Apr 2025 15:24:20 +0200
Subject: [PATCH 1/4] [docs] Fix the use of "dependent" and "dependant" in the
 C++ Modules Doc

"Dependant BMI" / "Dependent BMI" was used incorrectly in the
documentation:
"Dependent BMI" refers to a BMI that depends on the current TU, but it
was used for the BMI that current TU depends on.

I replaced all the mentions with "BMI dependency".
---
 clang/docs/StandardCPlusPlusModules.rst | 37 -
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 93edce0cf90b7..8b05984e0d9dd 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -305,17 +305,17 @@ Therefore, none of the following names are valid by 
default:
 Using a reserved module name is strongly discouraged, but
 ``-Wno-reserved-module-identifier`` can be used to suppress the warning.
 
-Specifying dependent BMIs
-~
+Specifying BMI dependencies
+~~~
 
-There are 3 ways to specify a dependent BMI:
+There are 3 ways to specify a BMI dependency:
 
 1. ``-fprebuilt-module-path=``.
 2. ``-fmodule-file=`` (Deprecated).
 3. ``-fmodule-file==``.
 
 The ``-fprebuilt-module-path`` option specifies the path to search for
-dependent BMIs. Multiple paths may be specified, similar to using ``-I`` to
+BMI dependencies. Multiple paths may be specified, similar to using ``-I`` to
 specify a search path for header files. When importing a module ``M``, the
 compiler looks for ``M.pcm`` in the directories specified by
 ``-fprebuilt-module-path``. Similarly, when importing a partition module unit
@@ -337,9 +337,8 @@ When these options are specified in the same invocation of 
the compiler, the
 ``-fmodule-file==``, which takes precedence over
 ``-fprebuilt-module-path=``.
 
-Note: all dependant BMIs must be specified explicitly, either directly or
-indirectly dependent BMIs explicitly. See
-https://github.com/llvm/llvm-project/issues/62707 for details.
+Note: all BMI dependencies must be specified explicitly, either directly or
+indirectly. See https://github.com/llvm/llvm-project/issues/62707 for details.
 
 When compiling a ``module implementation unit``, the BMI of the corresponding
 ``primary module interface unit`` must be specified because a module
@@ -1192,14 +1191,14 @@ them to ``your_library_imported.h`` too.
 Importing modules
 ~
 
-When there are dependent libraries providing modules, they should be imported
-in your module as well. Many existing libraries will fall into this category
-once the ``std`` module is more widely available.
+When there are library dependencies providing modules, the module dependencies
+should be imported in your module as well. Many existing libraries will fall
+into this category once the ``std`` module is more widely available.
 
-All dependent libraries providing modules
-^
+All library dependencies providing modules
+^^
 
-Of course, most of the complexity disappears if all the dependent libraries
+Of course, most of the complexity disappears if all the library dependencies
 provide modules.
 
 Headers need to be converted to include third-party headers conditionally. 
Then,
@@ -1260,8 +1259,8 @@ Non-exported ``using`` declarations are unnecessary if 
using implementation
 module units. Instead, third-party modules can be imported directly in
 implementation module units.
 
-Partial dependent libraries providing modules
-^
+Partial library dependencies providing modules
+^^
 
 If the library has to mix the use of ``include`` and ``import`` in its module,
 the primary goal is still the removal of duplicated declarations in translation
@@ -1562,11 +1561,11 @@ file as a header. For example:
   $ clang++ -std=c++20 -fmodule-header=system -xc++-header iostream -o 
iostream.pcm
   $ clang++ -std=c++20 -fmodule-file=iostream.pcm use.cpp
 
-How to specify dependent BMIs
-~
+How to specify BMI dependencies
+~~~
 
-``-fmodule-file`` can be used to specify a dependent BMI (or multiple times for
-more than one dependent BMI).
+``-fmodule-file`` can be used to specify a BMI dependency (or multiple times 
for
+more than one BMI dependency).
 
 With the existing implementation, ``-fprebuilt-module-path`` cannot be used for
 header units (because they are nominally anonymous). For header units, use

>From 1c7c534bfbda2d1d2f1ceb923970713dc35a2c62 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Tue, 22 Apr 2025 15:42:29 +0200
Subject: [PATCH 2/4] minor typos

---
 clan

[clang] [docs] Fix the use of word "dependent" and other typos in the C++ Modules Doc (PR #136719)

2025-04-23 Thread Arseniy Zaostrovnykh via cfe-commits

necto wrote:

I have no merge access yet, so I'll appreciate if someone click on the "merge" 
button

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


[clang] ae47f25 - [docs] Fix the use of word "dependent" and other typos in the C++ Modules Doc (#136719)

2025-04-23 Thread via cfe-commits

Author: Arseniy Zaostrovnykh
Date: 2025-04-23T15:34:54+08:00
New Revision: ae47f2533709058d3442a34af783d8cd721b4177

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

LOG: [docs] Fix the use of word "dependent" and other typos in the C++ Modules 
Doc (#136719)

"Dependant BMI" / "Dependent BMI" was used incorrectly in the
documentation:
"Dependent BMI" refers to a BMI that depends on the current TU, but it
was used for the BMI that current TU depends on.

I replaced all the mentions with "BMI dependency".

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 93edce0cf90b7..2ca014f3fd831 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -305,17 +305,17 @@ Therefore, none of the following names are valid by 
default:
 Using a reserved module name is strongly discouraged, but
 ``-Wno-reserved-module-identifier`` can be used to suppress the warning.
 
-Specifying dependent BMIs
-~
+Specifying BMI dependencies
+~~~
 
-There are 3 ways to specify a dependent BMI:
+There are 3 ways to specify a BMI dependency:
 
 1. ``-fprebuilt-module-path=``.
 2. ``-fmodule-file=`` (Deprecated).
 3. ``-fmodule-file==``.
 
 The ``-fprebuilt-module-path`` option specifies the path to search for
-dependent BMIs. Multiple paths may be specified, similar to using ``-I`` to
+BMI dependencies. Multiple paths may be specified, similar to using ``-I`` to
 specify a search path for header files. When importing a module ``M``, the
 compiler looks for ``M.pcm`` in the directories specified by
 ``-fprebuilt-module-path``. Similarly, when importing a partition module unit
@@ -337,9 +337,8 @@ When these options are specified in the same invocation of 
the compiler, the
 ``-fmodule-file==``, which takes precedence over
 ``-fprebuilt-module-path=``.
 
-Note: all dependant BMIs must be specified explicitly, either directly or
-indirectly dependent BMIs explicitly. See
-https://github.com/llvm/llvm-project/issues/62707 for details.
+Note: all BMI dependencies must be specified explicitly, either directly or
+indirectly. See https://github.com/llvm/llvm-project/issues/62707 for details.
 
 When compiling a ``module implementation unit``, the BMI of the corresponding
 ``primary module interface unit`` must be specified because a module
@@ -380,7 +379,7 @@ For example, the traditional compilation processes for 
headers are like:
   hdr2.h  --, |
   src2.cpp -+> clang++ src2.cpp --> src2.o ---'
 
-And the compilation process for module units are like:
+And the compilation processes for module units are like:
 
 .. code-block:: text
 
@@ -435,7 +434,7 @@ non-module-unit uses need to be consistent. Consider the 
following example:
   $ clang++ -std=c++23 Use.cpp -fprebuilt-module-path=.
 
 Clang rejects the example due to the inconsistent language standard modes. Not
-all compiler options are language dialect options, though. For example:
+all compiler options are language-dialect options, though. For example:
 
 .. code-block:: console
 
@@ -465,7 +464,7 @@ translation units.
 Source Files Consistency
 
 
-Clang may open the input files\ :sup:`1`` of a BMI during the compilation. 
This implies that
+Clang may open the input files [1]_ of a BMI during the compilation. This 
implies that
 when Clang consumes a BMI, all the input files need to be present in the 
original path
 and with the original contents.
 
@@ -477,21 +476,21 @@ When the ``-fmodules-embed-all-files`` flag are enabled, 
Clang explicitly emits
 code into the BMI file, the contents of the BMI file contain a sufficiently 
verbose
 representation to reproduce the original source file.
 
-:sup:`1`` Input files: The source files which took part in the compilation of 
the BMI.
-For example:
+.. [1] Input files: The source files which took part in the compilation of the 
BMI.
+   For example:
 
-.. code-block:: c++
+   .. code-block:: c++
 
-  // M.cppm
-  module;
-  #include "foo.h"
-  export module M;
+ // M.cppm
+ module;
+ #include "foo.h"
+ export module M;
 
-  // foo.h
-  #pragma once
-  #include "bar.h"
+ // foo.h
+ #pragma once
+ #include "bar.h"
 
-The ``M.cppm``, ``foo.h`` and ``bar.h`` are input files for the BMI of 
``M.cppm``.
+   The ``M.cppm``, ``foo.h`` and ``bar.h`` are input files for the BMI of 
``M.cppm``.
 
 Object definition consistency
 ^
@@ -781,8 +780,8 @@ for the BMI being produced. This ensures that build systems 
are not required to
 transitively imported modules when deciding whether to recompile.
 
 What

[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -524,7 +523,9 @@ CIRGenTypes::arrangeCIRFunctionInfo(CanQualType returnType) 
{
   if (retInfo.canHaveCoerceToType() && retInfo.getCoerceToType() == nullptr)
 retInfo.setCoerceToType(convertType(fi->getReturnType()));
 
-  assert(!cir::MissingFeatures::opCallArgs());
+  for (auto &i : fi->arguments())

andykaylor wrote:

Don't use auto here.

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


[clang] [clang] Adding an API to create a `CXStringSet` from a Vector of `StringRef`s (PR #136773)

2025-04-23 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

Hi @AaronBallman ! Again I appreciate your suggestion. I ran into some 
complexities when adding a test. It is precisely that this is a very internal 
API that is giving me some trouble. Since `clang/tools/libclang/CXString.h` is 
not an exposed header, I cannot really even add it to the clang unit tests, 
unless I expose (some of) the header's content through a more public API (not 
necessarily the C-APIs). 

Do you have suggestions other than landing this PR as is? One possible 
alternative is to move `clang/tools/libclang/CXString.h` into a directory in 
`clang/include/clang/`, and then we can add the unit test. The problem with 
this alternative is that it seems to be too big a change for what we are aiming 
for here. 

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


[clang] [clang] Enable making the module build stack thread-safe (PR #137059)

2025-04-23 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/137059

This PR makes another piece of the `CompilerInstance::cloneForModuleCompile()` 
result thread-safe: the module build stack. This data structure is used to 
detect cyclic dependencies between modules. The problem is that it uses 
`FullSourceLoc` which refers to the `SourceManager` of the parent 
`CompilerInstance`: if two threads happen to execute `CompilerInstance`s cloned 
from the same parent concurrently, and both discover a dependency cycle, they 
may concurrently access the parent `SourceManager` when emitting the 
diagnostic, creating a data race.

In this PR, we prevent this by keeping the stack empty and moving the 
responsibility of cycle detection to the client. The client can recreate the 
same module build stack externally and ensure thread-safety by enforcing mutual 
exclusion.

>From 5bcb9f27d41201db8a4e7ba4c498048a50e3f7dc Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Wed, 23 Apr 2025 13:04:54 -0700
Subject: [PATCH] [clang] Enable making the module build stack thread-safe

---
 clang/lib/Frontend/CompilerInstance.cpp | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 8596dd03148e8..1526ea53add7d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1240,11 +1240,15 @@ std::unique_ptr 
CompilerInstance::cloneForModuleCompileImpl(
   Instance.createSourceManager(Instance.getFileManager());
   SourceManager &SourceMgr = Instance.getSourceManager();
 
-  // Note that this module is part of the module build stack, so that we
-  // can detect cycles in the module graph.
-  SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
-  SourceMgr.pushModuleBuildStack(ModuleName,
- FullSourceLoc(ImportLoc, getSourceManager()));
+  if (ThreadSafeConfig) {
+// Detecting cycles in the module graph is responsibility of the client.
+  } else {
+// Note that this module is part of the module build stack, so that we
+// can detect cycles in the module graph.
+SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
+SourceMgr.pushModuleBuildStack(
+ModuleName, FullSourceLoc(ImportLoc, getSourceManager()));
+  }
 
   // Make a copy for the new instance.
   Instance.FailedModules = FailedModules;

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


[clang] [clang] Enable making the module build stack thread-safe (PR #137059)

2025-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

This PR makes another piece of the `CompilerInstance::cloneForModuleCompile()` 
result thread-safe: the module build stack. This data structure is used to 
detect cyclic dependencies between modules. The problem is that it uses 
`FullSourceLoc` which refers to the `SourceManager` of the parent 
`CompilerInstance`: if two threads happen to execute `CompilerInstance`s cloned 
from the same parent concurrently, and both discover a dependency cycle, they 
may concurrently access the parent `SourceManager` when emitting the 
diagnostic, creating a data race.

In this PR, we prevent this by keeping the stack empty and moving the 
responsibility of cycle detection to the client. The client can recreate the 
same module build stack externally and ensure thread-safety by enforcing mutual 
exclusion.

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


1 Files Affected:

- (modified) clang/lib/Frontend/CompilerInstance.cpp (+9-5) 


``diff
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 8596dd03148e8..1526ea53add7d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1240,11 +1240,15 @@ std::unique_ptr 
CompilerInstance::cloneForModuleCompileImpl(
   Instance.createSourceManager(Instance.getFileManager());
   SourceManager &SourceMgr = Instance.getSourceManager();
 
-  // Note that this module is part of the module build stack, so that we
-  // can detect cycles in the module graph.
-  SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
-  SourceMgr.pushModuleBuildStack(ModuleName,
- FullSourceLoc(ImportLoc, getSourceManager()));
+  if (ThreadSafeConfig) {
+// Detecting cycles in the module graph is responsibility of the client.
+  } else {
+// Note that this module is part of the module build stack, so that we
+// can detect cycles in the module graph.
+SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
+SourceMgr.pushModuleBuildStack(
+ModuleName, FullSourceLoc(ImportLoc, getSourceManager()));
+  }
 
   // Make a copy for the new instance.
   Instance.FailedModules = FailedModules;

``




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


[clang] [Clang,debuginfo] added vtt parameter in destructor DISubroutineType (PR #130674)

2025-04-23 Thread via cfe-commits
Markus =?utf-8?q?Gscho=C3=9Fmann?= ,
Markus =?utf-8?q?Gscho=C3=9Fmann?= ,
Markus =?utf-8?q?Gscho=C3=9Fmann?= ,
Markus =?utf-8?q?Gscho=C3=9Fmann?= 
Message-ID:
In-Reply-To: 


lexi-nadia wrote:

I believe this commit introduced a crash. Here's a minimal repro:

```
class Foo {
public:
  virtual ~Foo() noexcept;
};

class Bar : public Foo {
public:
  Bar() noexcept {}
  ~Bar() noexcept override;
};
```

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


[clang] [llvm] [TargetVerifier][AMDGPU] Add TargetVerifier. (PR #123609)

2025-04-23 Thread via cfe-commits

jofrn wrote:

There is still a need for other such rules that we may not want to apply more 
generally though. For calling convention, that is target specific, and it could 
go into its own pass.

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


[clang] [Clang][NFC] Use temporary instead of one use local variable when creating APValue (PR #137029)

2025-04-23 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)

2025-04-23 Thread via cfe-commits


@@ -0,0 +1,77 @@
+// RUN: %clang -### %s --target=i686-pc-windows-cygnus 
--sysroot=%S/Inputs/basic_cygwin_tree \
+// RUN:   -resource-dir=%S/Inputs/resource_dir \
+// RUN:   --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s
+// CHECK:  "-cc1"
+// CHECK-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10"
+// CHECK-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/i686-pc-cygwin/c++/10"
+// CHECK-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10/backward"
+// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{(/|)}}include"
+// CHECK-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../i686-pc-cygwin/include"
+// CHECK-SAME: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+// CHECK-SAME: {{^}} "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include/w32api"
+// CHECK-SAME: "-femulated-tls"
+// CHECK-SAME: "-exception-model=dwarf"
+// CHECK:  "{{.*}}gcc{{(\.exe)?}}"
+// CHECK-SAME: "-m32"
+
+// RUN: %clang -### %s --target=i686-pc-cygwin 
--sysroot=%S/Inputs/basic_cygwin_tree \
+// RUN:   --stdlib=platform -static 2>&1 | FileCheck 
--check-prefix=CHECK-STATIC %s
+// CHECK-STATIC:  "-cc1" "-triple" "i686-pc-windows-cygnus"
+// CHECK-STATIC-SAME: "-static-define"
+// CHECK-STATIC:  "{{.*}}gcc{{(\.exe)?}}"

jeremyd2019 wrote:

yes.  Once you are not calling GCC, you need to teach the driver about the 
default library search paths (which should already be taken care of), and 
default libraries, and the startup object files.  Which is probably ultimately 
necessary, but for now, we can just keep calling gcc.

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


[clang] [CIR] Create CIR_TypedAttr common class (PR #136852)

2025-04-23 Thread Henrich Lauko via cfe-commits

xlauko wrote:

### Merge activity

* **Apr 23, 5:00 PM EDT**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/136852).


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


[clang] [CIR] Create CIR_TypedAttr common class (PR #136852)

2025-04-23 Thread Henrich Lauko via cfe-commits

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


[clang] [llvm] [LLVM][Clang][Cygwin] Fix building Clang for Cygwin (PR #134494)

2025-04-23 Thread via cfe-commits
Mateusz =?utf-8?q?Mikuła?= ,
Mateusz =?utf-8?q?Mikuła?= ,
Mateusz =?utf-8?q?Mikuła?= ,
Mateusz =?utf-8?q?Mikuła?= 
Message-ID:
In-Reply-To: 



@@ -29,7 +29,6 @@
 #ifdef __CYGWIN__
 #include 
 #include 
-#define _WIN32 1
 #endif

jeremyd2019 wrote:

My updated version of this commit, removing the no-longer-reachable code is 
https://github.com/jeremyd2019/llvm-project/commit/f64e65460904de4bdaa2b28ad1d76fa471c4793c

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


[clang] [llvm] [LLVM][Clang][Cygwin] Fix building Clang for Cygwin (PR #134494)

2025-04-23 Thread via cfe-commits
Mateusz =?utf-8?q?Mikuła?= ,
Mateusz =?utf-8?q?Mikuła?= ,
Mateusz =?utf-8?q?Mikuła?= ,
Mateusz =?utf-8?q?Mikuła?= 
Message-ID:
In-Reply-To: 


jeremyd2019 wrote:

@mstorsjo maybe you could look at this PR too?  sorry to bug you so much, but 
it doesn't seem like anyone else is very interested in cygwin here 😉 

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+  fi->required = required;
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];
 
   return fi;
 }
 
+cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
+  bool inserted = functionsBeingProcessed.insert(&fi).second;
+  assert(inserted && "Recursively being processed?");
+
+  mlir::Type resultType = nullptr;

andykaylor wrote:

Does initializing this with nullptr here do anything? I would have expected 
that to be the default initial state.

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


[clang] [clang-tools-extra] [lldb] Reland: [clang] preserve class type sugar when taking pointer to member (PR #132401)

2025-04-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@emaxx-google thanks for the reproducer.

I will be off to C++Now soon, so it's unlikely I will have time to take a look 
at
that in the next two weeks, sorry about that.

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


[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime-2` running on `rocm-worker-hw-02` while building 
`clang` at step 7 "Add check check-clang".

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


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

```
Step 7 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang 
-cc1 -internal-isystem 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP # RUN: at line 1
+ /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang 
-cc1 -internal-isystem 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP
error: diagnostics with 'note' severity expected but not seen: 
  File 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
error: diagnostics with 'note' severity seen but not expected: 
  File 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
2 errors generated.

--




```



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


[clang] 55160e6 - [ConstEval] Fix crash when comparing strings past the end (#137078)

2025-04-23 Thread via cfe-commits

Author: Henrik G. Olsson
Date: 2025-04-23T16:41:21-07:00
New Revision: 55160e6a89820f219eaa218fa02da2006213ed2c

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

LOG: [ConstEval] Fix crash when comparing strings past the end (#137078)

When `ArePotentiallyOverlappingStringLiterals`, added in
https://github.com/llvm/llvm-project/pull/109208, compares string
literals it drops the front of the string with the greatest offset from
its base pointer. The number of characters dropped is equal to the
difference between the two strings' offsets from their base pointers.
This would trigger an assert when the resulting offset is past the end
of the object. Not only are one-past-the-end pointers legal constructs,
the compiler should not crash even when faced with illegal constructs.

rdar://149865910

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/AST/ByteCode/cxx20.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f598ef5929aa4..7c933f47bf7f0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2232,10 +2232,15 @@ static bool 
ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info,
   // within RHS. We don't need to look at the characters of one string that
   // would appear before the start of the other string if they were merged.
   CharUnits Offset = RHS.Offset - LHS.Offset;
-  if (Offset.isNegative())
+  if (Offset.isNegative()) {
+if (LHSString.Bytes.size() < (size_t)-Offset.getQuantity())
+  return false;
 LHSString.Bytes = LHSString.Bytes.drop_front(-Offset.getQuantity());
-  else
+  } else {
+if (RHSString.Bytes.size() < (size_t)Offset.getQuantity())
+  return false;
 RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity());
+  }
 
   bool LHSIsLonger = LHSString.Bytes.size() > RHSString.Bytes.size();
   StringRef Longer = LHSIsLonger ? LHSString.Bytes : RHSString.Bytes;

diff  --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 42e6ae33e92e4..4c1b1592896c9 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -119,6 +119,15 @@ constexpr auto b3 = name1() == name1(); // ref-error 
{{must be initialized by a
 constexpr auto b4 = name1() == name2();
 static_assert(!b4);
 
+constexpr auto bar(const char *p) { return p + __builtin_strlen(p); }
+constexpr auto b5 = bar(p1) == p1;
+static_assert(!b5);
+constexpr auto b6 = bar(p1) == ""; // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{comparison of addresses of 
potentially overlapping literals}}
+constexpr auto b7 = bar(p1) + 1 == ""; // both-error {{must be initialized by 
a constant expression}} \
+   // ref-note {{comparison against 
pointer '&"test1"[6]' that points past the end of a complete object has 
unspecified value}} \
+   // expected-note {{comparison against 
pointer '&"test1"[6] + 1' that points past the end of a complete object has 
unspecified value}}
+
 namespace UninitializedFields {
   class A {
   public:

diff  --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 28016da925ef9..dc8f4bf1666ee 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2203,6 +2203,8 @@ namespace BuiltinStrlen {
   static_assert(__builtin_strlen("foo") == 3, "");
   static_assert(__builtin_strlen("foo\0quux") == 3, "");
   static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
+  static_assert(__builtin_strlen("foo") + 1 + "foo" == "foo", ""); // 
expected-error {{static assertion expression is not an integral constant 
expression}}
+  // expected-note@-1 {{comparison against pointer '&"foo"[4]' that points 
past the end of a complete object has unspecified value}}
 
   constexpr bool check(const char *p) {
 return __builtin_strlen(p) == 3 &&



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


[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang` at step 7 
"test-build-unified-tree-check-all".

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


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

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe -cc1 -internal-isystem 
Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\21\include -nostdsysteminc 
-fcxx-exceptions -fexperimental-new-constant-interpreter -std=c++20 
-verify=both,expected -fcxx-exceptions 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\ByteCode\cxx20.cpp 
-DNEW_INTERP
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe' -cc1 
-internal-isystem 'Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\21\include' 
-nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\ByteCode\cxx20.cpp' 
-DNEW_INTERP
# .---command stderr
# | error: diagnostics with 'note' severity expected but not seen: 
# |   File 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\ByteCode\cxx20.cpp 
Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
# | error: diagnostics with 'note' severity seen but not expected: 
# |   File 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\ByteCode\cxx20.cpp 
Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
# | 2 errors generated.
# `-
# error: command failed with exit status: 1

--




```



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


[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread Henrik G. Olsson via cfe-commits

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


[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building `clang` at step 6 "test".

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


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

```
Step 6 (test) failure: build (failure)
...
UNSUPPORTED: lldb-api :: tools/lldb-server/TestGdbRemoteForkResume.py (1206 of 
2126)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteCompletion.py (1207 of 2126)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteExitCode.py (1208 of 2126)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteHostInfo.py (1209 of 2126)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteModuleInfo.py (1210 of 2126)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteAuxvSupport.py (1211 of 2126)
PASS: lldb-api :: terminal/TestEditlineCompletions.py (1212 of 2126)
UNSUPPORTED: lldb-api :: tools/lldb-server/TestGdbRemoteSaveCore.py (1213 of 
2126)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteKill.py (1214 of 2126)
UNRESOLVED: lldb-api :: tools/lldb-dap/variables/TestDAP_variables.py (1215 of 
2126)
 TEST 'lldb-api :: 
tools/lldb-dap/variables/TestDAP_variables.py' FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/variables
 -p TestDAP_variables.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
55160e6a89820f219eaa218fa02da2006213ed2c)
  clang revision 55160e6a89820f219eaa218fa02da2006213ed2c
  llvm revision 55160e6a89820f219eaa218fa02da2006213ed2c
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_darwin_dwarf_missing_obj (TestDAP_variables.TestDAP_variables) (requires 
one of macosx, darwin, ios, tvos, watchos, bridgeos, iphonesimulator, 
watchsimulator, appletvsimulator) 
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_darwin_dwarf_missing_obj_with_symbol_ondemand_enabled 
(TestDAP_variables.TestDAP_variables) (requires one of macosx, darwin, ios, 
tvos, watchos, bridgeos, iphonesimulator, watchsimulator, appletvsimulator) 
= DEBUG ADAPTER PROTOCOL LOGS =
1745452257.308542728 --> (stdin/stdout) 
{"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":false},"seq":1}
1745452257.310642958 <-- (stdin/stdout) {"body":{"$__lldb_version":"lldb 
version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
55160e6a89820f219eaa218fa02da2006213ed2c)\n  clang revision 
55160e6a89820f219eaa218fa02da2006213ed2c\n  llvm revision 
55160e6a89820f219eaa218fa02da2006213ed2c","completionTriggerCharacters":["."," 
","\t"],"exceptionBreakpointFilters":[{"default":false,"filter":"cpp_catch","label":"C++
 Catch"},{"default":false,"filter":"cpp_throw","label":"C++ 
Throw"},{"default":false,"filter":"objc_catch","label":"Objective-C 
Catch"},{"default":false,"filter":"objc_throw","label":"Objective-C 
Throw"}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":tru

[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-quick` 
running on `linaro-clang-aarch64-quick` while building `clang` at step 5 "ninja 
check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 
-internal-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/21/include 
-nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP # RUN: at line 1
+ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 
-internal-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/21/include 
-nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP
error: diagnostics with 'note' severity expected but not seen: 
  File 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/clang/test/AST/ByteCode/cxx20.cpp
 Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
error: diagnostics with 'note' severity seen but not expected: 
  File 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/clang/test/AST/ByteCode/cxx20.cpp
 Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
2 errors generated.

--




```



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


[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-sles-build-only` running on `rocm-worker-hw-04-sles` while 
building `clang` at step 6 "Add check check-clang".

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


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

```
Step 6 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 
-internal-isystem 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP # RUN: at line 1
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
-cc1 -internal-isystem 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP
error: diagnostics with 'note' severity expected but not seen: 
  File 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
error: diagnostics with 'note' severity seen but not expected: 
  File 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/ByteCode/cxx20.cpp
 Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
2 errors generated.

--




```



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


[clang] Revert "[ConstEval] Fix crash when comparing strings past the end" (PR #137088)

2025-04-23 Thread Henrik G. Olsson via cfe-commits

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


[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` 
running on `doug-worker-4` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 
-internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/21/include 
-nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP # RUN: at line 1
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 
-internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/21/include 
-nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP
error: diagnostics with 'note' severity expected but not seen: 
  File 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
error: diagnostics with 'note' severity seen but not expected: 
  File 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
2 errors generated.

--




```



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


[clang] [Clang] Add new -header-include-filtering=direct-per-file option (PR #137087)

2025-04-23 Thread Bob Wilson via cfe-commits

https://github.com/bob-wilson updated 
https://github.com/llvm/llvm-project/pull/137087

>From a7195bdc6d98f672344c25ea8794c434cc58e0ef Mon Sep 17 00:00:00 2001
From: Bob Wilson 
Date: Tue, 22 Apr 2025 09:24:49 -0700
Subject: [PATCH 1/2] [Clang] Add new -header-include-filtering=direct-per-file
 option

This adds a new filtering option to be used along with the
-header-include-format=json option. The existing "only-direct-system"
filtering option is missing some things:
- It does not show module imports.
- It does not show includes of non-system headers.
This new "direct-per-file" filtering has a separate entry in the JSON output
for each non-system source file, showing the direct includes and imports
from that file. You can use this to see uses of non-system headers, and also
find the paths through non-system headers that lead up to module imports and
system headers. Modules are identified here by their modulemap files.
---
 clang/include/clang/Basic/HeaderInclude.h   |  13 +-
 clang/include/clang/Driver/Options.td   |   3 +-
 clang/lib/Frontend/HeaderIncludeGen.cpp | 140 +++-
 clang/test/Preprocessor/print-header-json.c |   5 +
 clang/tools/driver/driver.cpp   |   2 +-
 5 files changed, 153 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Basic/HeaderInclude.h 
b/clang/include/clang/Basic/HeaderInclude.h
index 83c26543bbd3b..86c21cf292882 100644
--- a/clang/include/clang/Basic/HeaderInclude.h
+++ b/clang/include/clang/Basic/HeaderInclude.h
@@ -23,8 +23,14 @@ enum HeaderIncludeFormatKind { HIFMT_None, HIFMT_Textual, 
HIFMT_JSON };
 
 /// Whether header information is filtered or not. If HIFIL_Only_Direct_System
 /// is used, only information on system headers directly included from
-/// non-system headers is emitted.
-enum HeaderIncludeFilteringKind { HIFIL_None, HIFIL_Only_Direct_System };
+/// non-system files is emitted. The HIFIL_Direct_Per_File filtering shows the
+/// direct imports and includes for each non-system source and header file
+/// separately.
+enum HeaderIncludeFilteringKind {
+  HIFIL_None,
+  HIFIL_Only_Direct_System,
+  HIFIL_Direct_Per_File
+};
 
 inline HeaderIncludeFormatKind
 stringToHeaderIncludeFormatKind(const char *Str) {
@@ -40,6 +46,7 @@ inline bool stringToHeaderIncludeFiltering(const char *Str,
   llvm::StringSwitch>(Str)
   .Case("none", {true, HIFIL_None})
   .Case("only-direct-system", {true, HIFIL_Only_Direct_System})
+  .Case("direct-per-file", {true, HIFIL_Direct_Per_File})
   .Default({false, HIFIL_None});
   Kind = P.second;
   return P.first;
@@ -64,6 +71,8 @@ headerIncludeFilteringKindToString(HeaderIncludeFilteringKind 
K) {
 return "none";
   case HIFIL_Only_Direct_System:
 return "only-direct-system";
+  case HIFIL_Direct_Per_File:
+return "direct-per-file";
   }
   llvm_unreachable("Unknown HeaderIncludeFilteringKind enum");
 }
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a9f4083920663..c0f469e04375c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7793,7 +7793,8 @@ def header_include_format_EQ : Joined<["-"], 
"header-include-format=">,
   MarshallingInfoEnum, 
"HIFMT_Textual">;
 def header_include_filtering_EQ : Joined<["-"], "header-include-filtering=">,
   HelpText<"set the flag that enables filtering header information">,
-  Values<"none,only-direct-system">, NormalizedValues<["HIFIL_None", 
"HIFIL_Only_Direct_System"]>,
+  Values<"none,only-direct-system,direct-per-file">,
+  NormalizedValues<["HIFIL_None", "HIFIL_Only_Direct_System", 
"HIFIL_Direct_Per_File"]>,
   MarshallingInfoEnum, 
"HIFIL_None">;
 def show_includes : Flag<["--"], "show-includes">,
   HelpText<"Print cl.exe style /showIncludes to stdout">;
diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp 
b/clang/lib/Frontend/HeaderIncludeGen.cpp
index 792526083b1e6..85fc61b6f5e92 100644
--- a/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -106,6 +106,50 @@ class HeaderIncludesJSONCallback : public PPCallbacks {
   void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override;
 };
+
+/// A callback for emitting direct header and module usage information to a
+/// file in JSON. The output format is like HeaderIncludesJSONCallback but has
+/// an array of separate entries, one for each non-system source file used in
+/// the compilation showing only the direct includes and imports from that 
file.
+class HeaderIncludesDirectPerFileCallback : public PPCallbacks {
+  SourceManager &SM;
+  HeaderSearch &HSI;
+  raw_ostream *OutputFile;
+  bool OwnsOutputFile;
+  using DependencyMap =
+  llvm::DenseMap>;
+  DependencyMap Dependencies;
+
+public:
+  HeaderIncludesDirectPerFileCallback(const Preprocessor *PP,
+  raw_ostream *OutputFile_,
+ 

[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` 
running on `fuchsia-debian-64-us-central1-b-1` while building `clang` at step 4 
"annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[832/1384] Running the Clang regression tests
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using clang: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/clang
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126:
 note: Did not find cir-opt in 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin:/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126:
 note: Did not find clang-repl in 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin:/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/ld.lld
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/lld-link
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/ld64.lld
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/wasm-ld
-- Testing: 22372 tests, 60 workers --
Testing: 
FAIL: Clang :: AST/ByteCode/cxx20.cpp (56 of 22372)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/clang -cc1 
-internal-isystem 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP # RUN: at line 1
+ /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/bin/clang 
-cc1 -internal-isystem 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP
error: diagnostics with 'note' severity expected but not seen: 
  File 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
error: diagnostics with 'note' severity seen but not expected: 
  File 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/ByteCode/cxx20.cpp
 Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
2 errors generated.

--


Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

Failed Tests (1):
  Clang :: AST/ByteCode/cxx20.cpp


Testing Time: 141.73s

Total Discovered Tests: 46809
  Skipped  : 8 (0.02%)
  Unsupported  :   908 (1.94%)
  Passed   : 45865 (97.98%)
  Expectedly Failed:27 (0.06%)
  Failed   : 1 (0.00%)
[1382/1384] Linking CXX executable unittests/Transforms/Scalar/ScalarTests
FAILED: tools/clang/test/CMakeFiles/check-clang 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/tools/clang/test/CMakeFiles/check-clang
 
cd 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/tools/clang/test
 && /usr/bin/python3.10 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/./bin/llvm-lit 
-sv --param USE_Z3_SOLVER=0 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx/tools/clang/test
ninja: build stopped: subcommand failed.
['ninja', '-C', 
'/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-mxhadbqx', 
'check-llvm', 'check-clang', 'check-lld'] exited with return code 1.
@@@STEP_FAILURE@@@
Step 7 (check) failure: check (failure)
...
[832/1384] Running the Clang regression tests
llvm-lit: 
/var/lib/buildbot/fuchsi

[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)

2025-04-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building 
`clang` at step 7 "ninja check 1".

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


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

```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: AST/ByteCode/cxx20.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang
 -cc1 -internal-isystem 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP # RUN: at line 1
+ 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang
 -cc1 -internal-isystem 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/21/include
 -nostdsysteminc -fcxx-exceptions -fexperimental-new-constant-interpreter 
-std=c++20 -verify=both,expected -fcxx-exceptions 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/ByteCode/cxx20.cpp
 -DNEW_INTERP
error: diagnostics with 'note' severity expected but not seen: 
  File 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/ByteCode/cxx20.cpp
 Line 127 'expected-note': comparison against pointer '&"test1"[6] + 1' that 
points past the end of a complete object has unspecified value
error: diagnostics with 'note' severity seen but not expected: 
  File 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/ByteCode/cxx20.cpp
 Line 127: comparison against pointer '&"test1"[6]' that points past the end of 
a complete object has unspecified value
2 errors generated.

--




```



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


[clang] Eval string one past end reland (PR #137091)

2025-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Henrik G. Olsson (hnrklssn)


Changes

Relands #137078 after updating clang/test/AST/ByteCode/cxx20.cpp to 
account for diagnostic outputs that differ between Linux and macOS.

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


3 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+7-2) 
- (modified) clang/test/AST/ByteCode/cxx20.cpp (+8) 
- (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+2) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f598ef5929aa4..7c933f47bf7f0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2232,10 +2232,15 @@ static bool 
ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info,
   // within RHS. We don't need to look at the characters of one string that
   // would appear before the start of the other string if they were merged.
   CharUnits Offset = RHS.Offset - LHS.Offset;
-  if (Offset.isNegative())
+  if (Offset.isNegative()) {
+if (LHSString.Bytes.size() < (size_t)-Offset.getQuantity())
+  return false;
 LHSString.Bytes = LHSString.Bytes.drop_front(-Offset.getQuantity());
-  else
+  } else {
+if (RHSString.Bytes.size() < (size_t)Offset.getQuantity())
+  return false;
 RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity());
+  }
 
   bool LHSIsLonger = LHSString.Bytes.size() > RHSString.Bytes.size();
   StringRef Longer = LHSIsLonger ? LHSString.Bytes : RHSString.Bytes;
diff --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 42e6ae33e92e4..69a53a567fa41 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -119,6 +119,14 @@ constexpr auto b3 = name1() == name1(); // ref-error 
{{must be initialized by a
 constexpr auto b4 = name1() == name2();
 static_assert(!b4);
 
+constexpr auto bar(const char *p) { return p + __builtin_strlen(p); }
+constexpr auto b5 = bar(p1) == p1;
+static_assert(!b5);
+constexpr auto b6 = bar(p1) == ""; // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{comparison of addresses of 
potentially overlapping literals}}
+constexpr auto b7 = bar(p1) + 1 == ""; // both-error {{must be initialized by 
a constant expression}} \
+   // both-note-re {{comparison against 
pointer '&"test1"[6]{{( \+ 1)?}}' that points past the end of a complete object 
has unspecified value}}
+
 namespace UninitializedFields {
   class A {
   public:
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 28016da925ef9..dc8f4bf1666ee 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2203,6 +2203,8 @@ namespace BuiltinStrlen {
   static_assert(__builtin_strlen("foo") == 3, "");
   static_assert(__builtin_strlen("foo\0quux") == 3, "");
   static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
+  static_assert(__builtin_strlen("foo") + 1 + "foo" == "foo", ""); // 
expected-error {{static assertion expression is not an integral constant 
expression}}
+  // expected-note@-1 {{comparison against pointer '&"foo"[4]' that points 
past the end of a complete object has unspecified value}}
 
   constexpr bool check(const char *p) {
 return __builtin_strlen(p) == 3 &&

``




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


[clang] [clang][Modules] Diagnose mismatching pcm dependencies in explicit buiilds (PR #137068)

2025-04-23 Thread Cyndy Ishida via cfe-commits


@@ -3311,11 +3312,22 @@ ASTReader::ReadControlBlock(ModuleFile &F,
SignatureBytes.end());
 Blob = Blob.substr(ASTFileSignature::size);
 
+// Use BaseDirectoryAsWritten to ensure we use the same path in the
+// ModuleCache as when writing.
+StoredFile = ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
 if (ImportedFile.empty()) {
-  // Use BaseDirectoryAsWritten to ensure we use the same path in the
-  // ModuleCache as when writing.
-  ImportedFile =
-  ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
+  ImportedFile = StoredFile;
+} else {
+  auto ImportedFileRef =
+  PP.getFileManager().getOptionalFileRef(ImportedFile);
+  auto StoredFileRef =
+  PP.getFileManager().getOptionalFileRef(StoredFile);
+  if ((ImportedFileRef && StoredFileRef) &&
+  (*ImportedFileRef != *StoredFileRef)) {
+Diag(diag::warn_lazy_pcm_mismatch) << ImportedFile << StoredFile;
+Diag(diag::note_module_file_imported_by)

cyndyishida wrote:

It looks like I can just use `clang::DiagnosticsEngine::isIgnored` 

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


[clang] Eval string one past end reland (PR #137091)

2025-04-23 Thread Henrik G. Olsson via cfe-commits

https://github.com/hnrklssn created 
https://github.com/llvm/llvm-project/pull/137091

Relands #137078 after updating clang/test/AST/ByteCode/cxx20.cpp to account for 
diagnostic outputs that differ between Linux and macOS.

>From 92e524de8e568b47d8506f8d9156dc3f3d064aaa Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" 
Date: Wed, 23 Apr 2025 17:03:47 -0700
Subject: [PATCH 1/2] Reland "[ConstEval] Fix crash when comparing strings past
 the end" (#137088)"

This reverts commit 93705c3a76e9b00137be84fbc6ef3b4af5fcc031.
---
 clang/lib/AST/ExprConstant.cpp   | 9 +++--
 clang/test/AST/ByteCode/cxx20.cpp| 9 +
 clang/test/SemaCXX/constant-expression-cxx11.cpp | 2 ++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f598ef5929aa4..7c933f47bf7f0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2232,10 +2232,15 @@ static bool 
ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info,
   // within RHS. We don't need to look at the characters of one string that
   // would appear before the start of the other string if they were merged.
   CharUnits Offset = RHS.Offset - LHS.Offset;
-  if (Offset.isNegative())
+  if (Offset.isNegative()) {
+if (LHSString.Bytes.size() < (size_t)-Offset.getQuantity())
+  return false;
 LHSString.Bytes = LHSString.Bytes.drop_front(-Offset.getQuantity());
-  else
+  } else {
+if (RHSString.Bytes.size() < (size_t)Offset.getQuantity())
+  return false;
 RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity());
+  }
 
   bool LHSIsLonger = LHSString.Bytes.size() > RHSString.Bytes.size();
   StringRef Longer = LHSIsLonger ? LHSString.Bytes : RHSString.Bytes;
diff --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 42e6ae33e92e4..4c1b1592896c9 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -119,6 +119,15 @@ constexpr auto b3 = name1() == name1(); // ref-error 
{{must be initialized by a
 constexpr auto b4 = name1() == name2();
 static_assert(!b4);
 
+constexpr auto bar(const char *p) { return p + __builtin_strlen(p); }
+constexpr auto b5 = bar(p1) == p1;
+static_assert(!b5);
+constexpr auto b6 = bar(p1) == ""; // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{comparison of addresses of 
potentially overlapping literals}}
+constexpr auto b7 = bar(p1) + 1 == ""; // both-error {{must be initialized by 
a constant expression}} \
+   // ref-note {{comparison against 
pointer '&"test1"[6]' that points past the end of a complete object has 
unspecified value}} \
+   // expected-note {{comparison against 
pointer '&"test1"[6] + 1' that points past the end of a complete object has 
unspecified value}}
+
 namespace UninitializedFields {
   class A {
   public:
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 28016da925ef9..dc8f4bf1666ee 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2203,6 +2203,8 @@ namespace BuiltinStrlen {
   static_assert(__builtin_strlen("foo") == 3, "");
   static_assert(__builtin_strlen("foo\0quux") == 3, "");
   static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
+  static_assert(__builtin_strlen("foo") + 1 + "foo" == "foo", ""); // 
expected-error {{static assertion expression is not an integral constant 
expression}}
+  // expected-note@-1 {{comparison against pointer '&"foo"[4]' that points 
past the end of a complete object has unspecified value}}
 
   constexpr bool check(const char *p) {
 return __builtin_strlen(p) == 3 &&

>From b5f4f64348354c7b75619af7d58a0d99bb4cf8ad Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" 
Date: Wed, 23 Apr 2025 17:04:23 -0700
Subject: [PATCH 2/2] [ConstEval] Accept differing outputs in test case

Linux and macOS seem to differ in the output of one diagnostic. Accept
both for now to unblock CI and reland the fix.
---
 clang/test/AST/ByteCode/cxx20.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 4c1b1592896c9..69a53a567fa41 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -125,8 +125,7 @@ static_assert(!b5);
 constexpr auto b6 = bar(p1) == ""; // ref-error {{must be initialized by a 
constant expression}} \
// ref-note {{comparison of addresses of 
potentially overlapping literals}}
 constexpr auto b7 = bar(p1) + 1 == ""; // both-error {{must be initialized by 
a constant expression}} \
-   // ref-note {{comparison against 
pointer '&"test1"[6]' that points past the en

[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)

2025-04-23 Thread Fangyi Zhou via cfe-commits


@@ -93,9 +76,8 @@ ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
  RegionAndSymbolInvalidationTraits::TK_PreserveContents);
   }
 
-  return PrevState->invalidateRegions(Regions, getLoopCondition(LoopStmt),
-  BlockCount, LCtx, true, nullptr, nullptr,
-  &ITraits);
+  return PrevState->invalidateRegions(Regions, ElemRef, BlockCount, LCtx, true,

fangyi-zhou wrote:

I don't have a good answer to these questions... Any tips? I don't see any 
immediate ways to extract the required information

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


[clang] [clang] Adding an API to create a `CXStringSet` from a Vector of `StringRef`s (PR #136773)

2025-04-23 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

> Where is this new API expected to be used?

An intended use can be found here 
https://github.com/swiftlang/llvm-project/pull/10524, where we try to pass up a 
collection of strings to the user, and we try not to create copies of the 
strings. 

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


[clang] [CIR] Upstream cir.call with scalar arguments (PR #136810)

2025-04-23 Thread Erich Keane via cfe-commits


@@ -68,20 +168,70 @@ static cir::CIRCallOpInterface 
emitCallLikeOp(CIRGenFunction &cgf,
   assert(builder.getInsertionBlock() && "expected valid basic block");
   assert(!cir::MissingFeatures::opCallIndirect());
 
-  return builder.createCallOp(callLoc, directFuncOp);
+  return builder.createCallOp(callLoc, directFuncOp, cirCallArgs);
 }
 
 RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
 const CIRGenCallee &callee,
 ReturnValueSlot returnValue,
+const CallArgList &args,
 cir::CIRCallOpInterface *callOp,
 mlir::Location loc) {
   QualType retTy = funcInfo.getReturnType();
   const cir::ABIArgInfo &retInfo = funcInfo.getReturnInfo();
 
-  assert(!cir::MissingFeatures::opCallArgs());
+  ClangToCIRArgMapping cirFuncArgs(cgm.getASTContext(), funcInfo);
+  SmallVector cirCallArgs(cirFuncArgs.totalCIRArgs());
+
   assert(!cir::MissingFeatures::emitLifetimeMarkers());
 
+  // Translate all of the arguments as necessary to match the CIR lowering.
+  assert(funcInfo.arg_size() == args.size() &&
+ "Mismatch between function signature & arguments.");
+  unsigned argNo = 0;
+  const auto *infoIter = funcInfo.arg_begin();
+  for (auto i = args.begin(), e = args.end(); i != e;

erichkeane wrote:

The loop here is weird, I realize we want to count, but the other two are just 
args?  Should we just do a llvm::zip here? 

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


[clang] [CIR] Upstream cir.call with scalar arguments (PR #136810)

2025-04-23 Thread Erich Keane via cfe-commits


@@ -18,22 +18,118 @@
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];
 
   return fi;
 }
 
+namespace {
+
+/// Encapsulates information about the way function arguments from
+/// CIRGenFunctionInfo should be passed to actual CIR function.
+class ClangToCIRArgMapping {
+  static constexpr unsigned invalidIndex = ~0U;
+  unsigned totalNumCIRArgs;
+
+  /// Arguments of CIR function corresponding to single Clang argument.
+  struct CIRArgs {
+// Argument is expanded to CIR arguments at positions
+// [FirstArgIndex, FirstArgIndex + NumberOfArgs).
+unsigned firstArgIndex = 0;
+unsigned numberOfArgs = 0;
+
+CIRArgs() : firstArgIndex(invalidIndex), numberOfArgs(0) {}
+  };
+
+  SmallVector argInfo;
+
+public:
+  ClangToCIRArgMapping(const ASTContext &astContext,
+   const CIRGenFunctionInfo &funcInfo)
+  : totalNumCIRArgs(0), argInfo(funcInfo.arg_size()) {
+construct(astContext, funcInfo);
+  }
+
+  unsigned totalCIRArgs() const { return totalNumCIRArgs; }
+
+  /// Returns index of first CIR argument corresponding to argNo, and their
+  /// quantity.
+  std::pair getCIRArgs(unsigned argNo) const {
+assert(argNo < argInfo.size());
+return std::make_pair(argInfo[argNo].firstArgIndex,
+  argInfo[argNo].numberOfArgs);
+  }
+
+private:
+  void construct(const ASTContext &astContext,
+ const CIRGenFunctionInfo &funcInfo);
+};
+
+void ClangToCIRArgMapping::construct(const ASTContext &astContext,
+ const CIRGenFunctionInfo &funcInfo) {
+  unsigned cirArgNo = 0;
+
+  assert(!cir::MissingFeatures::opCallABIIndirectArg());
+
+  unsigned argNo = 0;
+  unsigned numArgs = funcInfo.arg_size();
+  for (const auto *i = funcInfo.arg_begin(); argNo < numArgs; ++i, ++argNo) {

erichkeane wrote:

This could very easily be a range-for loop, right?

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


[clang] [CIR] Upstream cir.call with scalar arguments (PR #136810)

2025-04-23 Thread Erich Keane via cfe-commits

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+  fi->required = required;
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];

andykaylor wrote:

Can you get the args buffer before the loop? The optimizer would probably do 
that for you, but I'd prefer to have it in the code that way.

It's also probably worth adding a comment explaining why the args buffer is one 
element larger than the arg types buffer. There's enough info here to figure 
that out, but it looks wrong on first reading.

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+

andykaylor wrote:

Maybe add `assert(!cir::MissingFeatures::paramInfo());` and 
`assert(!cir::MissingFeatures::funcTypeExtInfo());`?

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -47,18 +98,51 @@ class CIRGenFunctionInfo final
 
   // This function has to be CamelCase because llvm::FoldingSet requires so.
   // NOLINTNEXTLINE(readability-identifier-naming)
-  static void Profile(llvm::FoldingSetNodeID &id, CanQualType resultType) {
+  static void Profile(llvm::FoldingSetNodeID &id, RequiredArgs required,
+  CanQualType resultType,
+  llvm::ArrayRef argTypes) {
+id.AddBoolean(required.getOpaqueData());
 resultType.Profile(id);
+for (const auto &arg : argTypes)
+  arg.Profile(id);
   }
 
-  void Profile(llvm::FoldingSetNodeID &id) { getReturnType().Profile(id); }
+  // NOLINTNEXTLINE(readability-identifier-naming)
+  void Profile(llvm::FoldingSetNodeID &id) {
+id.AddBoolean(required.getOpaqueData());
+getReturnType().Profile(id);
+for (const auto &i : arguments())
+  i.type.Profile(id);
+  }
 
   CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
 
   cir::ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
   const cir::ABIArgInfo &getReturnInfo() const {
 return getArgsBuffer()[0].info;
   }
+  using const_arg_iterator = const ArgInfo *;
+  using arg_iterator = ArgInfo *;
+
+  const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
+  const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + numArgs; }
+  arg_iterator arg_begin() { return getArgsBuffer() + 1; }
+  arg_iterator arg_end() { return getArgsBuffer() + 1 + numArgs; }
+
+  unsigned arg_size() const { return numArgs; }
+
+  llvm::MutableArrayRef arguments() {

andykaylor wrote:

This doesn't seem like the right name here. It's return info about the 
arguments, not the actual arguments, right? Similarly for the arg_begin and 
arg_end functions.

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


[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)

2025-04-23 Thread Fangyi Zhou via cfe-commits


@@ -645,6 +645,7 @@ struct StreamOperationEvaluator {
   SymbolRef StreamSym = nullptr;
   const StreamState *SS = nullptr;
   const CallExpr *CE = nullptr;
+  std::optional ElemRef;

fangyi-zhou wrote:

I'm not entirely sure whether I get your point correctly. This value needs to 
be stored when `Init` is called, and used in other calls (e.g. 
`bindReturnValue`). The reason why this is declared as an optional is that 
there is no default constructor for `ConstCFGElementRef`, so I used an optional 
to give an absent value (I guess it could have been a pointer like other ones)

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -32,8 +32,14 @@ void X8664ABIInfo::computeInfo(CIRGenFunctionInfo &funcInfo) 
const {
   // Top level CIR has unlimited arguments and return types. Lowering for ABI
   // specific concerns should happen during a lowering phase. Assume everything
   // is direct for now.
-  assert(!cir::MissingFeatures::opCallArgs());
-
+  for (CIRGenFunctionInfo::arg_iterator it = funcInfo.arg_begin(),

andykaylor wrote:

Can you use a range-based for loop here?

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


[clang] Upstream enum support (PR #136807)

2025-04-23 Thread Bruno Cardoso Lopes via cfe-commits

https://github.com/bcardosolopes commented:

Title should start with `[CIR] ...`, more comments inline

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


[clang] [Clang][CodeGen] Emit fake uses before musttail calls (PR #136867)

2025-04-23 Thread Wolfgang Pieb via cfe-commits

wolfy1961 wrote:

LGTM

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+  fi->required = required;
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];
 
   return fi;
 }
 
+cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
+  bool inserted = functionsBeingProcessed.insert(&fi).second;
+  assert(inserted && "Recursively being processed?");
+
+  mlir::Type resultType = nullptr;
+  const cir::ABIArgInfo &retAI = fi.getReturnInfo();
+
+  switch (retAI.getKind()) {
+  case cir::ABIArgInfo::Ignore:
+// TODO(CIR): This should probably be the None type from the builtin
+// dialect.
+resultType = nullptr;
+break;
+
+  case cir::ABIArgInfo::Direct:
+resultType = retAI.getCoerceToType();
+break;
+
+  default:
+assert(false && "NYI");

andykaylor wrote:

```suggestion
cgm.errorNYI("getFunctionType: unhandled return kind");
```

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -47,18 +98,51 @@ class CIRGenFunctionInfo final
 
   // This function has to be CamelCase because llvm::FoldingSet requires so.
   // NOLINTNEXTLINE(readability-identifier-naming)
-  static void Profile(llvm::FoldingSetNodeID &id, CanQualType resultType) {
+  static void Profile(llvm::FoldingSetNodeID &id, RequiredArgs required,
+  CanQualType resultType,
+  llvm::ArrayRef argTypes) {
+id.AddBoolean(required.getOpaqueData());
 resultType.Profile(id);
+for (const auto &arg : argTypes)
+  arg.Profile(id);
   }
 
-  void Profile(llvm::FoldingSetNodeID &id) { getReturnType().Profile(id); }
+  // NOLINTNEXTLINE(readability-identifier-naming)
+  void Profile(llvm::FoldingSetNodeID &id) {
+id.AddBoolean(required.getOpaqueData());
+getReturnType().Profile(id);
+for (const auto &i : arguments())

andykaylor wrote:

Don't use auto here. Is this ArgInfo?

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+  fi->required = required;
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];
 
   return fi;
 }
 
+cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
+  bool inserted = functionsBeingProcessed.insert(&fi).second;
+  assert(inserted && "Recursively being processed?");
+
+  mlir::Type resultType = nullptr;
+  const cir::ABIArgInfo &retAI = fi.getReturnInfo();
+
+  switch (retAI.getKind()) {
+  case cir::ABIArgInfo::Ignore:
+// TODO(CIR): This should probably be the None type from the builtin
+// dialect.
+resultType = nullptr;
+break;
+
+  case cir::ABIArgInfo::Direct:
+resultType = retAI.getCoerceToType();
+break;
+
+  default:
+assert(false && "NYI");
+  }
+
+  SmallVector argTypes;
+  unsigned argNo = 0;
+  CIRGenFunctionInfo::const_arg_iterator it = fi.arg_begin(),
+ ie = it + fi.getNumRequiredArgs();
+  for (; it != ie; ++it, ++argNo) {
+const auto &argInfo = it->info;
+
+switch (argInfo.getKind()) {
+default:
+  llvm_unreachable("NYI");

andykaylor wrote:

```suggestion
  cgm.errorNYI("getFunctionType: unhandled argument kind");
```

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -47,18 +98,51 @@ class CIRGenFunctionInfo final
 
   // This function has to be CamelCase because llvm::FoldingSet requires so.
   // NOLINTNEXTLINE(readability-identifier-naming)
-  static void Profile(llvm::FoldingSetNodeID &id, CanQualType resultType) {
+  static void Profile(llvm::FoldingSetNodeID &id, RequiredArgs required,
+  CanQualType resultType,
+  llvm::ArrayRef argTypes) {
+id.AddBoolean(required.getOpaqueData());
 resultType.Profile(id);
+for (const auto &arg : argTypes)

andykaylor wrote:

```suggestion
for (const CanQualType &type : argTypes)
```

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


[clang] [CIR] Introduce type aliases for records (PR #136387)

2025-04-23 Thread Bruno Cardoso Lopes via cfe-commits

bcardosolopes wrote:

> It generates anonymous records for vtables and typeinfo

oh right, that was it! thanks for double checking

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+  fi->required = required;
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];
 
   return fi;
 }
 
+cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
+  bool inserted = functionsBeingProcessed.insert(&fi).second;
+  assert(inserted && "Recursively being processed?");
+
+  mlir::Type resultType = nullptr;
+  const cir::ABIArgInfo &retAI = fi.getReturnInfo();

andykaylor wrote:

```suggestion
  const cir::ABIArgInfo &retInfo = fi.getReturnInfo();
```
I'd prefer a more meaningful name here.

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+   llvm::ArrayRef argTypes,
+   RequiredArgs required) {
+  void *buffer = operator new(totalSizeToAlloc(argTypes.size() + 1));
 
   CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+  fi->required = required;
+  fi->numArgs = argTypes.size();
   fi->getArgsBuffer()[0].type = resultType;
+  for (unsigned i = 0; i < argTypes.size(); ++i)
+fi->getArgsBuffer()[i + 1].type = argTypes[i];
 
   return fi;
 }
 
+cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
+  bool inserted = functionsBeingProcessed.insert(&fi).second;
+  assert(inserted && "Recursively being processed?");
+
+  mlir::Type resultType = nullptr;
+  const cir::ABIArgInfo &retAI = fi.getReturnInfo();
+
+  switch (retAI.getKind()) {
+  case cir::ABIArgInfo::Ignore:
+// TODO(CIR): This should probably be the None type from the builtin
+// dialect.
+resultType = nullptr;
+break;
+
+  case cir::ABIArgInfo::Direct:
+resultType = retAI.getCoerceToType();
+break;
+
+  default:
+assert(false && "NYI");
+  }
+
+  SmallVector argTypes;
+  unsigned argNo = 0;
+  CIRGenFunctionInfo::const_arg_iterator it = fi.arg_begin(),
+ ie = it + fi.getNumRequiredArgs();
+  for (; it != ie; ++it, ++argNo) {

andykaylor wrote:

Can you make this a range-based loop?

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


[clang] [clang] Do not share ownership of `HeaderSearchOptions` (PR #132984)

2025-04-23 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/132984

>From 8599450e27f0d866db8785f1840372583fc545a2 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 28 Mar 2025 09:02:12 -0700
Subject: [PATCH] [clang] Do not share ownership of `HeaderSearchOptions`

---
 clang/include/clang/Frontend/ASTUnit.h | 4 ++--
 clang/include/clang/Frontend/CompilerInstance.h| 3 ---
 clang/include/clang/Frontend/CompilerInvocation.h  | 3 ---
 clang/lib/CrossTU/CrossTranslationUnit.cpp | 2 +-
 clang/lib/Frontend/ASTMerge.cpp| 2 +-
 clang/lib/Frontend/ASTUnit.cpp | 5 ++---
 clang/lib/Frontend/FrontendAction.cpp  | 6 ++
 clang/tools/c-index-test/core_main.cpp | 2 +-
 clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp | 2 +-
 clang/tools/libclang/CIndex.cpp| 2 +-
 clang/unittests/Frontend/ASTUnitTest.cpp   | 2 +-
 11 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index 0506ac361721d..eadc4f3719ba4 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -116,7 +116,7 @@ class ASTUnit {
   std::shared_ptr   PP;
   IntrusiveRefCntPtr  Ctx;
   std::shared_ptr  TargetOpts;
-  std::shared_ptrHSOpts;
+  std::unique_ptr HSOpts;
   std::shared_ptrPPOpts;
   IntrusiveRefCntPtr Reader;
   bool HadModuleLoaderFatalFailure = false;
@@ -699,7 +699,7 @@ class ASTUnit {
   WhatToLoad ToLoad,
   IntrusiveRefCntPtr Diags,
   const FileSystemOptions &FileSystemOpts,
-  std::shared_ptr HSOpts,
+  const HeaderSearchOptions &HSOpts,
   std::shared_ptr LangOpts = nullptr,
   bool OnlyLocalDecls = false,
   CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 8c91a2a86cfcd..d8ef2691b46bb 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -316,9 +316,6 @@ class CompilerInstance : public ModuleLoader {
   const HeaderSearchOptions &getHeaderSearchOpts() const {
 return Invocation->getHeaderSearchOpts();
   }
-  std::shared_ptr getHeaderSearchOptsPtr() const {
-return Invocation->getHeaderSearchOptsPtr();
-  }
 
   APINotesOptions &getAPINotesOpts() { return Invocation->getAPINotesOpts(); }
   const APINotesOptions &getAPINotesOpts() const {
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index f71d27813b2a1..3f61cef7462cb 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -269,9 +269,6 @@ class CompilerInvocation : public CompilerInvocationBase {
   /// @{
   using CompilerInvocationBase::LangOpts;
   using CompilerInvocationBase::TargetOpts;
-  std::shared_ptr getHeaderSearchOptsPtr() {
-return HSOpts;
-  }
   std::shared_ptr getLangOptsPtr() { return LangOpts; }
   /// @}
 
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp 
b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index ad2ebb6cd6e6c..ef395f497216c 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -569,7 +569,7 @@ 
CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) {
   return ASTUnit::LoadFromASTFile(
   ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(),
   ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(),
-  CI.getHeaderSearchOptsPtr());
+  CI.getHeaderSearchOpts());
 }
 
 /// Load the AST from a source-file, which is supposed to be located inside the
diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp
index 1e3a5c04c4e9b..b6b06440bc3f8 100644
--- a/clang/lib/Frontend/ASTMerge.cpp
+++ b/clang/lib/Frontend/ASTMerge.cpp
@@ -48,7 +48,7 @@ void ASTMergeAction::ExecuteAction() {
 /*ShouldOwnClient=*/true));
 std::unique_ptr Unit = ASTUnit::LoadFromASTFile(
 ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, 
Diags,
-CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr());
+CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
 
 if (!Unit)
   continue;
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 04ddc93415507..23a1324e68e15 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -804,8 +804,7 @@ void 
ASTUnit::ConfigureDiags(IntrusiveRefCntPtr Diags,
 std::unique_ptr ASTUnit::LoadFromASTFile(
 StringRef Filename, const PCHContainerReader &PCHContainerRdr,
 WhatToLoad ToLoa

[clang] [Clang][NFC] Use temporary instead of one use local variable when creating APValue (PR #137029)

2025-04-23 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik created 
https://github.com/llvm/llvm-project/pull/137029

Static analysis flagged this code b/c we should have been using std::move when 
passing by value since the value is not used anymore. In this case the simpler 
fix is just to use a temporary value as many of the other cases where we simply 
use MakeIntValue to then create an APValue result from it.

>From 6a7551c057843be12f6e26935b57c08666fa960f Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Wed, 23 Apr 2025 10:55:33 -0700
Subject: [PATCH] [Clang][NFC] Use temporary instead of one use local variable
 when creating APValue

Static analysis flagged this code b/c we should have been using std::move when
passing by value since the value is not used anymore. In this case the simpler
fix is just to use a temporary value as many of the other cases where we simply
use MakeIntValue to then create an APValue result from it.
---
 clang/lib/Sema/SemaExprCXX.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f5a10e0db85ad..72edb72ceb600 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6147,9 +6147,8 @@ static APValue EvaluateSizeTTypeTrait(Sema &S, TypeTrait 
Kind,
   S.Diag(KWLoc, diag::err_arg_is_not_destructurable) << T << ArgRange;
   return APValue();
 }
-llvm::APSInt V =
-S.getASTContext().MakeIntValue(*Size, S.getASTContext().getSizeType());
-return APValue{V};
+return APValue(
+S.getASTContext().MakeIntValue(*Size, 
S.getASTContext().getSizeType()));
 break;
   }
   default:

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Andy Kaylor via cfe-commits


@@ -13,20 +13,76 @@
 
 #include "CIRGenCall.h"
 #include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
 #include "clang/CIR/MissingFeatures.h"
 
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
-  void *buffer = operator new(totalSizeToAlloc(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,

andykaylor wrote:

This same change is being made in 
https://github.com/llvm/llvm-project/pull/136810. See my comment there about 
coordinating the two.

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


[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)

2025-04-23 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

> I'm looking at this patch in isolation, so its possible that the comments 
> here are addressed elasewhere.
> 
> It looks like useful functionality to add to the bare metal driver.
> 
> It also looks like there is some scope for some documentation, for users and 
> for toolchain developers. Users will need to know about what options to set 
> to point at their GCC installation (or place adjacent). Non-GNU toolchain 
> developers will need to avoid `/lib/crt0.o`. If multilibs doesn't 
> work for all toolchains yet, would be good to add that as a limitation.
> 
> That could be done with a follow up patch though.

Thanks for providing feedback @smithp35. I can add documentation related to the 
points you mentioned. Pls let me know if adding them in the BareMetal.cpp file 
would be ok or should I consider adding it in some other file.

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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

If you make it a canonical node, you also automatically don't get an `aka` in 
diagnostics, which might be an advantage (or not).

Ie you avoid the aka in `size_t (aka 'unsigned long')` you currently get.

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


[clang] [clang-format] Correctly identify include guards (PR #137112)

2025-04-23 Thread Owen Pan via cfe-commits

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


[clang] 0f5965f - [CIR] Introduce type aliases for records (#136387)

2025-04-23 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-04-23T10:52:35-07:00
New Revision: 0f5965fa9c67969e4de7374362b6af49bf400b3b

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

LOG: [CIR] Introduce type aliases for records (#136387)

This introduces MLIR aliases for ClangIR record types. These are used in
the incubator and having skipped over them upstream is causing the tests
to diverge.

Added: 


Modified: 
clang/lib/CIR/Dialect/IR/CIRDialect.cpp
clang/test/CIR/CodeGen/struct.c
clang/test/CIR/CodeGen/struct.cpp
clang/test/CIR/CodeGen/typedef.c
clang/test/CIR/CodeGen/union.c
clang/test/CIR/IR/struct.cir

Removed: 




diff  --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 146c91b253f39..3cd17053a52ba 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -33,6 +33,14 @@ struct CIROpAsmDialectInterface : public 
OpAsmDialectInterface {
   using OpAsmDialectInterface::OpAsmDialectInterface;
 
   AliasResult getAlias(Type type, raw_ostream &os) const final {
+if (auto recordType = dyn_cast(type)) {
+  StringAttr nameAttr = recordType.getName();
+  if (!nameAttr)
+os << "rec_anon_" << recordType.getKindAsStr();
+  else
+os << "rec_" << nameAttr.getValue();
+  return AliasResult::OverridableAlias;
+}
 if (auto intType = dyn_cast(type)) {
   // We only provide alias for standard integer types (i.e. integer types
   // whose width is a power of 2 and at least 8).

diff  --git a/clang/test/CIR/CodeGen/struct.c b/clang/test/CIR/CodeGen/struct.c
index b78a2367bda3a..c91a14e0637c1 100644
--- a/clang/test/CIR/CodeGen/struct.c
+++ b/clang/test/CIR/CodeGen/struct.c
@@ -7,6 +7,12 @@
 
 // For LLVM IR checks, the structs are defined before the variables, so these
 // checks are at the top.
+// CIR-DAG: !rec_IncompleteS = !cir.record
+// CIR-DAG: !rec_CompleteS = !cir.record
+// CIR-DAG: !rec_OuterS = !cir.record  
+// CIR-DAG: !rec_InnerS = !cir.record
+// CIR-DAG: !rec_PackedS = !cir.record
+// CIR-DAG: !rec_PackedAndPaddedS = !cir.record
 // LLVM-DAG: %struct.CompleteS = type { i32, i8 }
 // LLVM-DAG: %struct.OuterS = type { %struct.InnerS, i32 }
 // LLVM-DAG: %struct.InnerS = type { i32, i8 }
@@ -20,8 +26,7 @@
 
 struct IncompleteS *p;
 
-// CIR:  cir.global external @p = #cir.ptr : 
!cir.ptr>
+// CIR:  cir.global external @p = #cir.ptr : 
!cir.ptr
 // LLVM-DAG: @p = dso_local global ptr null
 // OGCG-DAG: @p = global ptr null, align 8
 
@@ -30,10 +35,9 @@ struct CompleteS {
   char b;
 } cs;
 
-// CIR:   cir.global external @cs = #cir.zero : !cir.record
-// LLVM-DAG:  @cs = dso_local global %struct.CompleteS zeroinitializer
-// OGCG-DAG:  @cs = global %struct.CompleteS zeroinitializer, align 4
+// CIR:   cir.global external @cs = #cir.zero : !rec_CompleteS
+// LLVM-DAG:  @cs = dso_local global %struct.CompleteS zeroinitializer
+// OGCG-DAG:  @cs = global %struct.CompleteS zeroinitializer, align 4
 
 struct InnerS {
   int a;
@@ -47,10 +51,9 @@ struct OuterS {
 
 struct OuterS os;
 
-// CIR:   cir.global external @os = #cir.zero : !cir.record, !s32i}>
-// LLVM-DAG:  @os = dso_local global %struct.OuterS zeroinitializer
-// OGCG-DAG:  @os = global %struct.OuterS zeroinitializer, align 4
+// CIR:   cir.global external @os = #cir.zero : !rec_OuterS
+// LLVM-DAG:  @os = dso_local global %struct.OuterS zeroinitializer
+// OGCG-DAG:  @os = global %struct.OuterS zeroinitializer, align 4
 
 #pragma pack(push)
 #pragma pack(1)
@@ -60,20 +63,18 @@ struct PackedS {
   char a1;
 } ps;
 
-// CIR:   cir.global external @ps = #cir.zero : !cir.record
-// LLVM-DAG:  @ps = dso_local global %struct.PackedS zeroinitializer
-// OGCG-DAG:  @ps = global %struct.PackedS zeroinitializer, align 1
+// CIR:   cir.global external @ps = #cir.zero : !rec_PackedS
+// LLVM-DAG:  @ps = dso_local global %struct.PackedS zeroinitializer
+// OGCG-DAG:  @ps = global %struct.PackedS zeroinitializer, align 1
 
 struct PackedAndPaddedS {
   int  b0;
   char b1;
 } __attribute__((aligned(2))) pps;
 
-// CIR:   cir.global external @pps = #cir.zero : !cir.record
-// LLVM-DAG:  @pps = dso_local global %struct.PackedAndPaddedS 
zeroinitializer
-// OGCG-DAG:  @pps = global %struct.PackedAndPaddedS zeroinitializer, 
align 2
+// CIR:   cir.global external @pps = #cir.zero : !rec_PackedAndPaddedS
+// LLVM-DAG:  @pps = dso_local global %struct.PackedAndPaddedS zeroinitializer
+// OGCG-DAG:  @pps = global %struct.PackedAndPaddedS zeroinitializer, align 2
 
 #pragma pack(pop)
 
@@ -82,9 +83,7 @@ void f(void) {
 }
 
 // CIR:  cir.func @f()
-// CIR-NEXT:   cir.alloca !cir.ptr>,
-// CIR-SAME:   !cir.ptr>>, ["p"]
+// CIR-N

[clang] Upstream enum support (PR #136807)

2025-04-23 Thread Bruno Cardoso Lopes via cfe-commits


@@ -617,6 +617,9 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
   case Decl::OpenACCDeclare:
 emitGlobalOpenACCDecl(cast(decl));
 break;
+  case Decl::Enum:
+assert(!cir::MissingFeatures::generateDebugInfo() && "NYI");

bcardosolopes wrote:

`assert(!cir::MissingFeatures::generateDebugInfo())` should be enough here.

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


[clang] [llvm] Reland "[HLSL][RootSignature] Implement initial parsing of the descriptor table clause params" (PR #136740)

2025-04-23 Thread Finn Plummer via cfe-commits


@@ -90,36 +89,170 @@ bool RootSignatureParser::parseDescriptorTableClause() {
   CurToken.TokKind == TokenKind::kw_Sampler) &&
  "Expects to only be invoked starting at given keyword");
 
+  TokenKind ParamKind = CurToken.TokKind;
+
+  if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
+   CurToken.TokKind))
+return true;
+
   DescriptorTableClause Clause;
-  switch (CurToken.TokKind) {
+  TokenKind ExpectedReg;
+  switch (ParamKind) {
   default:
 llvm_unreachable("Switch for consumed token was not provided");
   case TokenKind::kw_CBV:
 Clause.Type = ClauseType::CBuffer;
+ExpectedReg = TokenKind::bReg;
 break;
   case TokenKind::kw_SRV:
 Clause.Type = ClauseType::SRV;
+ExpectedReg = TokenKind::tReg;
 break;
   case TokenKind::kw_UAV:
 Clause.Type = ClauseType::UAV;
+ExpectedReg = TokenKind::uReg;
 break;
   case TokenKind::kw_Sampler:
 Clause.Type = ClauseType::Sampler;
+ExpectedReg = TokenKind::sReg;
 break;
   }
 
-  if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
-   CurToken.TokKind))
+  auto Params = parseDescriptorTableClauseParams(ExpectedReg);
+  if (!Params.has_value())
 return true;
 
-  if (consumeExpectedToken(TokenKind::pu_r_paren, diag::err_expected_after,
-   CurToken.TokKind))
+  // Check mandatory parameters were provided
+  if (!Params->Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< ExpectedReg;
+return true;
+  }
+
+  Clause.Reg = Params->Reg.value();
+
+  // Fill in optional values
+  if (Params->Space.has_value())
+Clause.Space = Params->Space.value();
+
+  if (consumeExpectedToken(TokenKind::pu_r_paren,
+   diag::err_hlsl_unexpected_end_of_params,
+   /*param of=*/ParamKind))
 return true;
 
   Elements.push_back(Clause);
   return false;
 }
 
+std::optional
+RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
+  assert(CurToken.TokKind == TokenKind::pu_l_paren &&
+ "Expects to only be invoked starting at given token");
+
+  // Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
+  // order and only exactly once. Parse through as many arguments as possible

inbelic wrote:

This is just in the context of specifying the arguments of a single 
`DescriptorTableClause`. So for a given clause we can only have one register 
specified.

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


[clang] [C] Add (new) -Wimplicit-void-ptr-cast to -Wc++-compat (PR #136855)

2025-04-23 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/136855

>From 73a0a93e22976fd8ffdd5df70c459b648b7dd06d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 23 Apr 2025 07:15:42 -0400
Subject: [PATCH 1/3] Diagnose implicit void * casts under -Wc++-compat

---
 .../include/clang/Basic/DiagnosticSemaKinds.td  |  3 +++
 clang/include/clang/Sema/Sema.h | 17 +
 clang/lib/Sema/SemaDeclAttr.cpp |  4 ++--
 clang/lib/Sema/SemaExpr.cpp | 14 +++---
 clang/lib/Sema/SemaInit.cpp |  7 +++
 clang/lib/Sema/SemaObjC.cpp |  4 ++--
 clang/lib/Sema/SemaObjCProperty.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp |  1 +
 8 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 45b6e1dc29980..84dc0a7206e63 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8682,6 +8682,9 @@ def err_typecheck_missing_return_type_incompatible : 
Error<
   "return type must match previous return type}0,1 when %select{block "
   "literal|lambda expression}2 has unspecified explicit return type">;
 
+def warn_compatible_implicit_pointer_conv : Warning<
+  "implicit conversion from %diff{$ to $|type to incompatible type}0,1 is not "
+  "permitted in C++">, InGroup, DefaultIgnore;
 def note_incomplete_class_and_qualified_id : Note<
   "conformance of forward class %0 to protocol %1 cannot be confirmed">;
 def warn_incompatible_qualified_id : Warning<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 96d81e618494a..0c77c5b5ca30a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7786,6 +7786,11 @@ class Sema final : public SemaBase {
 /// Compatible - the types are compatible according to the standard.
 Compatible,
 
+/// CompatibleVoidPtrToNonVoidPtr - The types are compatible in C because
+/// a void * can implicitly convert to another pointer type, which we
+/// differentiate for better diagnostic behavior.
+CompatibleVoidPtrToNonVoidPtr,
+
 /// PointerToInt - The assignment converts a pointer to an int, which we
 /// accept as an extension.
 PointerToInt,
@@ -7866,6 +7871,18 @@ class Sema final : public SemaBase {
 Incompatible
   };
 
+  bool IsAssignConvertCompatible(AssignConvertType ConvTy) {
+switch (ConvTy) {
+default:
+  return false;
+case Compatible:
+case CompatiblePointerDiscardsQualifiers:
+case CompatibleVoidPtrToNonVoidPtr:
+  return true;
+}
+llvm_unreachable("impossible");
+  }
+
   /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
   /// assignment conversion type specified by ConvTy.  This returns true if the
   /// conversion was invalid or false if the conversion was accepted.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 0cadbff13bdbf..642a62765d0d9 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3589,8 +3589,8 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   // If this ever proves to be a problem it should be easy to fix.
   QualType Ty = S.Context.getPointerType(cast(D)->getType());
   QualType ParamTy = FD->getParamDecl(0)->getType();
-  if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
-   ParamTy, Ty) != Sema::Compatible) {
+  if (!S.IsAssignConvertCompatible(S.CheckAssignmentConstraints(
+  FD->getParamDecl(0)->getLocation(), ParamTy, Ty))) {
 S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
   << NI.getName() << ParamTy << Ty;
 return;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 01a021443c94f..8d862fd179823 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9062,8 +9062,12 @@ checkPointerTypesForAssignment(Sema &S, QualType 
LHSType, QualType RHSType,
   }
 
   if (rhptee->isVoidType()) {
+// In C, void * to another pointer type is compatible, but we want to note
+// that there will be an implicit conversion happening here.
 if (lhptee->isIncompleteOrObjectType())
-  return ConvTy;
+  return ConvTy == Sema::Compatible && !S.getLangOpts().CPlusPlus
+ ? Sema::CompatibleVoidPtrToNonVoidPtr
+ : ConvTy;
 
 // As an extension, we allow cast to/from void* to function pointer.
 assert(lhptee->isFunctionType());
@@ -9098,7 +9102,7 @@ checkPointerTypesForAssignment(Sema &S, QualType LHSType, 
QualType RHSType,
   // Types are compatible ignoring the sign. Qualifier incompatibility
   // takes priority over sign incompatibility because the sign
   // warning can be disabl

[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)

2025-04-23 Thread via cfe-commits

jeremyd2019 wrote:

It did turn out to be just one more slash issue.  Test is passing now on 
Windows (and Linux, and Cygwin itself)

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


[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)

2025-04-23 Thread Balazs Benics via cfe-commits


@@ -93,9 +76,8 @@ ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
  RegionAndSymbolInvalidationTraits::TK_PreserveContents);
   }
 
-  return PrevState->invalidateRegions(Regions, getLoopCondition(LoopStmt),
-  BlockCount, LCtx, true, nullptr, nullptr,
-  &ITraits);
+  return PrevState->invalidateRegions(Regions, ElemRef, BlockCount, LCtx, true,

steakhal wrote:

@isuckatcs 

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


[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)

2025-04-23 Thread Balazs Benics via cfe-commits


@@ -114,7 +128,8 @@ class SValExplainer : public FullSValVisitor {
 
   std::string VisitSymbolConjured(const SymbolConjured *S) {
 return "symbol of type '" + S->getType().getAsString() +
-   "' conjured at statement '" + printStmt(S->getStmt()) + "'";
+   "' conjured at statement '" +

steakhal wrote:

Please do. These are only used in tests, and not in production.

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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-23 Thread Erich Keane via cfe-commits

erichkeane wrote:

> If you make it a canonical node, you also automatically don't get an `aka` in 
> diagnostics, which might be an advantage (or not).
> 
> Ie you avoid the aka in `size_t (aka 'unsigned long')` you currently get.

I don't think you'd WANT to avoid that, I would want a type-alias because what 
we want is actually something that works exactly LIKE a type alias in every 
way, except doesn't require declaration.  Optimally we'd just generate a 
`size_t` alias, but as Aaron mentioned, we cannot use that name.

YES, of course we could come up with a new type-like-thing that aliases a 
specific type (at which point, I'd say it isn't really a type, just a type 
alias with a fancy representation), but not have it be a type alias, but really 
all that does is save us a node in the AST.  IF we were worried about THAT, we 
could have it lazily constructed, though that buys us little.

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


[clang] [clang] Ensure correct copying of records with authenticated fields (PR #136783)

2025-04-23 Thread Oliver Hunt via cfe-commits


@@ -2801,6 +2801,10 @@ static bool isTriviallyCopyableTypeImpl(const QualType 
&type,
   if (type.hasNonTrivialObjCLifetime())
 return false;
 
+  QualType::PrimitiveCopyKind PCK = type.isNonTrivialToPrimitiveCopy();
+  if (PCK != QualType::PCK_Trivial && PCK != QualType::PCK_VolatileTrivial)

ojhunt wrote:

- [ ] I'm trying to find the origin of this particular check, as I'm not sure 
how it relates to pointer auth copying semantics



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


[clang] [llvm] [TargetVerifier][AMDGPU] Add TargetVerifier. (PR #123609)

2025-04-23 Thread via cfe-commits

https://github.com/jofrn updated 
https://github.com/llvm/llvm-project/pull/123609

>From 210b6d80bcfbbcd216f98199df386280724561e2 Mon Sep 17 00:00:00 2001
From: jofernau 
Date: Mon, 20 Jan 2025 04:51:26 -0800
Subject: [PATCH 01/12] [TargetVerifier][AMDGPU] Add TargetVerifier.

This pass verifies the IR for an individual backend. This is
different than Lint because it consolidates all checks for a
given backend in a single pass. A check for Lint may be
undefined behavior across all targets, whereas a check in
TargetVerifier would only pertain to the specified target
but can check more than just undefined behavior such are IR
validity. A use case of this would be to reject programs
with invalid IR while fuzzing.
---
 llvm/include/llvm/IR/Module.h |   4 +
 llvm/include/llvm/Target/TargetVerifier.h |  82 +++
 .../TargetVerify/AMDGPUTargetVerifier.h   |  36 +++
 llvm/lib/IR/Verifier.cpp  |  18 +-
 .../Target/AMDGPU/AMDGPUTargetVerifier.cpp| 213 ++
 llvm/lib/Target/AMDGPU/CMakeLists.txt |   1 +
 llvm/test/CodeGen/AMDGPU/tgt-verify.ll|  62 +
 llvm/tools/llvm-tgt-verify/CMakeLists.txt |  34 +++
 .../tools/llvm-tgt-verify/llvm-tgt-verify.cpp | 172 ++
 9 files changed, 618 insertions(+), 4 deletions(-)
 create mode 100644 llvm/include/llvm/Target/TargetVerifier.h
 create mode 100644 llvm/include/llvm/Target/TargetVerify/AMDGPUTargetVerifier.h
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUTargetVerifier.cpp
 create mode 100644 llvm/test/CodeGen/AMDGPU/tgt-verify.ll
 create mode 100644 llvm/tools/llvm-tgt-verify/CMakeLists.txt
 create mode 100644 llvm/tools/llvm-tgt-verify/llvm-tgt-verify.cpp

diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 91ccd76c41e07..03c0cf1cf0924 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -214,6 +214,10 @@ class LLVM_ABI Module {
 /// @name Constructors
 /// @{
 public:
+  /// Is this Module valid as determined by one of the verification passes
+  /// i.e. Lint, Verifier, TargetVerifier.
+  bool IsValid = true;
+
   /// Is this Module using intrinsics to record the position of debugging
   /// information, or non-intrinsic records? See IsNewDbgInfoFormat in
   /// \ref BasicBlock.
diff --git a/llvm/include/llvm/Target/TargetVerifier.h 
b/llvm/include/llvm/Target/TargetVerifier.h
new file mode 100644
index 0..e00c6a7b260c9
--- /dev/null
+++ b/llvm/include/llvm/Target/TargetVerifier.h
@@ -0,0 +1,82 @@
+//===-- llvm/Target/TargetVerifier.h - LLVM IR Target Verifier ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines target verifier interfaces that can be used for some
+// validation of input to the system, and for checking that transformations
+// haven't done something bad. In contrast to the Verifier or Lint, the
+// TargetVerifier looks for constructions invalid to a particular target
+// machine.
+//
+// To see what specifically is checked, look at TargetVerifier.cpp or an
+// individual backend's TargetVerifier.
+//
+//===--===//
+
+#ifndef LLVM_TARGET_VERIFIER_H
+#define LLVM_TARGET_VERIFIER_H
+
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Module.h"
+#include "llvm/TargetParser/Triple.h"
+
+namespace llvm {
+
+class Function;
+
+class TargetVerifierPass : public PassInfoMixin {
+public:
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {}
+};
+
+class TargetVerify {
+protected:
+  void WriteValues(ArrayRef Vs) {
+for (const Value *V : Vs) {
+  if (!V)
+continue;
+  if (isa(V)) {
+MessagesStr << *V << '\n';
+  } else {
+V->printAsOperand(MessagesStr, true, Mod);
+MessagesStr << '\n';
+  }
+}
+  }
+
+  /// A check failed, so printout out the condition and the message.
+  ///
+  /// This provides a nice place to put a breakpoint if you want to see why
+  /// something is not correct.
+  void CheckFailed(const Twine &Message) { MessagesStr << Message << '\n'; }
+
+  /// A check failed (with values to print).
+  ///
+  /// This calls the Message-only version so that the above is easier to set
+  /// a breakpoint on.
+  template 
+  void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) {
+CheckFailed(Message);
+WriteValues({V1, Vs...});
+  }
+public:
+  Module *Mod;
+  Triple TT;
+
+  std::string Messages;
+  raw_string_ostream MessagesStr;
+
+  TargetVerify(Module *Mod)
+  : Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())),
+MessagesStr(Messages) {}
+
+  void run(Function &F) {};
+};
+
+} // namespace llvm
+
+#endif // LLVM_TARGET_VERI

[clang] [Clang] Add `noalias` to `this` pointer in C++ constructors (PR #136792)

2025-04-23 Thread Guy David via cfe-commits

guy-david wrote:

Yeah, I realize it's misplaced, I am not familiar with that part of the 
project, see the first paragraph in the PR description.

I don't really agree with your second point about breaking people's existing 
assumptions on UB :) I am willing to run correctness suites to further validate 
this change, if you can recommend on any.
I think an opt-out flag is the wrong way to go about this, because it would add 
more maintenance if this does go against the standard, in which case we should 
revert this PR.

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


[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)

2025-04-23 Thread Balazs Benics via cfe-commits


@@ -645,6 +645,7 @@ struct StreamOperationEvaluator {
   SymbolRef StreamSym = nullptr;
   const StreamState *SS = nullptr;
   const CallExpr *CE = nullptr;
+  std::optional ElemRef;

steakhal wrote:

Ah I completely missed the context. nvm.

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


[clang] [Clang,debuginfo] added vtt parameter in destructor DISubroutineType (PR #130674)

2025-04-23 Thread Reid Kleckner via cfe-commits
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= 
Message-ID:
In-Reply-To: 


rnk wrote:

Thanks!

It looks like the new IR after this change doesn't pass verification, and 
presumably this causes the crash later:
```
$ clang -cc1 t.cpp -triple bpfel  -debug-info-kind=constructor -emit-llvm  -o - 
Attribute after last parameter!
ptr @_ZN3FooD0Ev
fatal error: error in backend: Broken module found, compilation aborted!
```

If you disable the verifier you can see the generated IR, but you can't see the 
"attributes beyond the last parameter". I guess they don't exist, so they don't 
get printed:
```
$ clang -cc1 t.cpp -triple bpfel  -debug-info-kind=constructor -emit-llvm  -o - 
-disable-llvm-verifier
...
; Function Attrs: nounwind
declare !dbg !5 void @_ZN3FooD0Ev() unnamed_addr #136686 
```

Actual base destructor (D0) prototypes have argument attributes that look like 
this:
```
define dso_local void @_ZN3BarD0Ev(ptr noundef nonnull align 8 
dereferenceable(8) %this) unnamed_addr #0 align 2 !dbg !27 {  
```

It's not clear what the BPF target is doing that's special that's forcing the 
compiler to emit this otherwise unused destructor declaration, that seems like 
the edge case here. Regardless, let's roll it back for now.


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


[clang] [CIR] Upstream cir.call with scalar arguments (PR #136810)

2025-04-23 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

This loop is using a bunch of traditional for loops instead of 'range-for' (and 
loops instead of algorithms!).  It would be a vast improvement to replace those 
with std::algorithms if they end up being 'simple' enough, and at least 
range-for loops.

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


[clang] [llvm] [DLCov 2/5] Implement DebugLoc coverage tracking (PR #107279)

2025-04-23 Thread David Blaikie via cfe-commits


@@ -169,6 +169,47 @@ See the discussion in the section about
 :ref:`merging locations` for examples of when the rule for
 dropping locations applies.
 
+.. _NewInstLocations:
+
+Setting locations for new instructions
+--
+
+Whenever a new instruction is created and there is no suitable location for 
that
+instruction, that instruction should be annotated accordingly. There are a set
+of special ``DebugLoc`` values that can be set on an instruction to annotate 
the
+reason that it does not have a valid location. These are as follows:
+
+* ``DebugLoc::getCompilerGenerated()``: This indicates that the instruction is 
a
+  compiler-generated instruction, i.e. it is not associated with any user 
source
+  code.
+
+* ``DebugLoc::getDropped()``: This indicates that the instruction has
+  intentionally had its source location removed, according to the rules for
+  :ref:`dropping locations`; this is set automatically by
+  ``Instruction::dropLocation()``.
+
+* ``DebugLoc::getUnknown()``: This indicates that the instruction does not have

dwblaikie wrote:

Wonder whether it's worth splitting these cases from "there could be a right 
answer here, but it's Too Hard(tm) to find it right now" (places to look to fix 
bugs/improve location coverage) from "this is unrepresentable" (places that 
would benefit from representational changes, but aren't otherwise fixable)

But I don't feel strongly about it.

Otherwise the doc changes look good to me

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


[clang] [Clang,debuginfo] added vtt parameter in destructor DISubroutineType (PR #130674)

2025-04-23 Thread Reid Kleckner via cfe-commits
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= 
Message-ID:
In-Reply-To: 


rnk wrote:

Hm, reverting this change doesn't fix the verifier error, the issue still 
repros for me with this change reverted. Are we sure this was bisected 
correctly? Maybe the verifier error was pre-existing, but after this change, 
now we crash when previously we silently generated IR that doesn't verify.

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


[clang] f418981 - [CIR] Create CIR_TypedAttr common class (#136852)

2025-04-23 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-04-23T23:02:25+02:00
New Revision: f4189817df9b32903d0704028c8d2ea9b0ea5908

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

LOG: [CIR] Create CIR_TypedAttr common class (#136852)

Introduce common base class for attributes with single type parameter.
This mirrors incubator changes introduced in 
https://github.com/llvm/clangir/pull/1583

Added: 


Modified: 
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index cce63c5cae608..fb3f7b1632436 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -27,6 +27,20 @@ class CIR_Attr 
traits = []>
   let mnemonic = attrMnemonic;
 }
 
+class CIR_TypedAttr traits = []>
+: CIR_Attr {
+
+  let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+  return $_get(type.getContext(), type);
+}]>
+  ];
+
+  let assemblyFormat = [{}];
+}
+
 class CIRUnitAttr traits = []>
 : CIR_Attr {
   let returnType = "bool";
@@ -64,43 +78,23 @@ def CIR_BoolAttr : CIR_Attr<"Bool", "bool", 
[TypedAttrInterface]> {
 // ZeroAttr
 
//===--===//
 
-def ZeroAttr : CIR_Attr<"Zero", "zero", [TypedAttrInterface]> {
+def ZeroAttr : CIR_TypedAttr<"Zero", "zero"> {
   let summary = "Attribute to represent zero initialization";
   let description = [{
 The ZeroAttr is used to indicate zero initialization on structs.
   }];
-
-  let parameters = (ins AttributeSelfTypeParameter<"">:$type);
-
-  let builders = [
-AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
-  return $_get(type.getContext(), type);
-}]>
-  ];
-
-  let assemblyFormat = [{}];
 }
 
 
//===--===//
 // UndefAttr
 
//===--===//
 
-def UndefAttr : CIR_Attr<"Undef", "undef", [TypedAttrInterface]> {
+def UndefAttr : CIR_TypedAttr<"Undef", "undef"> {
   let summary = "Represent an undef constant";
   let description = [{
 The UndefAttr represents an undef constant, corresponding to LLVM's notion
 of undef.
   }];
-
-  let parameters = (ins AttributeSelfTypeParameter<"">:$type);
-
-  let builders = [
-AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
-  return $_get(type.getContext(), type);
-}]>
-  ];
-
-  let assemblyFormat = [{}];
 }
 
 
//===--===//



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


[clang] [clang] Do not share ownership of `HeaderSearchOptions` (PR #132984)

2025-04-23 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

CC @AaronBallman as a last resort. The reason for `CompilerInvocation` not 
sharing ownership of its sub-objects is given here: 
https://github.com/llvm/llvm-project/pull/133467#issuecomment-2762065443

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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Erich Keane via cfe-commits


@@ -71,6 +130,23 @@ static cir::CIRCallOpInterface 
emitCallLikeOp(CIRGenFunction &cgf,
   return builder.createCallOp(callLoc, directFuncOp);
 }
 
+const CIRGenFunctionInfo &
+CIRGenTypes::arrangeFreeFunctionType(CanQual fpt) {
+  SmallVector argTypes;
+  for (unsigned i = 0, e = fpt->getNumParams(); i != e; ++i)

erichkeane wrote:

Is this not just a `llvm::copy(fpt->param_types(), 
std::back_inserter(argTypes))` ? 

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


[clang] [clang][modules] Minor improvements to diagnosing `out of date` errors (PR #136612)

2025-04-23 Thread Cyndy Ishida via cfe-commits

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


[clang] 3c9027c - [clang][Modules] Clarify error message when size check fails in lookupModuleFile

2025-04-23 Thread via cfe-commits

Author: Cyndy Ishida
Date: 2025-04-23T10:55:39-07:00
New Revision: 3c9027c1d7aac0c1e54af13182f1b8f58d376115

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

LOG: [clang][Modules] Clarify error message when size check fails in 
lookupModuleFile

Added: 


Modified: 
clang/lib/Serialization/ModuleManager.cpp
clang/test/Modules/explicit-build.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ModuleManager.cpp 
b/clang/lib/Serialization/ModuleManager.cpp
index 61c4e9ed88e9d..d466ea06301a6 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -110,7 +110,9 @@ ModuleManager::addModule(StringRef FileName, ModuleKind 
Type,
   // Look for the file entry. This only fails if the expected size or
   // modification time 
diff er.
   OptionalFileEntryRef Entry;
-  if (Type == MK_ExplicitModule || Type == MK_PrebuiltModule) {
+  const bool IgnoreModTime =
+  (Type == MK_ExplicitModule || Type == MK_PrebuiltModule);
+  if (IgnoreModTime) {
 // If we're not expecting to pull this file out of the module cache, it
 // might have a 
diff erent mtime due to being moved across filesystems in
 // a distributed build. The size must still match, though. (As must the
@@ -120,7 +122,9 @@ ModuleManager::addModule(StringRef FileName, ModuleKind 
Type,
   // Note: ExpectedSize and ExpectedModTime will be 0 for MK_ImplicitModule
   // when using an ASTFileSignature.
   if (lookupModuleFile(FileName, ExpectedSize, ExpectedModTime, Entry)) {
-ErrorStr = "module file has a 
diff erent size or mtime than expected";
+ErrorStr = IgnoreModTime
+   ? "module file has a 
diff erent size than expected"
+   : "module file has a 
diff erent size or mtime than expected";
 return OutOfDate;
   }
 

diff  --git a/clang/test/Modules/explicit-build.cpp 
b/clang/test/Modules/explicit-build.cpp
index fb65508ccf091..50bba0d09966a 100644
--- a/clang/test/Modules/explicit-build.cpp
+++ b/clang/test/Modules/explicit-build.cpp
@@ -199,6 +199,6 @@
 // RUN:-fmodule-file=%t/c.pcm \
 // RUN:%s -DHAVE_A -DHAVE_B -DHAVE_C 2>&1 | FileCheck 
--check-prefix=CHECK-MISMATCHED-B %s
 //
-// CHECK-MISMATCHED-B:  fatal error: module file '{{.*}}b.pcm' is out of 
date and needs to be rebuilt: module file has a 
diff erent size or mtime than expected
+// CHECK-MISMATCHED-B:  fatal error: module file '{{.*}}b.pcm' is out of 
date and needs to be rebuilt: module file has a 
diff erent size than expected
 // CHECK-MISMATCHED-B-NEXT: note: imported by module 'c'
 // CHECK-MISMATCHED-B-NOT:  note:



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


[clang] [CIR] Cleanup support for C functions (PR #136854)

2025-04-23 Thread Erich Keane via cfe-commits

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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> That is not possible, and this is exactly what I'm worried about with all 
> this discussion about making `size_t` more "built-in". `size_t` is specified 
> to be a typedef of a (platform-dependent) standard integer type, and it needs 
> to continue to behave that way; we cannot actually make it a different type, 
> no matter how much cleaner we personally think the language would be if it 
> were. That is not fundamentally changed by the committee adding the `%z` 
> format specifier or `19z` literals or anything like that.

Er, I feel like I must be missing something, because I think we can do this. 
`size_t` is defined to be an implementation-defined unsigned integer type. It 
is *not* required to be defined to `unsigned int` or `unsigned long`, etc 
explicitly, or even a standard integer type at all. So I think we can define it 
to be `__size_t`, so long as that type is compatible with the platform-specific 
underlying type.

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


[clang] [Clang][NFC] Use temporary instead of one use local variable when creating APValue (PR #137029)

2025-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)


Changes

Static analysis flagged this code b/c we should have been using std::move when 
passing by value since the value is not used anymore. In this case the simpler 
fix is just to use a temporary value as many of the other cases where we simply 
use MakeIntValue to then create an APValue result from it.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-3) 


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f5a10e0db85ad..72edb72ceb600 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6147,9 +6147,8 @@ static APValue EvaluateSizeTTypeTrait(Sema &S, TypeTrait 
Kind,
   S.Diag(KWLoc, diag::err_arg_is_not_destructurable) << T << ArgRange;
   return APValue();
 }
-llvm::APSInt V =
-S.getASTContext().MakeIntValue(*Size, S.getASTContext().getSizeType());
-return APValue{V};
+return APValue(
+S.getASTContext().MakeIntValue(*Size, 
S.getASTContext().getSizeType()));
 break;
   }
   default:

``




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


[clang] [CIR] Upstream cir.call with scalar arguments (PR #136810)

2025-04-23 Thread Bruno Cardoso Lopes via cfe-commits


@@ -68,20 +168,70 @@ static cir::CIRCallOpInterface 
emitCallLikeOp(CIRGenFunction &cgf,
   assert(builder.getInsertionBlock() && "expected valid basic block");
   assert(!cir::MissingFeatures::opCallIndirect());
 
-  return builder.createCallOp(callLoc, directFuncOp);
+  return builder.createCallOp(callLoc, directFuncOp, cirCallArgs);
 }
 
 RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
 const CIRGenCallee &callee,
 ReturnValueSlot returnValue,
+const CallArgList &args,
 cir::CIRCallOpInterface *callOp,
 mlir::Location loc) {
   QualType retTy = funcInfo.getReturnType();
   const cir::ABIArgInfo &retInfo = funcInfo.getReturnInfo();
 
-  assert(!cir::MissingFeatures::opCallArgs());
+  ClangToCIRArgMapping cirFuncArgs(cgm.getASTContext(), funcInfo);
+  SmallVector cirCallArgs(cirFuncArgs.totalCIRArgs());
+
   assert(!cir::MissingFeatures::emitLifetimeMarkers());
 
+  // Translate all of the arguments as necessary to match the CIR lowering.
+  assert(funcInfo.arg_size() == args.size() &&
+ "Mismatch between function signature & arguments.");
+  unsigned argNo = 0;
+  const auto *infoIter = funcInfo.arg_begin();
+  for (auto i = args.begin(), e = args.end(); i != e;
+   ++i, ++infoIter, ++argNo) {
+const cir::ABIArgInfo &argInfo = infoIter->info;
+
+// Insert a padding argument to ensure proper alignment.
+assert(!cir::MissingFeatures::opCallPaddingArgs());
+
+unsigned firstCIRArg;
+unsigned numCIRArgs;
+std::tie(firstCIRArg, numCIRArgs) = cirFuncArgs.getCIRArgs(argNo);
+
+switch (argInfo.getKind()) {
+case cir::ABIArgInfo::Direct: {
+  if (!mlir::isa(argInfo.getCoerceToType()) &&
+  argInfo.getCoerceToType() == convertType(infoIter->type) &&
+  argInfo.getDirectOffset() == 0) {
+assert(numCIRArgs == 1);
+assert(!cir::MissingFeatures::opCallAggregateArgs());
+mlir::Value v = i->getKnownRValue().getScalarVal();
+
+assert(!cir::MissingFeatures::opCallExtParameterInfo());
+
+// We might have to widen integers, but we should never truncate.
+assert(!cir::MissingFeatures::opCallWidenArg());
+
+// If the argument doesn't match, perform a bitcast to coerce it. This
+// can happen due to trivial type mismatches.
+assert(!cir::MissingFeatures::opCallBitcastArg());

bcardosolopes wrote:

I'm a bit worried with this series of missing features because in theory we 
should be `errorNYI` here.

However this is also tricky because in the incubator all of that is delayed 
until call conv lowering pass (which is currently off by default) and we don't 
have these bits in upstreaming just yet.

Ideally we don't want to repeat the same mistake again and bake call conv 
lowering soon enough, so contributors are forced to implement the proper 
mechanism as we incrementally add more call bits, which means getting closer to 
LLVM OG as we go. Not saying you should do it right away in this PR, but we 
should have a plan for something soon. Any extra thoughts @andykaylor 
@erichkeane @xlauko ?

For the time being: perhaps add a big comment before the first one just stating 
something along of the lines of what I just said so it's more clear to whoever 
touches this next?

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


[clang] [CIR] Upstream cir.call with scalar arguments (PR #136810)

2025-04-23 Thread Bruno Cardoso Lopes via cfe-commits


@@ -1496,6 +1496,10 @@ def FuncOp : CIR_Op<"func", [
return getFunctionType().getReturnTypes();
 }
 
+// TODO(cir): this should be an operand attribute, but for now we just 
hard-
+// wire this as a function. Will later add a $no_proto argument to this op.
+bool getNoProto() { return false; }

bcardosolopes wrote:

Maybe add assert on missing feature here?

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


[clang] [CIR] Create CIR_TypedAttr common class (PR #136852)

2025-04-23 Thread Bruno Cardoso Lopes via cfe-commits

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


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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

With template specialization resugaring, these being typedefs still help 
somewhat:
https://compiler-explorer.com/z/qKxbYMEGq

You have to make a bit of contortion to expose the intermediate type, but I 
think that's partly due to a different problem, where in diagnostics we don't 
try to skip over some unhelpful top level typedefs, like vector's `value_type`.

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #131838)

2025-04-23 Thread Shilei Tian via cfe-commits

shiltian wrote:

Hmm, this PR is much shorter than it used to be.

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


[clang] [llvm] Reland "[HLSL][RootSignature] Implement initial parsing of the descriptor table clause params" (PR #136740)

2025-04-23 Thread Finn Plummer via cfe-commits

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


[clang] [Clang] Warning as error for fold expressions over comparison operators (PR #136836)

2025-04-23 Thread via cfe-commits

cor3ntin wrote:

https://compiler-explorer.com/z/zoze5br4d it turns out that we already produce 
a warning for right fold... hum, this will require more work

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #131838)

2025-04-23 Thread Shilei Tian via cfe-commits


@@ -423,8 +423,8 @@ static void instantiateOMPDeclareVariantAttr(
   auto *FD = cast(New);
   auto *ThisContext = dyn_cast_or_null(FD->getDeclContext());
 
-  auto &&SubstExpr = [FD, ThisContext, &S, &TemplateArgs](Expr *E) {
-if (auto *DRE = dyn_cast(E->IgnoreParenImpCasts()))
+  auto &&SubstExpr = [FD, ThisContext, &S, &TemplateArgs, New](Expr *E) {

shiltian wrote:

Where is `New` used inside of the lambda?

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


[clang] b8e420e - Reland "[HLSL][RootSignature] Implement initial parsing of the descriptor table clause params" (#136740)

2025-04-23 Thread via cfe-commits

Author: Finn Plummer
Date: 2025-04-23T11:51:24-07:00
New Revision: b8e420e424b41f67019155055f4f600ba0454189

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

LOG: Reland "[HLSL][RootSignature] Implement initial parsing of the descriptor 
table clause params" (#136740)

This pr relands #133800.

It addresses the compilation error of using a shadowed name `Register`
for both the struct name and the data member holding this type:
`Register Register`. It resolves the issues my renaming the data members
called `Register` to `Reg`.

This issue was not caught as the current pre-merge checks do not include
a build of `llvm;clang` using the gcc/g++ compilers and this is not
erroneous with clang/clang++.

Second part of #126569

-

Co-authored-by: Finn Plummer 

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/ParseHLSLRootSignature.h
clang/lib/Parse/ParseHLSLRootSignature.cpp
clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 9975520f4f9ff..72e765bcb800d 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1836,8 +1836,11 @@ def err_hlsl_virtual_function
 def err_hlsl_virtual_inheritance
 : Error<"virtual inheritance is unsupported in HLSL">;
 
-// HLSL Root Siganture diagnostic messages
+// HLSL Root Signature Parser Diagnostics
 def err_hlsl_unexpected_end_of_params
 : Error<"expected %0 to denote end of parameters, or, another valid 
parameter of %1">;
+def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' 
multiple times">;
+def err_hlsl_rootsig_missing_param : Error<"did not specify mandatory 
parameter '%0'">;
+def err_hlsl_number_literal_overflow : Error<"integer literal is too large to 
be represented as a 32-bit %select{signed |}0 integer type">;
 
 } // end of Parser diagnostics

diff  --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index a8dd6b02501ae..3eb3f8ea8422d 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -40,26 +40,31 @@ class RootSignatureParser {
 private:
   DiagnosticsEngine &getDiags() { return PP.getDiagnostics(); }
 
-  // All private Parse.* methods follow a similar pattern:
+  // All private parse.* methods follow a similar pattern:
   //   - Each method will start with an assert to denote what the CurToken is
   // expected to be and will parse from that token forward
   //
   //   - Therefore, it is the callers responsibility to ensure that you are
   // at the correct CurToken. This should be done with the pattern of:
   //
-  //  if (TryConsumeExpectedToken(RootSignatureToken::Kind))
-  //if (Parse.*())
-  //  return true;
+  //  if (tryConsumeExpectedToken(RootSignatureToken::Kind)) {
+  //auto ParsedObject = parse.*();
+  //if (!ParsedObject.has_value())
+  //  return std::nullopt;
+  //...
+  // }
   //
   // or,
   //
-  //  if (ConsumeExpectedToken(RootSignatureToken::Kind, ...))
-  //return true;
-  //  if (Parse.*())
-  //return true;
+  //  if (consumeExpectedToken(RootSignatureToken::Kind, ...))
+  //return std::nullopt;
+  //  auto ParsedObject = parse.*();
+  //  if (!ParsedObject.has_value())
+  //return std::nullopt;
+  //  ...
   //
-  //   - All methods return true if a parsing error is encountered. It is the
-  // callers responsibility to propogate this error up, or deal with it
+  //   - All methods return std::nullopt if a parsing error is encountered. It
+  // is the callers responsibility to propogate this error up, or deal with it
   // otherwise
   //
   //   - An error will be raised if the proceeding tokens are not what is
@@ -69,6 +74,23 @@ class RootSignatureParser {
   bool parseDescriptorTable();
   bool parseDescriptorTableClause();
 
+  /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
+  /// order and only exactly once. `ParsedClauseParams` denotes the current
+  /// state of parsed params
+  struct ParsedClauseParams {
+std::optional Reg;
+std::optional Space;
+  };
+  std::optional
+  parseDescriptorTableClauseParams(RootSignatureToken::Kind RegType);
+
+  std::optional parseUIntParam();
+  std::optional parseRegister();
+
+  /// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned
+  /// 32-bit integer
+  std::optional handleUIntLiteral();
+
   /// Invoke the Lexer to consume a token and update CurToken with the result
   void consu

[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-23 Thread John McCall via cfe-commits

rjmccall wrote:

> > At least, it must ensure that `__size_t` is equivalent to `size_t` and 
> > generates the same mangled name.
> 
> Is that possible? @rjmccall

If `size_t` is a different type from `__size_t`, then `void foo(size_t);` 
declares a different entity from `void foo(__size_t);`. The two functions 
therefore must be mangled differently in order to allow them to coexist in the 
program. The same rule applies consistently to template specializations and 
everywhere else a type can be written.

The result is that, no, this is not possible. If you want two types to mangle 
the same way, you are really saying that they are the same type. This is 
relationship between a type and a sugaring of the type, not the relationship 
between two different types that share a representation.

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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Something being unspecified in the standard doesn't mean we're unconstrained. 
> In this case, it is unspecified because it is allowed to vary between 
> platforms, but platforms are required to specify what type `size_t` is, and 
> it is well-defined to write code based on that assumption on that platform. 
> Unportable code is not invalid code. Almost all C and C++ code makes some 
> non-portable assumptions, and this one in particular is very common.
> 
> Moreover, C++ encodes the underlying type of typedefs into the ABI. `size_t` 
> appears in a lot of type signatures, and it is mangled as its underlying 
> type. (This is actually very annoying for writing portable compiler tests 
> because e.g. `operator new(size_t)` has a different mangled name on different 
> targets, but we just have to deal with it.) The type produced by `sizeof` 
> expressions can similarly easily propagate into the ABI through template 
> argument deduction and `auto`. None of this can be changed without massively 
> breaking the ABI. It is off the table.
> 
> Now, C might be different because of how loose the compatible-types rule is. 
> If you want to pursue this just for C, we can talk about it; I don't know 
> that it's a good idea, but we can at least talk about it.

Okay, I see where the disconnect is now. I was using standards terms like 
"compatible" when what I was really meaning was "alias". e.g., I wasn't 
suggesting we introduce a distinct, new type. I was suggesting we take the 
existing types and give them a spelling of `__size_t`. Same for how we already 
handle things like `_int32` and `int`; they're the same type, just with 
different ways of spelling it.

But I'm more and more thinking Richard is correct, this is just a fancy form of 
sugar.

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


[clang] [llvm] [TargetVerifier][AMDGPU] Add TargetVerifier. (PR #123609)

2025-04-23 Thread via cfe-commits

https://github.com/jofrn updated 
https://github.com/llvm/llvm-project/pull/123609

>From 210b6d80bcfbbcd216f98199df386280724561e2 Mon Sep 17 00:00:00 2001
From: jofernau 
Date: Mon, 20 Jan 2025 04:51:26 -0800
Subject: [PATCH 01/12] [TargetVerifier][AMDGPU] Add TargetVerifier.

This pass verifies the IR for an individual backend. This is
different than Lint because it consolidates all checks for a
given backend in a single pass. A check for Lint may be
undefined behavior across all targets, whereas a check in
TargetVerifier would only pertain to the specified target
but can check more than just undefined behavior such are IR
validity. A use case of this would be to reject programs
with invalid IR while fuzzing.
---
 llvm/include/llvm/IR/Module.h |   4 +
 llvm/include/llvm/Target/TargetVerifier.h |  82 +++
 .../TargetVerify/AMDGPUTargetVerifier.h   |  36 +++
 llvm/lib/IR/Verifier.cpp  |  18 +-
 .../Target/AMDGPU/AMDGPUTargetVerifier.cpp| 213 ++
 llvm/lib/Target/AMDGPU/CMakeLists.txt |   1 +
 llvm/test/CodeGen/AMDGPU/tgt-verify.ll|  62 +
 llvm/tools/llvm-tgt-verify/CMakeLists.txt |  34 +++
 .../tools/llvm-tgt-verify/llvm-tgt-verify.cpp | 172 ++
 9 files changed, 618 insertions(+), 4 deletions(-)
 create mode 100644 llvm/include/llvm/Target/TargetVerifier.h
 create mode 100644 llvm/include/llvm/Target/TargetVerify/AMDGPUTargetVerifier.h
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUTargetVerifier.cpp
 create mode 100644 llvm/test/CodeGen/AMDGPU/tgt-verify.ll
 create mode 100644 llvm/tools/llvm-tgt-verify/CMakeLists.txt
 create mode 100644 llvm/tools/llvm-tgt-verify/llvm-tgt-verify.cpp

diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 91ccd76c41e07..03c0cf1cf0924 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -214,6 +214,10 @@ class LLVM_ABI Module {
 /// @name Constructors
 /// @{
 public:
+  /// Is this Module valid as determined by one of the verification passes
+  /// i.e. Lint, Verifier, TargetVerifier.
+  bool IsValid = true;
+
   /// Is this Module using intrinsics to record the position of debugging
   /// information, or non-intrinsic records? See IsNewDbgInfoFormat in
   /// \ref BasicBlock.
diff --git a/llvm/include/llvm/Target/TargetVerifier.h 
b/llvm/include/llvm/Target/TargetVerifier.h
new file mode 100644
index 0..e00c6a7b260c9
--- /dev/null
+++ b/llvm/include/llvm/Target/TargetVerifier.h
@@ -0,0 +1,82 @@
+//===-- llvm/Target/TargetVerifier.h - LLVM IR Target Verifier ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines target verifier interfaces that can be used for some
+// validation of input to the system, and for checking that transformations
+// haven't done something bad. In contrast to the Verifier or Lint, the
+// TargetVerifier looks for constructions invalid to a particular target
+// machine.
+//
+// To see what specifically is checked, look at TargetVerifier.cpp or an
+// individual backend's TargetVerifier.
+//
+//===--===//
+
+#ifndef LLVM_TARGET_VERIFIER_H
+#define LLVM_TARGET_VERIFIER_H
+
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Module.h"
+#include "llvm/TargetParser/Triple.h"
+
+namespace llvm {
+
+class Function;
+
+class TargetVerifierPass : public PassInfoMixin {
+public:
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {}
+};
+
+class TargetVerify {
+protected:
+  void WriteValues(ArrayRef Vs) {
+for (const Value *V : Vs) {
+  if (!V)
+continue;
+  if (isa(V)) {
+MessagesStr << *V << '\n';
+  } else {
+V->printAsOperand(MessagesStr, true, Mod);
+MessagesStr << '\n';
+  }
+}
+  }
+
+  /// A check failed, so printout out the condition and the message.
+  ///
+  /// This provides a nice place to put a breakpoint if you want to see why
+  /// something is not correct.
+  void CheckFailed(const Twine &Message) { MessagesStr << Message << '\n'; }
+
+  /// A check failed (with values to print).
+  ///
+  /// This calls the Message-only version so that the above is easier to set
+  /// a breakpoint on.
+  template 
+  void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) {
+CheckFailed(Message);
+WriteValues({V1, Vs...});
+  }
+public:
+  Module *Mod;
+  Triple TT;
+
+  std::string Messages;
+  raw_string_ostream MessagesStr;
+
+  TargetVerify(Module *Mod)
+  : Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())),
+MessagesStr(Messages) {}
+
+  void run(Function &F) {};
+};
+
+} // namespace llvm
+
+#endif // LLVM_TARGET_VERI

  1   2   3   4   5   >