[clang-tools-extra] [clangd] fix extract-to-function for overloaded operators (PR #81640)

2024-10-31 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

> Do I understand correctly that this is a partial fix for 
> [clangd/clangd#1254](https://github.com/clangd/clangd/issues/1254) in that it 
> addresses the issue with overloaded operators in particular, but it still 
> leaves in place the limitation that a **single** expression statement (of any 
> kind) cannot be extracted?

Exactly

> If so, would you mind adding an "unavailable" test case for the latter case, 
> with some sort of "TODO, we'd like to relax this limitation" comment?

Done


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


[clang] [libclang/python] Clean up tests (PR #114383)

2024-10-31 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/114383

Clean up imports via isort
Remove unused imports
Remove unused variables
Remove Python <3.6 compatibility measures

>From 25e10c362338265e07ec045b2b8bbe692ae18092 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 24 Aug 2024 11:33:22 +0200
Subject: [PATCH] [libclang/python] Clean up tests

Clean up imports via isort
Remove duplicate imports
Remove Python <3.6 compatibility measures
---
 .../tests/cindex/test_access_specifiers.py| 12 ++--
 .../bindings/python/tests/cindex/test_cdb.py  | 29 --
 .../tests/cindex/test_code_completion.py  | 15 ++---
 .../python/tests/cindex/test_comment.py   |  8 +--
 .../python/tests/cindex/test_cursor.py| 31 +-
 .../python/tests/cindex/test_cursor_kind.py   |  5 +-
 .../python/tests/cindex/test_diagnostics.py   |  7 +--
 .../python/tests/cindex/test_enums.py | 16 ++---
 .../test_exception_specification_kind.py  | 11 ++--
 .../bindings/python/tests/cindex/test_file.py |  5 +-
 .../python/tests/cindex/test_index.py |  8 +--
 .../python/tests/cindex/test_linkage.py   | 12 ++--
 .../python/tests/cindex/test_location.py  | 19 +++---
 .../python/tests/cindex/test_rewrite.py   | 10 +---
 .../python/tests/cindex/test_source_range.py  |  4 +-
 .../python/tests/cindex/test_tls_kind.py  | 12 ++--
 .../python/tests/cindex/test_token_kind.py|  5 +-
 .../python/tests/cindex/test_tokens.py| 11 +---
 .../tests/cindex/test_translation_unit.py | 58 ---
 .../bindings/python/tests/cindex/test_type.py | 18 ++
 clang/bindings/python/tests/cindex/util.py| 20 +--
 21 files changed, 121 insertions(+), 195 deletions(-)

diff --git a/clang/bindings/python/tests/cindex/test_access_specifiers.py 
b/clang/bindings/python/tests/cindex/test_access_specifiers.py
index c1cc18ebe6e589..ca2bbd3cc86117 100644
--- a/clang/bindings/python/tests/cindex/test_access_specifiers.py
+++ b/clang/bindings/python/tests/cindex/test_access_specifiers.py
@@ -1,18 +1,14 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import AccessSpecifier, Config
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import AccessSpecifier
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
-
-from .util import get_cursor
-from .util import get_tu
-
 import unittest
 
+from .util import get_cursor, get_tu
+
 
 class TestAccessSpecifiers(unittest.TestCase):
 def test_access_specifiers(self):
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py 
b/clang/bindings/python/tests/cindex/test_cdb.py
index a5cc22796aa2ad..d0adbb36d66f2a 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -1,20 +1,14 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import CompilationDatabase, CompilationDatabaseError, Config
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import CompilationDatabase
-from clang.cindex import CompilationDatabaseError
-from clang.cindex import CompileCommands
-from clang.cindex import CompileCommand
-import os
 import gc
-import unittest
 import sys
-from .util import skip_if_no_fspath
-from .util import str_to_path
-
+import unittest
+from pathlib import Path
 
 kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
@@ -31,7 +25,7 @@ def test_create_fail(self):
 with open(os.devnull, "wb") as null:
 os.dup2(null.fileno(), 2)
 with self.assertRaises(CompilationDatabaseError) as cm:
-cdb = CompilationDatabase.fromDirectory(path)
+CompilationDatabase.fromDirectory(path)
 os.dup2(stderr, 2)
 os.close(stderr)
 
@@ -40,7 +34,7 @@ def test_create_fail(self):
 
 def test_create(self):
 """Check we can load a compilation database"""
-cdb = CompilationDatabase.fromDirectory(kInputsDir)
+CompilationDatabase.fromDirectory(kInputsDir)
 
 def test_lookup_succeed(self):
 """Check we get some results if the file exists in the db"""
@@ -48,13 +42,10 @@ def test_lookup_succeed(self):
 cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
 self.assertNotEqual(len(cmds), 0)
 
-@skip_if_no_fspath
 def test_lookup_succeed_pathlike(self):
 """Same as test_lookup_succeed, but with PathLikes"""
-cdb = CompilationDatabase.fromDirectory(str_to_path(kInputsDir))
-cmds = cdb.getCompileCommands(
-str_to_path("/home/john.doe/MyProject/project.cpp")
-)
+cdb = CompilationDatabase.fromDirectory(Path(kInputsDir))
+cmds = 
cdb.getCompileCommands(Path("/home/john.doe/MyProject/project.cpp"))
 self.assertNotEqual(len(cmds), 0)
 
 def test_all_compilecommand

[clang] [libclang/python] Clean up tests (PR #114383)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Clean up imports via isort
Remove unused imports
Remove unused variables
Remove Python <3.6 compatibility measures

---

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


21 Files Affected:

- (modified) clang/bindings/python/tests/cindex/test_access_specifiers.py 
(+4-8) 
- (modified) clang/bindings/python/tests/cindex/test_cdb.py (+10-19) 
- (modified) clang/bindings/python/tests/cindex/test_code_completion.py (+6-9) 
- (modified) clang/bindings/python/tests/cindex/test_comment.py (+4-4) 
- (modified) clang/bindings/python/tests/cindex/test_cursor.py (+15-16) 
- (modified) clang/bindings/python/tests/cindex/test_cursor_kind.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_diagnostics.py (+3-4) 
- (modified) clang/bindings/python/tests/cindex/test_enums.py (+8-8) 
- (modified) 
clang/bindings/python/tests/cindex/test_exception_specification_kind.py (+5-6) 
- (modified) clang/bindings/python/tests/cindex/test_file.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_index.py (+3-5) 
- (modified) clang/bindings/python/tests/cindex/test_linkage.py (+4-8) 
- (modified) clang/bindings/python/tests/cindex/test_location.py (+10-9) 
- (modified) clang/bindings/python/tests/cindex/test_rewrite.py (+2-8) 
- (modified) clang/bindings/python/tests/cindex/test_source_range.py (+2-2) 
- (modified) clang/bindings/python/tests/cindex/test_tls_kind.py (+4-8) 
- (modified) clang/bindings/python/tests/cindex/test_token_kind.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_tokens.py (+3-8) 
- (modified) clang/bindings/python/tests/cindex/test_translation_unit.py 
(+25-33) 
- (modified) clang/bindings/python/tests/cindex/test_type.py (+6-12) 
- (modified) clang/bindings/python/tests/cindex/util.py (+1-19) 


``diff
diff --git a/clang/bindings/python/tests/cindex/test_access_specifiers.py 
b/clang/bindings/python/tests/cindex/test_access_specifiers.py
index c1cc18ebe6e589..ca2bbd3cc86117 100644
--- a/clang/bindings/python/tests/cindex/test_access_specifiers.py
+++ b/clang/bindings/python/tests/cindex/test_access_specifiers.py
@@ -1,18 +1,14 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import AccessSpecifier, Config
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import AccessSpecifier
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
-
-from .util import get_cursor
-from .util import get_tu
-
 import unittest
 
+from .util import get_cursor, get_tu
+
 
 class TestAccessSpecifiers(unittest.TestCase):
 def test_access_specifiers(self):
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py 
b/clang/bindings/python/tests/cindex/test_cdb.py
index a5cc22796aa2ad..d0adbb36d66f2a 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -1,20 +1,14 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import CompilationDatabase, CompilationDatabaseError, Config
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import CompilationDatabase
-from clang.cindex import CompilationDatabaseError
-from clang.cindex import CompileCommands
-from clang.cindex import CompileCommand
-import os
 import gc
-import unittest
 import sys
-from .util import skip_if_no_fspath
-from .util import str_to_path
-
+import unittest
+from pathlib import Path
 
 kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
@@ -31,7 +25,7 @@ def test_create_fail(self):
 with open(os.devnull, "wb") as null:
 os.dup2(null.fileno(), 2)
 with self.assertRaises(CompilationDatabaseError) as cm:
-cdb = CompilationDatabase.fromDirectory(path)
+CompilationDatabase.fromDirectory(path)
 os.dup2(stderr, 2)
 os.close(stderr)
 
@@ -40,7 +34,7 @@ def test_create_fail(self):
 
 def test_create(self):
 """Check we can load a compilation database"""
-cdb = CompilationDatabase.fromDirectory(kInputsDir)
+CompilationDatabase.fromDirectory(kInputsDir)
 
 def test_lookup_succeed(self):
 """Check we get some results if the file exists in the db"""
@@ -48,13 +42,10 @@ def test_lookup_succeed(self):
 cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
 self.assertNotEqual(len(cmds), 0)
 
-@skip_if_no_fspath
 def test_lookup_succeed_pathlike(self):
 """Same as test_lookup_succeed, but with PathLikes"""
-cdb = CompilationDatabase.fromDirectory(str_to_path(kInputsDir))
-cmds = cdb.getCompileCommands(
-str_to_path("/home/john.doe/MyProject/project.cpp")
-)
+cdb = CompilationDatabase.fromDirectory(Path(k

[clang] [C++20] [Modules] Convert '-fexperimental-modules-reduced-bmi' to '-fmodules-reduced-bmi' (PR #114382)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

According to our previous consensus in 
https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi, the 
reduced BMI will be the default and recommend users to use the new option.

The `-fexperimental-modules-reduced-bmi ` option is introduced in 
https://github.com/llvm/llvm-project/pull/85050 in Mar13 and released in 19.x. 
And now we are in 20's release cycle. Also I rarely receive issue reports about 
reduced BMI. No matter it is due to the quality of reduced BMI is really good 
or no one uses it. I think we should speed up the process to get more people 
get involved.

This patch literally did the second point in 
https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi

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


5 Files Affected:

- (modified) clang/docs/StandardCPlusPlusModules.rst (+9-9) 
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+8) 
- (modified) clang/include/clang/Driver/Options.td (+4-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10-2) 
- (modified) clang/test/Driver/module-fgen-reduced-bmi.cppm (+24-2) 


``diff
diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 8e22adad15106e..26b29337ce42cb 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -602,16 +602,16 @@ unnecessary dependencies for the BMI. To mitigate the 
problem, Clang has a
 compiler option to reduce the information contained in the BMI. These two
 formats are known as Full BMI and Reduced BMI, respectively.
 
-Users can use the ``-fexperimental-modules-reduced-bmi`` option to produce a
+Users can use the ``-fmodules-reduced-bmi`` option to produce a
 Reduced BMI.
 
 For the one-phase compilation model (CMake implements this model), with
-``-fexperimental-modules-reduced-bmi``, the generated BMI will be a Reduced
+``-fmodules-reduced-bmi``, the generated BMI will be a Reduced
 BMI automatically. (The output path of the BMI is specified by
 ``-fmodule-output=`` as usual with the one-phase compilation model).
 
 It is also possible to produce a Reduced BMI with the two-phase compilation
-model. When ``-fexperimental-modules-reduced-bmi``, ``--precompile``, and
+model. When ``-fmodules-reduced-bmi``, ``--precompile``, and
 ``-fmodule-output=`` are specified, the generated BMI specified by ``-o`` will
 be a full BMI and the BMI specified by ``-fmodule-output=`` will be a Reduced
 BMI. The dependency graph in this case would look like:
@@ -625,7 +625,7 @@ BMI. The dependency graph in this case would look like:
-> ...
-> consumer_n.cpp
 
-Clang does not emit diagnostics when ``-fexperimental-modules-reduced-bmi`` is
+Clang does not emit diagnostics when ``-fmodules-reduced-bmi`` is
 used with a non-module unit. This design permits users of the one-phase
 compilation model to try using reduced BMIs without needing to modify the build
 system. The two-phase compilation module requires build system support.
@@ -691,7 +691,7 @@ ensure it is reachable, e.g. ``using N::g;``.
 Support for Reduced BMIs is still experimental, but it may become the default
 in the future. The expected roadmap for Reduced BMIs as of Clang 19.x is:
 
-1. ``-fexperimental-modules-reduced-bmi`` is opt-in for 1~2 releases. The 
period depends
+1. ``-fmodules-reduced-bmi`` is opt-in for 1~2 releases. The period depends
on user feedback and may be extended.
 2. Announce that Reduced BMIs are no longer experimental and introduce
``-fmodules-reduced-bmi`` as a new option, and recommend use of the new
@@ -814,8 +814,8 @@ With reduced BMI, non-cascading changes can be more 
powerful. For example,
 
 .. code-block:: console
 
-  $ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm  
-fexperimental-modules-reduced-bmi -o A.o
-  $ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm  
-fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
+  $ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm  -fmodules-reduced-bmi 
-o A.o
+  $ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm  -fmodules-reduced-bmi 
-o B.o -fmodule-file=A=A.pcm
   $ md5sum B.pcm
   6c2bd452ca32ab418bf35cd141b060b9  B.pcm
 
@@ -831,8 +831,8 @@ and recompile the example:
 
 .. code-block:: console
 
-  $ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm  
-fexperimental-modules-reduced-bmi -o A.o
-  $ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm  
-fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
+  $ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm  -fmodules-reduced-bmi 
-o A.o
+  $ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm  -fmodules-reduced-bmi 
-o B.o -fmodule-file=A=A.pcm
   $ md5sum B.pcm
   6c2bd452ca32ab418bf35cd141b060b9  B.pcm
 
diff --git a/clang/include/clang/Basic/Di

[clang-tools-extra] [clangd] fix extract-to-function for overloaded operators (PR #81640)

2024-10-31 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/81640

>From 0fc20dcd188510cebce43da06619729ed20884c1 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Tue, 13 Feb 2024 18:59:16 +0100
Subject: [PATCH 1/3] [clangd] fix extract-to-function for overloaded operators

When selecting code that contains the use of overloaded operators,
the SelectionTree will attribute the operator to the operator
declaration, not to the `CXXOperatorCallExpr`. To allow
extract-to-function to work with these operators, make unselected
`CXXOperatorCallExpr`s valid root statements, just like `DeclStmt`s.

Partially fixes clangd/clangd#1254
---
 .../refactor/tweaks/ExtractFunction.cpp   | 15 +++---
 .../unittests/tweaks/ExtractFunctionTests.cpp | 47 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++
 3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
index 0302839c58252e..aae480175b33f6 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -56,6 +56,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
@@ -70,7 +71,6 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/raw_os_ostream.h"
 #include 
 
 namespace clang {
@@ -104,9 +104,12 @@ bool isRootStmt(const Node *N) {
   // Root statement cannot be partially selected.
   if (N->Selected == SelectionTree::Partial)
 return false;
-  // Only DeclStmt can be an unselected RootStmt since VarDecls claim the 
entire
-  // selection range in selectionTree.
-  if (N->Selected == SelectionTree::Unselected && !N->ASTNode.get())
+  // A DeclStmt can be an unselected RootStmt since VarDecls claim the entire
+  // selection range in selectionTree. Additionally, an CXXOperatorCallExpr of 
a
+  // binary operation can be unselected because it's children claim the entire
+  // selection range in the selection tree (e.g. <<).
+  if (N->Selected == SelectionTree::Unselected && !N->ASTNode.get() 
&&
+  !N->ASTNode.get())
 return false;
   return true;
 }
@@ -913,8 +916,8 @@ Expected ExtractFunction::apply(const 
Selection &Inputs) {
 
   tooling::Replacements OtherEdit(
   createForwardDeclaration(*ExtractedFunc, SM));
-  if (auto PathAndEdit = Tweak::Effect::fileEdit(SM, SM.getFileID(*FwdLoc),
- OtherEdit))
+  if (auto PathAndEdit =
+  Tweak::Effect::fileEdit(SM, SM.getFileID(*FwdLoc), OtherEdit))
 MultiFileEffect->ApplyEdits.try_emplace(PathAndEdit->first,
 PathAndEdit->second);
   else
diff --git a/clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
index dec63d454d52c6..8e347b516c6ffe 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
@@ -571,6 +571,53 @@ int getNum(bool Superstitious, int Min, int Max) {
   EXPECT_EQ(apply(Before), After);
 }
 
+TEST_F(ExtractFunctionTest, OverloadedOperators) {
+  Context = File;
+  std::string Before = R"cpp(struct A {
+int operator+(int x) { return x; }
+  };
+  A &operator<<(A &, int);
+  A &operator|(A &, int);
+
+  A stream{};
+
+  void foo(int, int);
+
+  int main() {
+[[foo(1, 2);
+foo(3, 4);
+stream << 42;
+stream + 42;
+stream | 42;
+foo(1, 2);
+foo(3, 4);]]
+  })cpp";
+  std::string After =
+  R"cpp(struct A {
+int operator+(int x) { return x; }
+  };
+  A &operator<<(A &, int);
+  A &operator|(A &, int);
+
+  A stream{};
+
+  void foo(int, int);
+
+  void extracted() {
+foo(1, 2);
+foo(3, 4);
+stream << 42;
+stream + 42;
+stream | 42;
+foo(1, 2);
+foo(3, 4);
+}
+int main() {
+extracted();
+  })cpp";
+  EXPECT_EQ(apply(Before), After);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 2c71e1fcb747bc..f52ad4887ddc8d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -78,6 +78,9 @@ Co

[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-31 Thread Sylvestre Ledru via cfe-commits

sylvestre wrote:

@everythingfunctional with this change and install, we are installing flang 
with the -20 in the install dir:
` -- Installing: /build/source/debian/tmp/usr/lib/llvm-20/bin/flang-20 `

it should not be the case, it should be named `/usr/lib/llvm-20/bin/flang` to 
match what is done elsewhere

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


[clang] [llvm] [LoongArch] Support amcas[_db].{b/h/w/d} instructions. (PR #114189)

2024-10-31 Thread WÁNG Xuěruì via cfe-commits

xen0n wrote:

Also please split the LLVM and Clang changes.

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


[clang] [clang] Fix an em/email typo in Maintainers.rst (PR #114385)

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

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

Pretty sure this was a mistake, everyone else uses "email".

>From cba89dbe6f6c1c24329b945f0d7732b623c222e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 31 Oct 2024 11:00:39 +0100
Subject: [PATCH] [clang] Fix an em/email typo in Maintainers.rst

Pretty sure this was a mistake, everyone else uses "email".
---
 clang/Maintainers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index 35c218d8e0e8fa..896b463d882d08 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -72,7 +72,7 @@ Sema
 Experimental new constant interpreter
 ~
 | Timm Bäder
-| tbaeder\@redhat.com (em), tbaeder (Phabricator), tbaederr (GitHub), tbaeder 
(Discourse), tbaeder (Discord)
+| tbaeder\@redhat.com (email), tbaeder (Phabricator), tbaederr (GitHub), 
tbaeder (Discourse), tbaeder (Discord)
 
 
 Modules & serialization

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


[clang] [analyzer] EvalBinOpLL should return Unknown less often (PR #114222)

2024-10-31 Thread Balazs Benics via cfe-commits

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


[clang] e67e03a - [analyzer] EvalBinOpLL should return Unknown less often (#114222)

2024-10-31 Thread via cfe-commits

Author: Balazs Benics
Date: 2024-10-31T11:01:47+01:00
New Revision: e67e03a22c27b26125247efeae1b2d36edeb3617

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

LOG: [analyzer] EvalBinOpLL should return Unknown less often (#114222)

SValBuilder::getKnownValue, getMinValue, getMaxValue use
SValBuilder::simplifySVal.

simplifySVal does repeated simplification until a fixed-point is
reached. A single step is done by SimpleSValBuilder::simplifySValOnce,
using a Simplifier visitor. That will basically decompose SymSymExprs,
and apply constant folding using the constraints we have in the State.
Once it decomposes a SymSymExpr, it simplifies both sides and then uses
the SValBuilder::evalBinOp to reconstruct the same - but now simpler -
SymSymExpr, while applying some caching to remain performant.

This decomposition, and then the subsequent re-composition poses new
challenges to the SValBuilder::evalBinOp, which is built to handle
expressions coming from real C/C++ code, thus applying some implicit
assumptions.

One previous assumption was that nobody would form an expression like
"((int*)0) - q" (where q is an int pointer), because it doesn't really
makes sense to write code like that.

However, during simplification, we may end up with a call to evalBinOp
similar to this.

To me, simplifying a SymbolRef should never result in Unknown or Undef,
unless it was Unknown or Undef initially or, during simplification we
realized that it's a division by zero once we did the constant folding,
etc.

In the following case the simplified SVal should not become UnknownVal:
```c++
void top(char *p, char *q) {
  int diff = p - q; // diff: reg - reg
  if (!p) // p: NULL
simplify(diff); // diff after simplification should be: 0(loc) - reg
}
```

Returning Unknown from the simplifySVal can weaken analysis precision in
other places too, such as in SValBuilder::getKnownValue, getMinValue, or
getMaxValue because we call simplifySVal before doing anything else.

For nonloc::SymbolVals, this loss of precision is critical, because for
those the SymbolRef carries an accurate type of the encoded computation,
thus we should at least have a conservative upper or lower bound that we
could return from getMinValue or getMaxValue - yet we would just return
nullptr.

```c++
const llvm::APSInt *SimpleSValBuilder::getKnownValue(ProgramStateRef state,
  SVal V) {
  return getConstValue(state, simplifySVal(state, V));
}

const llvm::APSInt *SimpleSValBuilder::getMinValue(ProgramStateRef state,
SVal V) {
  V = simplifySVal(state, V);

  if (const llvm::APSInt *Res = getConcreteValue(V))
return Res;

  if (SymbolRef Sym = V.getAsSymbol())
return state->getConstraintManager().getSymMinVal(state, Sym);

  return nullptr;
}
```

For now, I don't plan to make the simplification bullet-proof, I'm just
explaining why I made this change and what you need to look out for in
the future if you see a similar issue.

CPP-5750

Added: 
clang/unittests/StaticAnalyzer/SValSimplifyerTest.cpp

Modified: 
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
clang/unittests/StaticAnalyzer/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 45e48d435aca6a..229169f848e228 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -860,11 +860,12 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
 // If one of the operands is a symbol and the other is a constant,
 // build an expression for use by the constraint manager.
 if (SymbolRef rSym = rhs.getAsLocSymbol()) {
-  // We can only build expressions with symbols on the left,
-  // so we need a reversible operator.
-  if (!BinaryOperator::isComparisonOp(op) || op == BO_Cmp)
+  if (op == BO_Cmp)
 return UnknownVal();
 
+  if (!BinaryOperator::isComparisonOp(op))
+return makeNonLoc(L.getValue(), op, rSym, resultTy);
+
   op = BinaryOperator::reverseComparisonOp(op);
   return makeNonLoc(rSym, op, L.getValue(), resultTy);
 }

diff  --git a/clang/unittests/StaticAnalyzer/CMakeLists.txt 
b/clang/unittests/StaticAnalyzer/CMakeLists.txt
index 5ef72cfaea4011..f5da86e5456030 100644
--- a/clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ b/clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_unittest(StaticAnalysisTests
   RegisterCustomCheckersTest.cpp
   StoreTest.cpp
   SymbolReaperTest.cpp
+  SValSimplifyerTest.cpp
   SValTest.cpp
   TestReturnValueUnderConstruction.cpp
   Z3CrosscheckOracleTest.cpp

diff  --git a/clang/unit

[clang] [clang] Fix an em/email typo in Maintainers.rst (PR #114385)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Pretty sure this was a mistake, everyone else uses "email".

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


1 Files Affected:

- (modified) clang/Maintainers.rst (+1-1) 


``diff
diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index 35c218d8e0e8fa..896b463d882d08 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -72,7 +72,7 @@ Sema
 Experimental new constant interpreter
 ~
 | Timm Bäder
-| tbaeder\@redhat.com (em), tbaeder (Phabricator), tbaederr (GitHub), tbaeder 
(Discourse), tbaeder (Discord)
+| tbaeder\@redhat.com (email), tbaeder (Phabricator), tbaederr (GitHub), 
tbaeder (Discourse), tbaeder (Discord)
 
 
 Modules & serialization

``




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


[libclc] [libclc] Move min/max/clamp into the CLC builtins library (PR #114386)

2024-10-31 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

CC @rjodinchr, I hope this method of dealing with clspv works for you.

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


[libclc] [libclc] Move min/max/clamp into the CLC builtins library (PR #114386)

2024-10-31 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/114386

>From 045a64caab8d99c29e6b0abbdcdc19f84a55b820 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 26 Sep 2024 08:57:15 +0100
Subject: [PATCH] [libclc] Move min/max/clamp into the CLC builtins library

These functions are "shared" between integer and floating-point types,
hence the directory name. They are used in several CLC internal
functions such as __clc_ldexp.

Note that clspv and spirv targets don't want to define these functions,
so pre-processor macros replace calls to __clc_min with regular min, for
example. This means they can use as much of the generic CLC source files
as possible, but where CLC functions would usually call out to an
external __clc_min symbol, they call out to an external min symbol. Then
they opt out of defining __clc_min itself in their CLC builtins
library.

Preprocessor definitions for these targets have also been
changed somewhat: what used to be CLC_SPIRV (the 32-bit target) is now
CLC_SPIRV32, and CLC_SPIRV now represents either CLC_SPIRV32 or
CLC_SPIRV64. Same goes for CLC_CLSPV.

There are no differences (measured with llvm-diff) in any of the final
builtins libraries for nvptx, amdgpu, or clspv. Neither are there
differences in the SPIR-V targets' LLVM IR before it's actually lowered
to SPIR-V.
---
 libclc/CMakeLists.txt | 15 ---
 libclc/clc/include/clc/clcfunc.h  |  4 ++--
 .../include/clc/integer/gentype.inc   |  4 ++--
 .../{generic => clc}/include/clc/math/gentype.inc |  0
 libclc/clc/include/clc/shared/clc_clamp.h | 12 
 libclc/clc/include/clc/shared/clc_clamp.inc   |  9 +
 libclc/clc/include/clc/shared/clc_max.h   | 12 
 libclc/clc/include/clc/shared/clc_max.inc |  7 +++
 libclc/clc/include/clc/shared/clc_min.h   | 12 
 libclc/clc/include/clc/shared/clc_min.inc |  7 +++
 libclc/clc/lib/generic/SOURCES|  3 +++
 libclc/clc/lib/generic/shared/clc_clamp.cl|  7 +++
 libclc/clc/lib/generic/shared/clc_clamp.inc   | 14 ++
 libclc/clc/lib/generic/shared/clc_max.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_max.inc | 11 +++
 libclc/clc/lib/generic/shared/clc_min.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_min.inc | 11 +++
 libclc/generic/lib/common/smoothstep.cl   |  2 +-
 libclc/generic/lib/common/step.cl |  2 +-
 libclc/generic/lib/math/clc_hypot.cl  |  3 ++-
 libclc/generic/lib/math/clc_ldexp.cl  |  5 +++--
 libclc/generic/lib/math/math.h|  2 +-
 libclc/generic/lib/shared/clamp.cl|  1 +
 libclc/generic/lib/shared/clamp.inc   |  4 ++--
 libclc/generic/lib/shared/max.cl  |  1 +
 libclc/generic/lib/shared/max.inc |  7 ---
 libclc/generic/lib/shared/min.cl  |  1 +
 libclc/generic/lib/shared/min.inc |  7 ---
 28 files changed, 156 insertions(+), 21 deletions(-)
 rename libclc/{generic => clc}/include/clc/integer/gentype.inc (99%)
 rename libclc/{generic => clc}/include/clc/math/gentype.inc (100%)
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.h
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_max.h
 create mode 100644 libclc/clc/include/clc/shared/clc_max.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_min.h
 create mode 100644 libclc/clc/include/clc/shared/clc_min.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_min.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_min.inc

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 16d74e53295cc1..2c2c7f16e29442 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -321,21 +321,30 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 message( STATUS "  device: ${d} ( ${${d}_aliases} )" )
 
 if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
-  set( build_flags -O0 -finline-hint-functions )
+  set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
   set( opt_flags )
   set( spvflags --spirv-max-version=1.1 )
+  set( MACRO_ARCH SPIRV32 )
+  if( ARCH STREQUAL spirv64 )
+set( MACRO_ARCH SPIRV64 )
+  endif()
 elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
-  set( build_flags "-Wno-unknown-assumption")
+  set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
   set( opt_flags -O3 )
+  set( MACRO_ARCH CLSPV32 )
+  if( ARCH STREQUAL clspv64 )
+set( MACR

[libclc] [libclc] Move min/max/clamp into the CLC builtins library (PR #114386)

2024-10-31 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff b2bdd8bd39e90bfe3c66f6d5600468570a77ede6 
bac2d7c143b7a40fe6cf50c8c57cf00897874fa8 --extensions inc,h -- 
libclc/clc/include/clc/shared/clc_clamp.h 
libclc/clc/include/clc/shared/clc_clamp.inc 
libclc/clc/include/clc/shared/clc_max.h 
libclc/clc/include/clc/shared/clc_max.inc 
libclc/clc/include/clc/shared/clc_min.h 
libclc/clc/include/clc/shared/clc_min.inc 
libclc/clc/lib/generic/shared/clc_clamp.inc 
libclc/clc/lib/generic/shared/clc_max.inc 
libclc/clc/lib/generic/shared/clc_min.inc libclc/clc/include/clc/clcfunc.h 
libclc/generic/lib/math/math.h libclc/generic/lib/shared/clamp.inc 
libclc/generic/lib/shared/max.inc libclc/generic/lib/shared/min.inc 
libclc/clc/include/clc/integer/gentype.inc 
libclc/clc/include/clc/math/gentype.inc
``





View the diff from clang-format here.


``diff
diff --git a/libclc/clc/include/clc/integer/gentype.inc 
b/libclc/clc/include/clc/integer/gentype.inc
index cefed9c5e5..2c8dd143db 100644
--- a/libclc/clc/include/clc/integer/gentype.inc
+++ b/libclc/clc/include/clc/integer/gentype.inc
@@ -1,5 +1,5 @@
-//These 2 defines only change when switching between data sizes or base types 
to
-//keep this file manageable.
+// These 2 defines only change when switching between data sizes or base types
+// to keep this file manageable.
 #define __CLC_GENSIZE 8
 #define __CLC_SCALAR_GENTYPE char
 

``




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


[libclc] [libclc] Move min/max/clamp into the CLC builtins library (PR #114386)

2024-10-31 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/114386

These functions are "shared" between integer and floating-point types, hence 
the directory name. They are used in several CLC internal functions such as 
__clc_ldexp.

Note that clspv and spirv targets don't want to define these functions, so 
pre-processor macros replace calls to __clc_min with regular min, for example. 
This means they can use as much of the generic CLC source files as possible, 
but where CLC functions would usually call out to an external __clc_min symbol, 
they call out to an external min symbol. Then they opt out of defining 
__clc_min itself in their CLC builtins library.

Preprocessor definitions for these targets have also been changed somewhat: 
what used to be CLC_SPIRV (the 32-bit target) is now CLC_SPIRV32, and CLC_SPIRV 
now represents either CLC_SPIRV32 or CLC_SPIRV64. Same goes for CLC_CLSPV.

There are no differences (measured with llvm-diff) in any of the final builtins 
libraries for nvptx, amdgpu, or clspv. Neither are there differences in the 
SPIR-V targets' LLVM IR before it's actually lowered to SPIR-V.

>From bac2d7c143b7a40fe6cf50c8c57cf00897874fa8 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 26 Sep 2024 08:57:15 +0100
Subject: [PATCH] [libclc] Move min/max/clamp into the CLC builtins library

These functions are "shared" between integer and floating-point types,
hence the directory name. They are used in several CLC internal
functions such as __clc_ldexp.

Note that clspv and spirv targets don't want to define these functions,
so pre-processor macros replace calls to __clc_min with regular min, for
example. This means they can use as much of the generic CLC source files
as possible, but where CLC functions would usually call out to an
external __clc_min symbol, they call out to an external min symbol. Then
they opt out of defining __clc_min itself in their CLC builtins
library.

Preprocessor definitions for these targets have also been
changed somewhat: what used to be CLC_SPIRV (the 32-bit target) is now
CLC_SPIRV32, and CLC_SPIRV now represents either CLC_SPIRV32 or
CLC_SPIRV64. Same goes for CLC_CLSPV.

There are no differences (measured with llvm-diff) in any of the final
builtins libraries for nvptx, amdgpu, or clspv. Neither are there
differences in the SPIR-V targets' LLVM IR before it's actually lowered
to SPIR-V.
---
 libclc/CMakeLists.txt | 15 ---
 libclc/clc/include/clc/clcfunc.h  |  4 ++--
 .../include/clc/integer/gentype.inc   |  0
 .../{generic => clc}/include/clc/math/gentype.inc |  0
 libclc/clc/include/clc/shared/clc_clamp.h | 12 
 libclc/clc/include/clc/shared/clc_clamp.inc   |  9 +
 libclc/clc/include/clc/shared/clc_max.h   | 12 
 libclc/clc/include/clc/shared/clc_max.inc |  7 +++
 libclc/clc/include/clc/shared/clc_min.h   | 12 
 libclc/clc/include/clc/shared/clc_min.inc |  7 +++
 libclc/clc/lib/generic/SOURCES|  3 +++
 libclc/clc/lib/generic/shared/clc_clamp.cl|  7 +++
 libclc/clc/lib/generic/shared/clc_clamp.inc   | 14 ++
 libclc/clc/lib/generic/shared/clc_max.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_max.inc | 11 +++
 libclc/clc/lib/generic/shared/clc_min.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_min.inc | 11 +++
 libclc/generic/lib/common/smoothstep.cl   |  2 +-
 libclc/generic/lib/common/step.cl |  2 +-
 libclc/generic/lib/math/clc_hypot.cl  |  3 ++-
 libclc/generic/lib/math/clc_ldexp.cl  |  5 +++--
 libclc/generic/lib/math/math.h|  2 +-
 libclc/generic/lib/shared/clamp.cl|  1 +
 libclc/generic/lib/shared/clamp.inc   |  4 ++--
 libclc/generic/lib/shared/max.cl  |  1 +
 libclc/generic/lib/shared/max.inc |  7 ---
 libclc/generic/lib/shared/min.cl  |  1 +
 libclc/generic/lib/shared/min.inc |  7 ---
 28 files changed, 154 insertions(+), 19 deletions(-)
 rename libclc/{generic => clc}/include/clc/integer/gentype.inc (100%)
 rename libclc/{generic => clc}/include/clc/math/gentype.inc (100%)
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.h
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_max.h
 create mode 100644 libclc/clc/include/clc/shared/clc_max.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_min.h
 create mode 100644 libclc/clc/include/clc/shared/clc_min.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.inc
 cre

[libclc] [libclc] Move min/max/clamp into the CLC builtins library (PR #114386)

2024-10-31 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/114386

>From c0e8cf9ec8a3ce75b62afdcbb6383af16c2f3539 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 26 Sep 2024 08:57:15 +0100
Subject: [PATCH] [libclc] Move min/max/clamp into the CLC builtins library

These functions are "shared" between integer and floating-point types,
hence the directory name. They are used in several CLC internal
functions such as __clc_ldexp.

Note that clspv and spirv targets don't want to define these functions,
so pre-processor macros replace calls to __clc_min with regular min, for
example. This means they can use as much of the generic CLC source files
as possible, but where CLC functions would usually call out to an
external __clc_min symbol, they call out to an external min symbol. Then
they opt out of defining __clc_min itself in their CLC builtins
library.

Preprocessor definitions for these targets have also been
changed somewhat: what used to be CLC_SPIRV (the 32-bit target) is now
CLC_SPIRV32, and CLC_SPIRV now represents either CLC_SPIRV32 or
CLC_SPIRV64. Same goes for CLC_CLSPV.

There are no differences (measured with llvm-diff) in any of the final
builtins libraries for nvptx, amdgpu, or clspv. Neither are there
differences in the SPIR-V targets' LLVM IR before it's actually lowered
to SPIR-V.
---
 libclc/CMakeLists.txt | 15 ---
 libclc/clc/include/clc/clcfunc.h  |  4 ++--
 .../include/clc/integer/gentype.inc   |  4 ++--
 .../{generic => clc}/include/clc/math/gentype.inc |  0
 libclc/clc/include/clc/shared/clc_clamp.h | 12 
 libclc/clc/include/clc/shared/clc_clamp.inc   |  9 +
 libclc/clc/include/clc/shared/clc_max.h   | 12 
 libclc/clc/include/clc/shared/clc_max.inc |  7 +++
 libclc/clc/include/clc/shared/clc_min.h   | 12 
 libclc/clc/include/clc/shared/clc_min.inc |  7 +++
 libclc/clc/lib/generic/SOURCES|  3 +++
 libclc/clc/lib/generic/shared/clc_clamp.cl|  7 +++
 libclc/clc/lib/generic/shared/clc_clamp.inc   | 14 ++
 libclc/clc/lib/generic/shared/clc_max.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_max.inc | 11 +++
 libclc/clc/lib/generic/shared/clc_min.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_min.inc | 11 +++
 libclc/generic/lib/common/smoothstep.cl   |  2 +-
 libclc/generic/lib/common/step.cl |  2 +-
 libclc/generic/lib/math/clc_hypot.cl  |  4 +++-
 libclc/generic/lib/math/clc_ldexp.cl  |  6 +++---
 libclc/generic/lib/math/math.h|  2 +-
 libclc/generic/lib/shared/clamp.cl|  1 +
 libclc/generic/lib/shared/clamp.inc   |  4 ++--
 libclc/generic/lib/shared/max.cl  |  1 +
 libclc/generic/lib/shared/max.inc |  7 ---
 libclc/generic/lib/shared/min.cl  |  1 +
 libclc/generic/lib/shared/min.inc |  7 ---
 28 files changed, 157 insertions(+), 22 deletions(-)
 rename libclc/{generic => clc}/include/clc/integer/gentype.inc (99%)
 rename libclc/{generic => clc}/include/clc/math/gentype.inc (100%)
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.h
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_max.h
 create mode 100644 libclc/clc/include/clc/shared/clc_max.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_min.h
 create mode 100644 libclc/clc/include/clc/shared/clc_min.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_min.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_min.inc

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 16d74e53295cc1..2c2c7f16e29442 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -321,21 +321,30 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 message( STATUS "  device: ${d} ( ${${d}_aliases} )" )
 
 if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
-  set( build_flags -O0 -finline-hint-functions )
+  set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
   set( opt_flags )
   set( spvflags --spirv-max-version=1.1 )
+  set( MACRO_ARCH SPIRV32 )
+  if( ARCH STREQUAL spirv64 )
+set( MACRO_ARCH SPIRV64 )
+  endif()
 elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
-  set( build_flags "-Wno-unknown-assumption")
+  set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
   set( opt_flags -O3 )
+  set( MACRO_ARCH CLSPV32 )
+  if( ARCH STREQUAL clspv64 )
+set( MA

[libclc] fba9f05 - [libclc] Format clc_ldexp.cl and clc_hypot.cl. NFC

2024-10-31 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-10-31T10:18:29Z
New Revision: fba9f05ff7b36f9cbb5835d79f659290dadecaad

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

LOG: [libclc] Format clc_ldexp.cl and clc_hypot.cl. NFC

Added: 


Modified: 
libclc/generic/lib/math/clc_hypot.cl
libclc/generic/lib/math/clc_ldexp.cl

Removed: 




diff  --git a/libclc/generic/lib/math/clc_hypot.cl 
b/libclc/generic/lib/math/clc_hypot.cl
index 35532a9532062a..8261d97c2b493b 100644
--- a/libclc/generic/lib/math/clc_hypot.cl
+++ b/libclc/generic/lib/math/clc_hypot.cl
@@ -23,76 +23,78 @@
 #include 
 #include 
 
+#include "../clcmacro.h"
 #include "config.h"
 #include "math.h"
-#include "../clcmacro.h"
 
-// Returns sqrt(x*x + y*y) with no overflow or underflow unless the result 
warrants it
-_CLC_DEF _CLC_OVERLOAD float __clc_hypot(float x, float y)
-{
-uint ux = as_uint(x);
-uint aux = ux & EXSIGNBIT_SP32;
-uint uy = as_uint(y);
-uint auy = uy & EXSIGNBIT_SP32;
-float retval;
-int c = aux > auy;
-ux = c ? aux : auy;
-uy = c ? auy : aux;
-
-int xexp = clamp((int)(ux >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32, -126, 126);
-float fx_exp = as_float((xexp + EXPBIAS_SP32) << EXPSHIFTBITS_SP32);
-float fi_exp = as_float((-xexp + EXPBIAS_SP32) << EXPSHIFTBITS_SP32);
-float fx = as_float(ux) * fi_exp;
-float fy = as_float(uy) * fi_exp;
-retval = sqrt(mad(fx, fx, fy*fy)) * fx_exp;
-
-retval = ux > PINFBITPATT_SP32 | uy == 0 ? as_float(ux) : retval;
-retval = ux == PINFBITPATT_SP32 | uy == PINFBITPATT_SP32 ? 
as_float(PINFBITPATT_SP32) : retval;
-return retval;
+// Returns sqrt(x*x + y*y) with no overflow or underflow unless the result
+// warrants it
+_CLC_DEF _CLC_OVERLOAD float __clc_hypot(float x, float y) {
+  uint ux = as_uint(x);
+  uint aux = ux & EXSIGNBIT_SP32;
+  uint uy = as_uint(y);
+  uint auy = uy & EXSIGNBIT_SP32;
+  float retval;
+  int c = aux > auy;
+  ux = c ? aux : auy;
+  uy = c ? auy : aux;
+
+  int xexp = clamp((int)(ux >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32, -126, 126);
+  float fx_exp = as_float((xexp + EXPBIAS_SP32) << EXPSHIFTBITS_SP32);
+  float fi_exp = as_float((-xexp + EXPBIAS_SP32) << EXPSHIFTBITS_SP32);
+  float fx = as_float(ux) * fi_exp;
+  float fy = as_float(uy) * fi_exp;
+  retval = sqrt(mad(fx, fx, fy * fy)) * fx_exp;
+
+  retval = ux > PINFBITPATT_SP32 | uy == 0 ? as_float(ux) : retval;
+  retval = ux == PINFBITPATT_SP32 | uy == PINFBITPATT_SP32
+   ? as_float(PINFBITPATT_SP32)
+   : retval;
+  return retval;
 }
 _CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_hypot, float, float)
 
 #ifdef cl_khr_fp64
-_CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y)
-{
-ulong ux = as_ulong(x) & ~SIGNBIT_DP64;
-int xexp = ux >> EXPSHIFTBITS_DP64;
-x = as_double(ux);
+_CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y) {
+  ulong ux = as_ulong(x) & ~SIGNBIT_DP64;
+  int xexp = ux >> EXPSHIFTBITS_DP64;
+  x = as_double(ux);
 
-ulong uy = as_ulong(y) & ~SIGNBIT_DP64;
-int yexp = uy >> EXPSHIFTBITS_DP64;
-y = as_double(uy);
+  ulong uy = as_ulong(y) & ~SIGNBIT_DP64;
+  int yexp = uy >> EXPSHIFTBITS_DP64;
+  y = as_double(uy);
 
-int c = xexp > EXPBIAS_DP64 + 500 | yexp > EXPBIAS_DP64 + 500;
-double preadjust = c ? 0x1.0p-600 : 1.0;
-double postadjust = c ? 0x1.0p+600 : 1.0;
+  int c = xexp > EXPBIAS_DP64 + 500 | yexp > EXPBIAS_DP64 + 500;
+  double preadjust = c ? 0x1.0p-600 : 1.0;
+  double postadjust = c ? 0x1.0p+600 : 1.0;
 
-c = xexp < EXPBIAS_DP64 - 500 | yexp < EXPBIAS_DP64 - 500;
-preadjust = c ? 0x1.0p+600 : preadjust;
-postadjust = c ? 0x1.0p-600 : postadjust;
+  c = xexp < EXPBIAS_DP64 - 500 | yexp < EXPBIAS_DP64 - 500;
+  preadjust = c ? 0x1.0p+600 : preadjust;
+  postadjust = c ? 0x1.0p-600 : postadjust;
 
-double ax = x * preadjust;
-double ay = y * preadjust;
+  double ax = x * preadjust;
+  double ay = y * preadjust;
 
-// The post adjust may overflow, but this can't be avoided in any case
-double r = sqrt(fma(ax, ax, ay*ay)) * postadjust;
+  // The post adjust may overflow, but this can't be avoided in any case
+  double r = sqrt(fma(ax, ax, ay * ay)) * postadjust;
 
-// If the 
diff erence in exponents between x and y is large
-double s = x + y;
-c = abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
-r = c ? s : r;
+  // If the 
diff erence in exponents between x and y is large
+  double s = x + y;
+  c = abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
+  r = c ? s : r;
 
-// Check for NaN
-//c = x != x | y != y;
-c = isnan(x) | isnan(y);
-r = c ? as_double(QNANBITPATT_DP64) : r;
+  // Check for NaN
+  // c = x != x | y != y;
+  c = isnan(x) | isnan(y);
+  r = c ? as_double(QNANBITPATT

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

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

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

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

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 145786bcc59b45..38fe79a7375f45 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -451,6 +451,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now diagnoses missing format attributes for non-template functions and 
class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 72eada50a56cc9..f941f3883b78d7 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -530,7 +530,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 34ff49d7238a7f..08274a067f05ce 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1055,6 +1055,10 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
+def note_format_function : Note<"%0 format function">;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d98e1cbb9c81..d4af760a11f274 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4576,6 +4576,8 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f8e5f3c6d309d6..3aa85829dd8023 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16049,6 +16049,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 601c6f2eef1d9

[clang] 287781c - [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (#113845)

2024-10-31 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-10-31T00:14:24-07:00
New Revision: 287781c7c9dbd7674cf7cbab8a8fe8a49a4b9317

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

LOG: [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and 
[[clang::noescape]]. (#113845)

This PR makes webkit.UncountedLambdaCapturesChecker ignore trivial
functions as well as the one being passed to an argument with
[[clang::noescape]] attribute. This dramatically reduces the false
positive rate for this checker.

To do this, this PR replaces VisitLambdaExpr in favor of checking
lambdas via VisitDeclRefExpr and VisitCallExpr. The idea is that if a
lambda is defined but never called or stored somewhere, then capturing
whatever variable in such a lambda is harmless.

VisitCallExpr explicitly looks for direct invocation of lambdas and
registers its DeclRefExpr to be ignored in VisitDeclRefExpr. If a lambda
is being passed to a function, it checks whether its argument is
annotated with [[clang::noescape]]. If it's not annotated such, it
checks captures for their safety.

Because WTF::switchOn could not be annotated with [[clang::noescape]] as
function type parameters are variadic template function so we hard-code
this function into the checker.

Finally, this PR also converts the accompanying test to use -verify and
adds a bunch of tests.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/test/Analysis/Checkers/WebKit/mock-types.h
clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 4b41ca96e1df1d..814015c311d61e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -63,6 +63,10 @@ std::optional isUncounted(const clang::CXXRecordDecl* 
Class);
 /// class, false if not, std::nullopt if inconclusive.
 std::optional isUncountedPtr(const clang::QualType T);
 
+/// \returns true if \p T is either a raw pointer or reference to an uncounted
+/// or unchecked class, false if not, std::nullopt if inconclusive.
+std::optional isUnsafePtr(const QualType T);
+
 /// \returns true if \p T is a RefPtr, Ref, CheckedPtr, CheckedRef, or its
 /// variant, false if not.
 bool isSafePtrType(const clang::QualType T);

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index 998bd4ccee07db..d3484d74a2e3eb 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 
+#include "ASTUtils.h"
 #include "DiagOutputUtils.h"
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
@@ -26,6 +27,7 @@ class UncountedLambdaCapturesChecker
   BugType Bug{this, "Lambda capture of uncounted variable",
   "WebKit coding guidelines"};
   mutable BugReporter *BR = nullptr;
+  TrivialFunctionAnalysis TFA;
 
 public:
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
@@ -37,6 +39,8 @@ class UncountedLambdaCapturesChecker
 // want to visit those, so we make our own RecursiveASTVisitor.
 struct LocalVisitor : public RecursiveASTVisitor {
   const UncountedLambdaCapturesChecker *Checker;
+  llvm::DenseSet DeclRefExprsToIgnore;
+
   explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker)
   : Checker(Checker) {
 assert(Checker);
@@ -45,32 +49,100 @@ class UncountedLambdaCapturesChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
-  bool VisitLambdaExpr(LambdaExpr *L) {
+  bool VisitDeclRefExpr(DeclRefExpr *DRE) {
+if (DeclRefExprsToIgnore.contains(DRE))
+  return true;
+auto *VD = dyn_cast_or_null(DRE->getDecl());
+if (!VD)
+  return true;
+auto *Init = VD->getInit()->IgnoreParenCasts();
+auto *L = dyn_cast_or_null(Init);
+if (!L)
+  return true;
 Checker->visitLambdaExpr(L);
 return true;
   }
+
+  // WTF::switchOn(T, F... f) is a variadic template function and couldn't
+  // be annotated with NOESCAPE. We hard code it here to workaround that.
+  bool shouldTreatAllArgAsNoEscape(FunctionDecl *Decl) {
+auto *NsDecl = Decl->getParent();
+ 

[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #113845)

2024-10-31 Thread Ryosuke Niwa via cfe-commits

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


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Vitaly Buka via cfe-commits


@@ -831,6 +831,28 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
   return CanonTTP;
 }
 
+/// Check if a type can have its sanitizer instrumentation elided.
+/// Determine this by its presence in a SCL alongside its specified categories.
+/// For example:
+/// ignorelist.txt>
+/// [{unsigned-integer-overflow,signed-integer-overflow}]
+/// type:*=no_sanitize
+/// type:size_t=sanitize
+/// containsType(Mask, Ty.getAsString(), "sanitize");
+
+  bool noSanitizeType =

vitalybuka wrote:

> Out of curiosity: What is a printing policy?

Not sure, but other users of containsType use policy.

> We do not want the canonical type, we should support typedefs.

Can you add a test to control that? with current patch canonical works.

Actually I was inspired by the patch to add -fsanitize=enum type ignore list, 
and 
without canonical `void f(enum MyEnum e)` is matched as `enum MyEnum`.


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


[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)

2024-10-31 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/112424

>From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 15 Oct 2024 22:43:24 +0300
Subject: [PATCH 1/3] [Clang] prevent setting default lexical access specifier
 for missing primary declarations

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/Sema/SemaAccess.cpp | 3 ++-
 clang/test/SemaCXX/enum.cpp   | 8 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..64ffdcde045a3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,8 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when the default lexical access specifier was set 
for missing
+  primary declarations. (#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index df6edb21a50dee..8b4a5b70669d84 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-MemberDecl->setAccess(LexicalAS);
+if (LexicalAS != AS_none)
+  MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp
index 9c398cc8da886c..44042d8bf5cfc8 100644
--- a/clang/test/SemaCXX/enum.cpp
+++ b/clang/test/SemaCXX/enum.cpp
@@ -143,3 +143,11 @@ struct PR28903 {
 })
   };
 };
+
+namespace GH112208 {
+class C {
+  enum E { e = 0 };
+  void f(int, enum E;); // expected-error {{ISO C++ forbids forward references 
to 'enum' types}} \
+// expected-error {{unexpected ';' before ')'}}
+};
+}

>From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 18 Oct 2024 14:55:47 +0300
Subject: [PATCH 2/3] prevent assertion failure by handling invalid enum
 forward declarations

---
 clang/docs/ReleaseNotes.rst   | 3 +--
 clang/lib/Sema/SemaAccess.cpp | 3 +--
 clang/lib/Sema/SemaDecl.cpp   | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64ffdcde045a3a..3fd37663ca7bc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,8 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
-- Fixed an assertion failure when the default lexical access specifier was set 
for missing
-  primary declarations. (#GH112208)
+- Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 8b4a5b70669d84..df6edb21a50dee 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-if (LexicalAS != AS_none)
-  MemberDecl->setAccess(LexicalAS);
+MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..9eb3d06289e88f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
 << Name;
 Invalid = true;
   }
+  if (TUK == TagUseKind::Declaration && Name)
+Invalid = true;
 } else if (!PrevDecl) {
   Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
 }

>From 82e3dda6fd4b438e13ed133605f9a8f077f157a2 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 30 Oct 2024 08:25:30 +0200
Subject: [PATCH 3/3] remove redundant Name check

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

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a5f41d48e9f984..eeb16a0d4bb3d1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17945,7 +17945,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
 << Name;
 Invalid = true;
   }
-  if (TUK 

[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #113845)

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

llvm-ci wrote:

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

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


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 Tools :: 
clang-tidy/infrastructure/read_file_config.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: mkdir -p 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/
+ mkdir -p 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/
RUN: at line 3: cp 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang-tools-extra/test/clang-tidy/infrastructure/read_file_config.cpp
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
+ cp 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang-tools-extra/test/clang-tidy/infrastructure/read_file_config.cpp
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
RUN: at line 4: echo 'Checks: "-*,modernize-use-nullptr"' > 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/.clang-tidy
+ echo 'Checks: "-*,modernize-use-nullptr"'
RUN: at line 5: echo '[{"command": "cc -c -o test.o test.cpp", "directory": 
"/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config",
 "file": 
"/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp"}]'
 > 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/compile_commands.json
+ echo '[{"command": "cc -c -o test.o test.cpp", "directory": 
"/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config",
 "file": 
"/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp"}]'
RUN: at line 6: clang-tidy 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
 | not grep "warning: .*\[clang-analyzer-deadcode.DeadStores\]$"
+ not grep 'warning: .*\[clang-analyzer-deadcode.DeadStores\]$'
+ clang-tidy 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
RUN: at line 7: clang-tidy -checks="-*,clang-analyzer-*" 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
 | grep "warning: .*\[clang-analyzer-deadcode.DeadStores\]$"
+ grep 'warning: .*\[clang-analyzer-deadcode.DeadStores\]$'
+ clang-tidy '-checks=-*,clang-analyzer-*' 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
clang-tidy: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/include/llvm/Support/Casting.h:662:
 decltype(auto) llvm::dyn_cast(From*) [with To = clang::ParenExpr; From = 
clang::Expr]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent 
value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump:
0.  Program arguments: clang-tidy -checks=-*,clang-analyzer-* 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/tools/extra/test/clang-tidy/infrastructure/Output/read-file-config/test.cpp
1.   parser at end of file
 #0 0x5781c8be43b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang-tidy+0x4c043b0)
 #1 0x5781c8be17bf llvm::sys::RunSignalHandlers() 
(/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang-tidy+0x4c017bf)
 #2 0x5781c8be1915 SignalHandler(int) Signals.cpp:0:0
 #3 0x75c1bd92c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x75c1bd9809fc __pthread_kill_implementation ./nptl/pt

[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #113845)

2024-10-31 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/9836


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

```
Step 6 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: 
Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp' FAILED 

Exit Code: 134

Command Output (stderr):
--
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/20/include
 -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+ /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/20/include
 -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
clang: 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/llvm/include/llvm/Support/Casting.h:662:
 decltype(auto) llvm::dyn_cast(From*) [with To = clang::ParenExpr; From = 
clang::Expr]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent 
value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: 
/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/20/include
 -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
1.   parser at end of file
 #0 0x027214c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang+0x27214c8)
 #1 0x0271ea0c SignalHandler(int) Signals.cpp:0:0
 #2 0x7fadaf16b910 __restore_rt (/lib64/libpthread.so.0+0x16910)
 #3 0x7fadaea99d2b raise (/lib64/libc.so.6+0x4ad2b)
 #4 0x7fadaea9b3e5 abort (/lib64/libc.so.6+0x4c3e5)
 #5 0x7fadaea91c6a __assert_fail_base (/lib64/libc.so.6+0x42c6a)
 #6 0x7fadaea91cf2 (/lib64/libc.so.6+0x42cf2)
 #7 0x05163216 clang::IgnoreParensSingleStep(clang::Expr*) 
(/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang+0x5163216)
 #8 0x05be4b0a clang::Expr::IgnoreParenCasts() 
(/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang+0x5be4b0a)
 #9 0x048668a5 clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseDeclRefExpr(clang::DeclRefExpr*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) 
UncountedLambdaCapturesChecker.cpp:0:0
#10 0x04859f02 clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::dataTraverseNode(clang::Stmt*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) 
UncountedLambdaCapturesChecker.cpp:0:0
#11 0x04861ffd clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseStmt(clang::Stmt*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) (.constprop.6931) 
UncountedLambdaCapturesChecker.cpp:0:0
#12 0x04872c83 clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) 
UncountedLambdaCapturesChecker.cpp:0:0
#13 0x04859627 clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseDecl(clang::Decl*) (.pa

[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #114374)

2024-10-31 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/114374

This PR makes webkit.UncountedLambdaCapturesChecker ignore trivial functions as 
well as the one being passed to an argument with [[clang::noescape]] attribute. 
This dramatically reduces the false positive rate for this checker.

To do this, this PR replaces VisitLambdaExpr in favor of checking lambdas via 
VisitDeclRefExpr and VisitCallExpr. The idea is that if a lambda is defined but 
never called or stored somewhere, then capturing whatever variable in such a 
lambda is harmless.

VisitCallExpr explicitly looks for direct invocation of lambdas and registers 
its DeclRefExpr to be ignored in VisitDeclRefExpr. If a lambda is being passed 
to a function, it checks whether its argument is annotated with 
[[clang::noescape]]. If it's not annotated such, it checks captures for their 
safety.

Because WTF::switchOn could not be annotated with [[clang::noescape]] as 
function type parameters are variadic template function so we hard-code this 
function into the checker.

In order to check whether "this" pointer is ref-counted type or not, we 
override TraverseDecl and record the most recent method's declaration.

In addition, this PR fixes a bug in isUnsafePtr that it was erroneously 
checking whether std::nullopt was returned by isUncounted and isUnchecked as 
opposed to the actual boolean value.

Finally, this PR also converts the accompanying test to use -verify and adds a 
bunch of tests.

>From 474490de53c029ab59008bed9fc33f61db4cb1d7 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Thu, 31 Oct 2024 01:12:35 -0700
Subject: [PATCH] [webkit.UncountedLambdaCapturesChecker] Ignore trivial
 functions and [[clang::noescape]].

This PR makes webkit.UncountedLambdaCapturesChecker ignore trivial
functions as well as the one being passed to an argument with
[[clang::noescape]] attribute. This dramatically reduces the false
positive rate for this checker.

To do this, this PR replaces VisitLambdaExpr in favor of checking
lambdas via VisitDeclRefExpr and VisitCallExpr. The idea is that if a
lambda is defined but never called or stored somewhere, then capturing
whatever variable in such a lambda is harmless.

VisitCallExpr explicitly looks for direct invocation of lambdas and
registers its DeclRefExpr to be ignored in VisitDeclRefExpr. If a lambda
is being passed to a function, it checks whether its argument is
annotated with [[clang::noescape]]. If it's not annotated such, it
checks captures for their safety.

Because WTF::switchOn could not be annotated with [[clang::noescape]] as
function type parameters are variadic template function so we hard-code
this function into the checker.

In order to check whether "this" pointer is ref-counted type or not,
we override TraverseDecl and record the most recent method's declaration.

In addition, this PR fixes a bug in isUnsafePtr that it was erroneously
checking whether std::nullopt was returned by isUncounted and isUnchecked
as opposed to the actual boolean value.

Finally, this PR also converts the accompanying test to use -verify and
adds a bunch of tests.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |   8 +-
 .../Checkers/WebKit/PtrTypesSemantics.h   |   4 +
 .../WebKit/UncountedLambdaCapturesChecker.cpp | 130 -
 .../Analysis/Checkers/WebKit/mock-types.h |   2 +
 .../WebKit/uncounted-lambda-captures.cpp  | 177 +++---
 5 files changed, 286 insertions(+), 35 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 2293dcf1d4bd64..2ef93b2855e237 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -203,7 +203,13 @@ std::optional isUncountedPtr(const QualType T) {
 std::optional isUnsafePtr(const QualType T) {
   if (T->isPointerType() || T->isReferenceType()) {
 if (auto *CXXRD = T->getPointeeCXXRecordDecl()) {
-  return isUncounted(CXXRD) || isUnchecked(CXXRD);
+  auto isUncountedPtr = isUncounted(CXXRD);
+  auto isUncheckedPtr = isUnchecked(CXXRD);
+  if (isUncountedPtr && isUncheckedPtr)
+return *isUncountedPtr || *isUncheckedPtr;
+  if (isUncountedPtr)
+return *isUncountedPtr;
+  return isUncheckedPtr;
 }
   }
   return false;
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 4b41ca96e1df1d..814015c311d61e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -63,6 +63,10 @@ std::optional isUncounted(const clang::CXXRecordDecl* 
Class);
 /// class, false if not, std::nullopt if inconclusive.
 std::optional isUncountedPtr(const clang::QualType T);
 
+/// \returns true if \p T is either a raw pointer or reference to an u

[clang] dadfd4a - Revert "[webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]." (#114372)

2024-10-31 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-10-31T00:30:18-07:00
New Revision: dadfd4a288d9fd87314c1542a052e5942960c40b

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

LOG: Revert "[webkit.UncountedLambdaCapturesChecker] Ignore trivial functions 
and [[clang::noescape]]." (#114372)

Reverts llvm/llvm-project#113845. Introduced a test failure.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/test/Analysis/Checkers/WebKit/mock-types.h
clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 814015c311d61e..4b41ca96e1df1d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -63,10 +63,6 @@ std::optional isUncounted(const clang::CXXRecordDecl* 
Class);
 /// class, false if not, std::nullopt if inconclusive.
 std::optional isUncountedPtr(const clang::QualType T);
 
-/// \returns true if \p T is either a raw pointer or reference to an uncounted
-/// or unchecked class, false if not, std::nullopt if inconclusive.
-std::optional isUnsafePtr(const QualType T);
-
 /// \returns true if \p T is a RefPtr, Ref, CheckedPtr, CheckedRef, or its
 /// variant, false if not.
 bool isSafePtrType(const clang::QualType T);

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index d3484d74a2e3eb..998bd4ccee07db 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -6,7 +6,6 @@
 //
 
//===--===//
 
-#include "ASTUtils.h"
 #include "DiagOutputUtils.h"
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
@@ -27,7 +26,6 @@ class UncountedLambdaCapturesChecker
   BugType Bug{this, "Lambda capture of uncounted variable",
   "WebKit coding guidelines"};
   mutable BugReporter *BR = nullptr;
-  TrivialFunctionAnalysis TFA;
 
 public:
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
@@ -39,8 +37,6 @@ class UncountedLambdaCapturesChecker
 // want to visit those, so we make our own RecursiveASTVisitor.
 struct LocalVisitor : public RecursiveASTVisitor {
   const UncountedLambdaCapturesChecker *Checker;
-  llvm::DenseSet DeclRefExprsToIgnore;
-
   explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker)
   : Checker(Checker) {
 assert(Checker);
@@ -49,100 +45,32 @@ class UncountedLambdaCapturesChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
-  bool VisitDeclRefExpr(DeclRefExpr *DRE) {
-if (DeclRefExprsToIgnore.contains(DRE))
-  return true;
-auto *VD = dyn_cast_or_null(DRE->getDecl());
-if (!VD)
-  return true;
-auto *Init = VD->getInit()->IgnoreParenCasts();
-auto *L = dyn_cast_or_null(Init);
-if (!L)
-  return true;
+  bool VisitLambdaExpr(LambdaExpr *L) {
 Checker->visitLambdaExpr(L);
 return true;
   }
-
-  // WTF::switchOn(T, F... f) is a variadic template function and couldn't
-  // be annotated with NOESCAPE. We hard code it here to workaround that.
-  bool shouldTreatAllArgAsNoEscape(FunctionDecl *Decl) {
-auto *NsDecl = Decl->getParent();
-if (!NsDecl || !isa(NsDecl))
-  return false;
-return safeGetName(NsDecl) == "WTF" && safeGetName(Decl) == "switchOn";
-  }
-
-  bool VisitCallExpr(CallExpr *CE) {
-checkCalleeLambda(CE);
-if (auto *Callee = CE->getDirectCallee()) {
-  bool TreatAllArgsAsNoEscape = shouldTreatAllArgAsNoEscape(Callee);
-  unsigned ArgIndex = 0;
-  for (auto *Param : Callee->parameters()) {
-if (ArgIndex >= CE->getNumArgs())
-  break;
-auto *Arg = CE->getArg(ArgIndex)->IgnoreParenCasts();
-if (!Param->hasAttr() && !TreatAllArgsAsNoEscape) {
-  if (auto *L = dyn_cast_or_null(Arg))
-Checker->visitLambdaExpr(L);
-}
-++ArgIndex;
-  }
-}
-return true;
-  }
-
-  void checkCalleeLambda(CallExpr *CE) {
-auto *Callee = CE->getCallee();
-if (!Callee)
-  return;
-auto *DRE = dyn_c

[clang] Revert "[webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]." (PR #114372)

2024-10-31 Thread Ryosuke Niwa via cfe-commits

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


[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #113845)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-debian-cpp20` 
running on `clang-debian-cpp20` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


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 :: 
Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp' FAILED 

Exit Code: 134

Command Output (stderr):
--
RUN: at line 1: 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang -cc1 
-internal-isystem 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/lib/clang/20/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+ /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang -cc1 
-internal-isystem 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/lib/clang/20/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
clang: 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/include/llvm/Support/Casting.h:662:
 decltype(auto) llvm::dyn_cast(From *) [To = clang::ParenExpr, From = 
clang::Expr]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent 
value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang -cc1 
-internal-isystem 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/lib/clang/20/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
1.   parser at end of file
 #0 0x5cacb1ec9e78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang+0x3b8be78)
 #1 0x5cacb1ec78ed llvm::sys::RunSignalHandlers() 
(/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang+0x3b898ed)
 #2 0x5cacb1eca3f8 SignalHandler(int) Signals.cpp:0:0
 #3 0x7a7b94b95510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
 #4 0x7a7b94be30fc (/lib/x86_64-linux-gnu/libc.so.6+0x8a0fc)
 #5 0x7a7b94b95472 raise (/lib/x86_64-linux-gnu/libc.so.6+0x3c472)
 #6 0x7a7b94b7f4b2 abort (/lib/x86_64-linux-gnu/libc.so.6+0x264b2)
 #7 0x7a7b94b7f3d5 (/lib/x86_64-linux-gnu/libc.so.6+0x263d5)
 #8 0x7a7b94b8e3a2 (/lib/x86_64-linux-gnu/libc.so.6+0x353a2)
 #9 0x5cacb49d823e clang::IgnoreParensSingleStep(clang::Expr*) 
(/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang+0x669a23e)
#10 0x5cacb55192cb clang::Expr::IgnoreParenCasts() 
(/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/clang+0x71db2cb)
#11 0x5cacb4082a2e clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseDeclRefExpr(clang::DeclRefExpr*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) 
UncountedLambdaCapturesChecker.cpp:0:0
#12 0x5cacb407805c clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseStmt(clang::Stmt*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) 
UncountedLambdaCapturesChecker.cpp:0:0
#13 0x5cacb4097918 clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) 
UncountedLambdaCapturesChecker.cpp:0:0
#14 0x5cacb4072a92 clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseFunctionDecl(clang::FunctionDecl*) 
UncountedLambdaCapturesChecker.cpp:0:0
#15 0x5cacb40701bc clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::An

[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #113845)

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

llvm-ci wrote:

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

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86708 tests, 88 workers --
Testing: 
FAIL: Clang :: Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp (834 of 
86708)
 TEST 'Clang :: 
Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/20/include
 -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/20/include
 -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp:58:37:
 runtime error: member call on null pointer of type 'clang::Expr'
#0 0x62dce19c5002 in VisitDeclRefExpr 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp:58:37
#1 0x62dce19c5002 in WalkUpFromDeclRefExpr 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/include/clang/AST/StmtNodes.inc:474:1
#2 0x62dce19c5002 in clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseDeclRefExpr(clang::DeclRefExpr*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:2487:1
#3 0x62dce19b3a68 in clang::RecursiveASTVisitor<(anonymous 
namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
const::LocalVisitor>::TraverseStmt(clang::Stmt*, 
llvm::SmallVectorImpl, 
llvm::PointerIntPairInfo>>>*) 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/

[clang] [llvm] [LLVM][IR] Use splat syntax when printing Constant[Data]Vector. (PR #112548)

2024-10-31 Thread Paul Walker via cfe-commits


@@ -1690,6 +1690,23 @@ static void WriteConstantInternal(raw_ostream &Out, 
const Constant *CV,
   if (isa(CV) || isa(CV)) {
 auto *CVVTy = cast(CV->getType());
 Type *ETy = CVVTy->getElementType();
+
+// Use the same shorthand for splat vector (i.e. "splat(Ty val)") as is
+// permitted on IR input to reduce the output changes when enabling
+// UseConstant{Int,FP}ForFixedLengthSplat.
+// TODO: Remove this block when the UseConstant{Int,FP}ForFixedLengthSplat
+// options are removed.
+if (auto *SplatVal = CV->getSplatValue()) {
+  if (isa(SplatVal) || isa(SplatVal)) {
+Out << "splat (";
+WriterCtx.TypePrinter->print(ETy, Out);
+Out << " ";
+WriteAsOperandInternal(Out, SplatVal, WriterCtx);
+Out << ")";
+return;

paulwalker-arm wrote:

Done.

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


[clang] d3daa3c - [clang/AST] Make it possible to use SwiftAttr in type context (#108631)

2024-10-31 Thread via cfe-commits

Author: Pavel Yaskevich
Date: 2024-10-31T11:15:22Z
New Revision: d3daa3c4435a54f7876d0ced81787fea92e77d08

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

LOG: [clang/AST] Make it possible to use SwiftAttr in type context (#108631)

Swift ClangImporter now supports concurrency annotations on imported
declarations and their parameters/results, to make it possible to use
imported APIs in Swift safely there has to be a way to annotate
individual parameters and result types with relevant attributes that
indicate that e.g. a block is called on a particular actor or it accepts
a `Sendable` parameter.

To faciliate that `SwiftAttr` is switched from `InheritableAttr` which
is a declaration attribute to `DeclOrTypeAttr`. To support this
attribute in type context we need access to its "Attribute" argument
which requires `AttributedType` to be extended to include `Attr *` when
available instead of just `attr::Kind` otherwise it won't be possible to
determine what attribute should be imported.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Serialization/ASTRecordWriter.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaSwift.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/attr-swift_attr.m
clang/test/SemaObjC/validate-attr-swift_attr.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 145786bcc59b45..4e542ee91a8b36 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -338,6 +338,19 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --
 
+- The ``swift_attr`` can now be applied to types. To make it possible to use 
imported APIs
+  in Swift safely there has to be a way to annotate individual parameters and 
result types
+  with relevant attributes that indicate that e.g. a block is called on a 
particular actor
+  or it accepts a Sendable or global-actor (i.e. ``@MainActor``) isolated 
parameter.
+
+  For example:
+
+  .. code-block:: objc
+
+ @interface MyService
+   -(void) handle: (void (^ __attribute__((swift_attr("@Sendable"(id)) 
handler;
+ @end
+
 - Clang now disallows more than one ``__attribute__((ownership_returns(class, 
idx)))`` with
   
diff erent class names attached to one function.
 

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 07b4e36f3ef05e..4c1455a3e1bbf2 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1719,8 +1719,15 @@ class ASTContext : public RefCountedBase {
   QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
 
   QualType getAttributedType(attr::Kind attrKind, QualType modifiedType,
+ QualType equivalentType,
+ const Attr *attr = nullptr) const;
+
+  QualType getAttributedType(const Attr *attr, QualType modifiedType,
  QualType equivalentType) const;
 
+  QualType getAttributedType(NullabilityKind nullability, QualType 
modifiedType,
+ QualType equivalentType);
+
   QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr,
QualType Wrapped) const;
 

diff  --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index 3057669e3758b5..5f3a885832e2e4 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -76,6 +76,7 @@ def APValue : PropertyType { let PassByReference = 1; }
 def APValueKind : EnumPropertyType<"APValue::ValueKind">;
 def ArraySizeModifier : EnumPropertyType<"ArraySizeModifier">;
 def AttrKind : EnumPropertyType<"attr::Kind">;
+def Attr : PropertyType<"const Attr *">;
 def AutoTypeKeyword : EnumPropertyType;
 def Bool : PropertyType<"bool">;
 def BuiltinTypeKind : EnumPropertyType<"BuiltinType::Kind">;

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ba3161c366f4d9..1bcc7ee0b70dee 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -69,6 +69,7 @@ class ValueDecl;
 class TagDecl;
 class Te

[clang] [clang/AST] Make it possible to use SwiftAttr in type context (PR #108631)

2024-10-31 Thread Gábor Horváth via cfe-commits

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


[clang] [llvm] [LLVM][IR] Use splat syntax when printing Constant[Data]Vector. (PR #112548)

2024-10-31 Thread Paul Walker via cfe-commits


@@ -1690,6 +1690,23 @@ static void WriteConstantInternal(raw_ostream &Out, 
const Constant *CV,
   if (isa(CV) || isa(CV)) {
 auto *CVVTy = cast(CV->getType());
 Type *ETy = CVVTy->getElementType();
+
+// Use the same shorthand for splat vector (i.e. "splat(Ty val)") as is
+// permitted on IR input to reduce the output changes when enabling
+// UseConstant{Int,FP}ForFixedLengthSplat.
+// TODO: Remove this block when the UseConstant{Int,FP}ForFixedLengthSplat
+// options are removed.
+if (auto *SplatVal = CV->getSplatValue()) {
+  if (isa(SplatVal) || isa(SplatVal)) {
+Out << "splat (";

paulwalker-arm wrote:

The splat printing follows the same style as used for ConstantExprs.

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


[clang] [libclang/python] Clean up tests (PR #114383)

2024-10-31 Thread Jannick Kremer via cfe-commits


@@ -344,7 +343,7 @@ class Bar {
 )
 
 self.assertEqual(len(copy_assignment_operators_cursors), 10)
-self.assertTrue(len(non_copy_assignment_operators_cursors), 9)
+self.assertEqual(len(non_copy_assignment_operators_cursors), 7)

DeinAlptraum wrote:

I made a mistake here in #109846 

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


[clang] [analyzer] EvalBinOpLL should return Unknown less often (PR #114222)

2024-10-31 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

> I think we don't have any mechanisms like these. This was just a theoretical 
> comment if I understood it right.

Actually, both. Yes, we don't have many of these in the engine as of today, but 
we do model some overflows in some checkers, like the bitwise shifts checker. 
It would be nice if we could write that logic once, and reuse it in constant 
folding as well, but this is really theoretical at this point. 

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


[libclc] [libclc] Move min/max/clamp into the CLC builtins library (PR #114386)

2024-10-31 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/114386

>From 0465b89a7b624b8015e27efdbaf948c4aadd0e94 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 26 Sep 2024 08:57:15 +0100
Subject: [PATCH] [libclc] Move min/max/clamp into the CLC builtins library

These functions are "shared" between integer and floating-point types,
hence the directory name. They are used in several CLC internal
functions such as __clc_ldexp.

Note that clspv and spirv targets don't want to define these functions,
so pre-processor macros replace calls to __clc_min with regular min, for
example. This means they can use as much of the generic CLC source files
as possible, but where CLC functions would usually call out to an
external __clc_min symbol, they call out to an external min symbol. Then
they opt out of defining __clc_min itself in their CLC builtins
library.

Preprocessor definitions for these targets have also been
changed somewhat: what used to be CLC_SPIRV (the 32-bit target) is now
CLC_SPIRV32, and CLC_SPIRV now represents either CLC_SPIRV32 or
CLC_SPIRV64. Same goes for CLC_CLSPV.

There are no differences (measured with llvm-diff) in any of the final
builtins libraries for nvptx, amdgpu, or clspv. Neither are there
differences in the SPIR-V targets' LLVM IR before it's actually lowered
to SPIR-V.
---
 libclc/CMakeLists.txt | 15 ---
 libclc/clc/include/clc/clcfunc.h  |  4 ++--
 .../include/clc/integer/gentype.inc   |  4 ++--
 .../{generic => clc}/include/clc/math/gentype.inc |  0
 libclc/clc/include/clc/shared/clc_clamp.h | 15 +++
 libclc/clc/include/clc/shared/clc_clamp.inc   |  9 +
 libclc/clc/include/clc/shared/clc_max.h   | 12 
 libclc/clc/include/clc/shared/clc_max.inc |  7 +++
 libclc/clc/include/clc/shared/clc_min.h   | 12 
 libclc/clc/include/clc/shared/clc_min.inc |  7 +++
 libclc/clc/lib/generic/SOURCES|  3 +++
 libclc/clc/lib/generic/shared/clc_clamp.cl|  7 +++
 libclc/clc/lib/generic/shared/clc_clamp.inc   | 14 ++
 libclc/clc/lib/generic/shared/clc_max.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_max.inc | 11 +++
 libclc/clc/lib/generic/shared/clc_min.cl  |  7 +++
 libclc/clc/lib/generic/shared/clc_min.inc | 11 +++
 libclc/generic/include/config.h   |  2 ++
 libclc/generic/lib/common/smoothstep.cl   |  2 +-
 libclc/generic/lib/common/step.cl |  2 +-
 libclc/generic/lib/math/clc_hypot.cl  |  4 +++-
 libclc/generic/lib/math/clc_ldexp.cl  |  9 +
 libclc/generic/lib/math/math.h|  2 +-
 libclc/generic/lib/shared/clamp.cl|  1 +
 libclc/generic/lib/shared/clamp.inc   |  4 ++--
 libclc/generic/lib/shared/max.cl  |  1 +
 libclc/generic/lib/shared/max.inc |  7 ---
 libclc/generic/lib/shared/min.cl  |  1 +
 libclc/generic/lib/shared/min.inc |  7 ---
 29 files changed, 164 insertions(+), 23 deletions(-)
 rename libclc/{generic => clc}/include/clc/integer/gentype.inc (99%)
 rename libclc/{generic => clc}/include/clc/math/gentype.inc (100%)
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.h
 create mode 100644 libclc/clc/include/clc/shared/clc_clamp.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_max.h
 create mode 100644 libclc/clc/include/clc/shared/clc_max.inc
 create mode 100644 libclc/clc/include/clc/shared/clc_min.h
 create mode 100644 libclc/clc/include/clc/shared/clc_min.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_clamp.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_max.inc
 create mode 100644 libclc/clc/lib/generic/shared/clc_min.cl
 create mode 100644 libclc/clc/lib/generic/shared/clc_min.inc

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 16d74e53295cc1..2c2c7f16e29442 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -321,21 +321,30 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 message( STATUS "  device: ${d} ( ${${d}_aliases} )" )
 
 if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
-  set( build_flags -O0 -finline-hint-functions )
+  set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
   set( opt_flags )
   set( spvflags --spirv-max-version=1.1 )
+  set( MACRO_ARCH SPIRV32 )
+  if( ARCH STREQUAL spirv64 )
+set( MACRO_ARCH SPIRV64 )
+  endif()
 elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
-  set( build_flags "-Wno-unknown-assumption")
+  set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
   set( opt_flags -O3 )
+  set( MACRO_A

[clang] [clang][bytecode] Diagnose delete with non-virtual dtor (PR #114373)

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

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


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

2024-10-31 Thread LLVM Continuous Integration via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

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

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


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 :: Analysis/scan-build/deduplication.test' 
FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 3
rm -rf 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
 && mkdir 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed command: rm -rf 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed command: mkdir 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# RUN: at line 4
'/usr/bin/perl' 
'/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/tools/scan-build/bin/scan-build'
 --use-analyzer=/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang-20 
 -o 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
  /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -S 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c

/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c
  | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test
 -check-prefix CHECK-STDOUT
# executed command: /usr/bin/perl 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/tools/scan-build/bin/scan-build
 --use-analyzer=/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang-20 
-o 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
 /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -S 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c
 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c
# .---command stderr
# | In file included from 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c:1:
# | 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/header.h:3:12:
 warning: Division by zero [core.DivideZero]
# | 3 |   return 1 / x;
# |   |  ~~^~~
# | 1 warning generated.
# | In file included from 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c:1:
# | 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/header.h:3:12:
 warning: Division by zero [core.DivideZero]
# | 3 |   return 1 / x;
# |   |  ~~^~~
# | 1 warning generated.
# `-
# executed command: 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test
 -check-prefix CHECK-STDOUT
# RUN: at line 9
ls 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir/*/
 | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test
 -check-prefix CHECK-FILENAMES
# executed command: ls 
'/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir/*/'
# executed command: 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test
 -check-prefix CHECK-FILENAMES
# RUN: at line 11
rm -rf 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
 && mkdir 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed comman

[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread David Olsen via cfe-commits

https://github.com/dkolsen-pgi updated 
https://github.com/llvm/llvm-project/pull/113483

>From fd38921f9899e3e5ae538a94f123433119919731 Mon Sep 17 00:00:00 2001
From: David Olsen 
Date: Wed, 23 Oct 2024 11:01:40 -0700
Subject: [PATCH 1/2] [CIR] Call code gen; create empty cir.func op

Finish hooking up ClangIR code gen into the Clang control flow,
initializing enough that basic code gen is possible.

Add an almost empty cir.func op to the ClangIR dialect.  Currently the
only property of the function is its name.  Add the code necessary to
code gen a cir.func op.

Create essentially empty files
clang/lib/CIR/Dialect/IR/{CIRAttrs.cpp,CIRTypes.cpp}.  These will be
filled in later as attributes and types are defined in the ClangIR
dialect.

(Part of upstreaming the ClangIR incubator project into LLVM.)
---
 clang/include/clang/CIR/CIRGenerator.h|   1 +
 .../include/clang/CIR/Dialect/IR/CIRDialect.h |  18 +++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  46 ++
 clang/lib/CIR/CodeGen/CIRGenModule.cpp| 151 +-
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  31 
 clang/lib/CIR/CodeGen/CIRGenerator.cpp|  10 +-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp |  38 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  52 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp |  37 +
 clang/lib/CIR/Dialect/IR/CMakeLists.txt   |   2 +
 clang/lib/CIR/FrontendAction/CIRGenAction.cpp |  43 -
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 12 files changed, 424 insertions(+), 7 deletions(-)
 create mode 100644 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
 create mode 100644 clang/lib/CIR/Dialect/IR/CIRTypes.cpp

diff --git a/clang/include/clang/CIR/CIRGenerator.h 
b/clang/include/clang/CIR/CIRGenerator.h
index 9a8930ac46ea9c..f72cea6e11692a 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -53,6 +53,7 @@ class CIRGenerator : public clang::ASTConsumer {
   ~CIRGenerator() override;
   void Initialize(clang::ASTContext &astCtx) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
+  mlir::ModuleOp getModule();
 };
 
 } // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h 
b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
index d53e5d1663d62a..5c00225013d81e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
@@ -13,4 +13,22 @@
 #ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 #define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/OpDefinition.h"
+#include "mlir/Interfaces/CallInterfaces.h"
+#include "mlir/Interfaces/ControlFlowInterfaces.h"
+#include "mlir/Interfaces/FunctionInterfaces.h"
+#include "mlir/Interfaces/InferTypeOpInterface.h"
+#include "mlir/Interfaces/LoopLikeInterface.h"
+#include "mlir/Interfaces/MemorySlotInterfaces.h"
+#include "mlir/Interfaces/SideEffectInterfaces.h"
+
+#include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
+
+#define GET_OP_CLASSES
+#include "clang/CIR/Dialect/IR/CIROps.h.inc"
+
 #endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7311c8db783e06..06554bf4717c81 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -16,4 +16,50 @@
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
 
+include "mlir/Interfaces/ControlFlowInterfaces.td"
+include "mlir/Interfaces/FunctionInterfaces.td"
+include "mlir/Interfaces/InferTypeOpInterface.td"
+include "mlir/Interfaces/LoopLikeInterface.td"
+include "mlir/Interfaces/MemorySlotInterfaces.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
+
+include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/IR/EnumAttr.td"
+include "mlir/IR/SymbolInterfaces.td"
+include "mlir/IR/CommonAttrConstraints.td"
+
+//===--===//
+// CIR Ops
+//===--===//
+
+class LLVMLoweringInfo {
+  string llvmOp = "";
+}
+
+class CIR_Op traits = []> :
+Op, LLVMLoweringInfo;
+
+//===--===//
+// FuncOp
+//===--===//
+
+// For starters, cir.func has only name, nothing else.  The other properties
+// of a function will be added over time as more of ClangIR is upstreamed.
+
+def FuncOp : CIR_Op<"func"> {
+  let summary = "Declare or define a function";
+  let description = [{
+... lots of text to be added later ...
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name);
+
+  let skipDefaultBuilders = 1;
+
+  let builders = [OpBuilder<(ins "StringRef":$name)>];
+
+  let hasCustomAssem

[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-10-31 Thread Chris Cotter via cfe-commits

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


[clang] [Clang][Sema] Always use latest redeclaration of primary template (PR #114258)

2024-10-31 Thread Felipe de Azevedo Piovezan via cfe-commits

felipepiovezan wrote:

> > @felipepiovezan I tested without this patch applied and was still seeing 
> > crashes... could you perhaps see if 
> > https://github.com/sdkrystian/llvm-project/tree/reapply-use-latest-primary 
> > fixes the regression?
> 
> Let me give it a try now!

Yup, that fixes the issue. I've also confirmed that reverting the fix brings 
back the crash!

It is weird that you were unable to repro this 🤔 Were you perhaps not building 
libcxx at the same time?

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


[clang] [llvm] [X86][AMX] Support AMX-TRANSPOSE (PR #113532)

2024-10-31 Thread Feng Zou via cfe-commits


@@ -34,9 +34,31 @@ class ShapeT {
 if (MRI)
   deduceImm(MRI);
   }
+  // When ShapeT has mult shapes, we only use Shapes (never use Row and Col)
+  // and ImmShapes. Due to the most case is only one shape (just simply use
+  // Shape.Row or Shape.Col), so here we don't merge Row and Col into vector
+  // Shapes to keep the speed and code simplicity.
+  // TODO: The upper solution is a temporary way to minimize current tile
+  // register allocation code changes. It can not handle both Reg shape and
+  // Imm shape for different shapes (e.g. shape 1 is reg shape while shape 2
+  // is imm shape). Refine me when we have more mult-tile shape instructions!
+  ShapeT(ArrayRef ShapesOperands,
+ const MachineRegisterInfo *MRI = nullptr)
+  : Row(nullptr), Col(nullptr), RowImm(InvalidImmShape),
+ColImm(InvalidImmShape) {
+assert(ShapesOperands.size() % 2 == 0 && "Miss row or col!");
+
+for (auto *Shape : ShapesOperands)
+  Shapes.push_back(Shape);
+
+if (MRI)
+  deduceImm(MRI);
+  }
   ShapeT()
   : Row(nullptr), Col(nullptr), RowImm(InvalidImmShape),
 ColImm(InvalidImmShape) {}
+  // TODO: We need to extern cmp operator for muti-shapes if

fzou1 wrote:

muti->multi

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


[clang] [clang/AST] Make it possible to use SwiftAttr in type context (PR #108631)

2024-10-31 Thread via cfe-commits

github-actions[bot] wrote:



@xedin Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Edd Dawson (playstation-edd)


Changes

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+12-2) 
- (modified) clang/test/Driver/ps5-linker.c (+18) 


``diff
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

``




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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread David Olsen via cfe-commits


@@ -0,0 +1,38 @@
+//===- CIRAttrs.cpp - MLIR CIR Attributes 
-===//
+//
+// 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 the attributes in the CIR dialect.
+//
+//===--===//
+
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+
+using namespace mlir;
+using namespace mlir::cir;

dkolsen-pgi wrote:

Those `using namespace` directives are in the Clang incubator project.  I would 
prefer to minimize the gratuitous differences between LLVM upstream and ClangIR 
incubator.

There is discussion about getting rid of the `::mlir::cir` namespace and moving 
everything therein to the `::cir` namespace.  If that happens, I will make the 
corresponding change upstream and will likely get rid of the `using namespace` 
directives then.


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


[clang] [libclang/python/tests] Clean up imports (PR #114409)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Sort imports using `isort`.
Remove unused imports.
Collect multiple imports from the same module into a single import statement.
Unify import style.

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


21 Files Affected:

- (modified) clang/bindings/python/tests/cindex/test_access_specifiers.py 
(+4-8) 
- (modified) clang/bindings/python/tests/cindex/test_cdb.py (+2-6) 
- (modified) clang/bindings/python/tests/cindex/test_code_completion.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_comment.py (+4-4) 
- (modified) clang/bindings/python/tests/cindex/test_cursor.py (+12-13) 
- (modified) clang/bindings/python/tests/cindex/test_cursor_kind.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_diagnostics.py (+3-4) 
- (modified) clang/bindings/python/tests/cindex/test_enums.py (+8-8) 
- (modified) 
clang/bindings/python/tests/cindex/test_exception_specification_kind.py (+5-6) 
- (modified) clang/bindings/python/tests/cindex/test_file.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_index.py (+2-4) 
- (modified) clang/bindings/python/tests/cindex/test_linkage.py (+4-8) 
- (modified) clang/bindings/python/tests/cindex/test_location.py (+10-9) 
- (modified) clang/bindings/python/tests/cindex/test_rewrite.py (+2-8) 
- (modified) clang/bindings/python/tests/cindex/test_source_range.py (+2-2) 
- (modified) clang/bindings/python/tests/cindex/test_tls_kind.py (+4-8) 
- (modified) clang/bindings/python/tests/cindex/test_token_kind.py (+2-3) 
- (modified) clang/bindings/python/tests/cindex/test_tokens.py (+3-8) 
- (modified) clang/bindings/python/tests/cindex/test_translation_unit.py 
(+15-15) 
- (modified) clang/bindings/python/tests/cindex/test_type.py (+3-9) 
- (modified) clang/bindings/python/tests/cindex/util.py (+1-2) 


``diff
diff --git a/clang/bindings/python/tests/cindex/test_access_specifiers.py 
b/clang/bindings/python/tests/cindex/test_access_specifiers.py
index c1cc18ebe6e589..ca2bbd3cc86117 100644
--- a/clang/bindings/python/tests/cindex/test_access_specifiers.py
+++ b/clang/bindings/python/tests/cindex/test_access_specifiers.py
@@ -1,18 +1,14 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import AccessSpecifier, Config
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import AccessSpecifier
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
-
-from .util import get_cursor
-from .util import get_tu
-
 import unittest
 
+from .util import get_cursor, get_tu
+
 
 class TestAccessSpecifiers(unittest.TestCase):
 def test_access_specifiers(self):
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py 
b/clang/bindings/python/tests/cindex/test_cdb.py
index 299e79a2708988..342a544c86337b 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -1,14 +1,10 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import CompilationDatabase, CompilationDatabaseError, Config
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import CompilationDatabase
-from clang.cindex import CompilationDatabaseError
-from clang.cindex import CompileCommands
-from clang.cindex import CompileCommand
-import os
 import gc
 import unittest
 import sys
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py 
b/clang/bindings/python/tests/cindex/test_code_completion.py
index 921a8f1f0aac87..c7a86aa82a8ebc 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -1,11 +1,10 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import Config, TranslationUnit
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import TranslationUnit
-
 import unittest
 from pathlib import Path
 
diff --git a/clang/bindings/python/tests/cindex/test_comment.py 
b/clang/bindings/python/tests/cindex/test_comment.py
index 265c6d3d73de04..1ecbb42c18ffca 100644
--- a/clang/bindings/python/tests/cindex/test_comment.py
+++ b/clang/bindings/python/tests/cindex/test_comment.py
@@ -1,14 +1,14 @@
 import os
-from clang.cindex import Config
+
+from clang.cindex import Config, TranslationUnit
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
 
-from clang.cindex import TranslationUnit
-from tests.cindex.util import get_cursor
-
 import unittest
 
+from .util import get_cursor
+
 
 class TestComment(unittest.TestCase):
 def test_comment(self):
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py 
b/clang/bindings/python/tests/cindex/test_cursor.py
index 81c7f1c74966f1..4d989a7421e790 100

[clang] [Clang][Sema] Always use latest redeclaration of primary template (PR #114258)

2024-10-31 Thread Felipe de Azevedo Piovezan via cfe-commits

felipepiovezan wrote:

> @felipepiovezan I tested without this patch applied and was still seeing 
> crashes... could you perhaps see if 
> https://github.com/sdkrystian/llvm-project/tree/reapply-use-latest-primary 
> fixes the regression?

Let me give it a try now!

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-10-31 Thread Helena Kotas via cfe-commits

hekota wrote:

LGTM! I'm not familiar with the SPIR-V side though.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread David Olsen via cfe-commits

https://github.com/dkolsen-pgi updated 
https://github.com/llvm/llvm-project/pull/113483

>From fd38921f9899e3e5ae538a94f123433119919731 Mon Sep 17 00:00:00 2001
From: David Olsen 
Date: Wed, 23 Oct 2024 11:01:40 -0700
Subject: [PATCH 1/2] [CIR] Call code gen; create empty cir.func op

Finish hooking up ClangIR code gen into the Clang control flow,
initializing enough that basic code gen is possible.

Add an almost empty cir.func op to the ClangIR dialect.  Currently the
only property of the function is its name.  Add the code necessary to
code gen a cir.func op.

Create essentially empty files
clang/lib/CIR/Dialect/IR/{CIRAttrs.cpp,CIRTypes.cpp}.  These will be
filled in later as attributes and types are defined in the ClangIR
dialect.

(Part of upstreaming the ClangIR incubator project into LLVM.)
---
 clang/include/clang/CIR/CIRGenerator.h|   1 +
 .../include/clang/CIR/Dialect/IR/CIRDialect.h |  18 +++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  46 ++
 clang/lib/CIR/CodeGen/CIRGenModule.cpp| 151 +-
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  31 
 clang/lib/CIR/CodeGen/CIRGenerator.cpp|  10 +-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp |  38 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  52 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp |  37 +
 clang/lib/CIR/Dialect/IR/CMakeLists.txt   |   2 +
 clang/lib/CIR/FrontendAction/CIRGenAction.cpp |  43 -
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 12 files changed, 424 insertions(+), 7 deletions(-)
 create mode 100644 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
 create mode 100644 clang/lib/CIR/Dialect/IR/CIRTypes.cpp

diff --git a/clang/include/clang/CIR/CIRGenerator.h 
b/clang/include/clang/CIR/CIRGenerator.h
index 9a8930ac46ea9c..f72cea6e11692a 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -53,6 +53,7 @@ class CIRGenerator : public clang::ASTConsumer {
   ~CIRGenerator() override;
   void Initialize(clang::ASTContext &astCtx) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
+  mlir::ModuleOp getModule();
 };
 
 } // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h 
b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
index d53e5d1663d62a..5c00225013d81e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
@@ -13,4 +13,22 @@
 #ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 #define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/OpDefinition.h"
+#include "mlir/Interfaces/CallInterfaces.h"
+#include "mlir/Interfaces/ControlFlowInterfaces.h"
+#include "mlir/Interfaces/FunctionInterfaces.h"
+#include "mlir/Interfaces/InferTypeOpInterface.h"
+#include "mlir/Interfaces/LoopLikeInterface.h"
+#include "mlir/Interfaces/MemorySlotInterfaces.h"
+#include "mlir/Interfaces/SideEffectInterfaces.h"
+
+#include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
+
+#define GET_OP_CLASSES
+#include "clang/CIR/Dialect/IR/CIROps.h.inc"
+
 #endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7311c8db783e06..06554bf4717c81 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -16,4 +16,50 @@
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
 
+include "mlir/Interfaces/ControlFlowInterfaces.td"
+include "mlir/Interfaces/FunctionInterfaces.td"
+include "mlir/Interfaces/InferTypeOpInterface.td"
+include "mlir/Interfaces/LoopLikeInterface.td"
+include "mlir/Interfaces/MemorySlotInterfaces.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
+
+include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/IR/EnumAttr.td"
+include "mlir/IR/SymbolInterfaces.td"
+include "mlir/IR/CommonAttrConstraints.td"
+
+//===--===//
+// CIR Ops
+//===--===//
+
+class LLVMLoweringInfo {
+  string llvmOp = "";
+}
+
+class CIR_Op traits = []> :
+Op, LLVMLoweringInfo;
+
+//===--===//
+// FuncOp
+//===--===//
+
+// For starters, cir.func has only name, nothing else.  The other properties
+// of a function will be added over time as more of ClangIR is upstreamed.
+
+def FuncOp : CIR_Op<"func"> {
+  let summary = "Declare or define a function";
+  let description = [{
+... lots of text to be added later ...
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name);
+
+  let skipDefaultBuilders = 1;
+
+  let builders = [OpBuilder<(ins "StringRef":$name)>];
+
+  let hasCustomAssem

[clang] [llvm] [InstrPGO] Avoid using global variable to fix potential data race (PR #114364)

2024-10-31 Thread Lei Wang via cfe-commits

https://github.com/wlei-llvm updated 
https://github.com/llvm/llvm-project/pull/114364

>From a7b444bd75d6f83ed0f5692783990a59f36e8459 Mon Sep 17 00:00:00 2001
From: wlei 
Date: Thu, 31 Oct 2024 09:58:27 -0700
Subject: [PATCH 1/3] Reapply "[InstrPGO] Support cold function coverage
 instrumentation (#109837)"

This reverts commit d924a9ba03a05b417676e84f6c81aac44f907f71.
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Driver/ToolChain.cpp|  4 ++-
 clang/lib/Driver/ToolChains/Clang.cpp | 20 +++
 .../test/CodeGen/pgo-cold-function-coverage.c | 19 ++
 ...fprofile-generate-cold-function-coverage.c |  8 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 17 -
 .../Instrumentation/PGOInstrumentation.cpp| 19 ++
 .../PGOProfile/instr-gen-cold-function.ll | 35 +++
 8 files changed, 126 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/pgo-cold-function-coverage.c
 create mode 100644 clang/test/Driver/fprofile-generate-cold-function-coverage.c
 create mode 100644 llvm/test/Transforms/PGOProfile/instr-gen-cold-function.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8bc2fe377b8ec..2814d2b1bf3733 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1786,6 +1786,12 @@ defm debug_info_for_profiling : 
BoolFOption<"debug-info-for-profiling",
   PosFlag,
   NegFlag>;
+def fprofile_generate_cold_function_coverage : Flag<["-"], 
"fprofile-generate-cold-function-coverage">, 
+Group, Visibility<[ClangOption, CLOption]>,
+HelpText<"Generate instrumented code to collect coverage info for cold 
functions into default.profraw file (overridden by '=' form of option or 
LLVM_PROFILE_FILE env var)">;
+def fprofile_generate_cold_function_coverage_EQ : Joined<["-"], 
"fprofile-generate-cold-function-coverage=">, 
+Group, Visibility<[ClangOption, CLOption]>, 
MetaVarName<"">,
+HelpText<"Generate instrumented code to collect coverage info for cold 
functions into /default.profraw (overridden by LLVM_PROFILE_FILE env 
var)">; 
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 6d3ede40691093..bdf3da0c96adca 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -899,7 +899,9 @@ bool ToolChain::needsProfileRT(const ArgList &Args) {
  Args.hasArg(options::OPT_fprofile_instr_generate) ||
  Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
  Args.hasArg(options::OPT_fcreate_profile) ||
- Args.hasArg(options::OPT_forder_file_instrumentation);
+ Args.hasArg(options::OPT_forder_file_instrumentation) ||
+ Args.hasArg(options::OPT_fprofile_generate_cold_function_coverage) ||
+ Args.hasArg(options::OPT_fprofile_generate_cold_function_coverage_EQ);
 }
 
 bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) {
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 04b3832327a99c..4c6f508f1f24a6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -632,6 +632,26 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 }
   }
 
+  if (auto *ColdFuncCoverageArg = Args.getLastArg(
+  options::OPT_fprofile_generate_cold_function_coverage,
+  options::OPT_fprofile_generate_cold_function_coverage_EQ)) {
+SmallString<128> Path(
+ColdFuncCoverageArg->getOption().matches(
+options::OPT_fprofile_generate_cold_function_coverage_EQ)
+? ColdFuncCoverageArg->getValue()
+: "");
+llvm::sys::path::append(Path, "default_%m.profraw");
+// FIXME: Idealy the file path should be passed through
+// `-fprofile-instrument-path=`(InstrProfileOutput), however, this field is
+// shared with other profile use path(see PGOOptions), we need to refactor
+// PGOOptions to make it work.
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString(
+Twine("--instrument-cold-function-only-path=") + Path));
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("--pgo-function-entry-coverage");
+  }
+
   Arg *PGOGenArg = nullptr;
   if (PGOGenerateArg) {
 assert(!CSPGOGenerateArg);
diff --git a/clang/test/CodeGen/pgo-cold-function-coverage.c 
b/clang/test/CodeGen/pgo-cold-function-coverage.c
new file mode 100644
index 00..fd1e1e7e14cda5
--- /dev/null
+++ b/clang/test/CodeGen/pgo-cold-function-coverage.c
@@ -0,0 +1,19 @@
+// Test -fprofile-generate-cold-function-coverage 
+
+// RUN: rm -rf %t && sp

[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)

2024-10-31 Thread Helena Kotas via cfe-commits


@@ -483,10 +582,101 @@ static BuiltinTypeDeclBuilder 
setupBufferType(CXXRecordDecl *Decl, Sema &S,
   .addDefaultHandleConstructor(S, RC);
 }
 
+BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context,
+ SourceLocation NameLoc,
+ TemplateTypeParmDecl *T) {
+  // Obtain the QualType for 'unsigned long'
+  QualType UnsignedLongType = Context.UnsignedLongTy;
+
+  // Create a QualType that points to this TemplateTypeParmDecl
+  QualType TType = Context.getTypeDeclType(T);
+
+  // Create a TypeSourceInfo for the template type parameter 'T'
+  TypeSourceInfo *TTypeSourceInfo =
+  Context.getTrivialTypeSourceInfo(TType, NameLoc);
+
+  UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) 
UnaryExprOrTypeTraitExpr(
+  UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc);
+
+  // Create an IntegerLiteral for the value '16' with size type
+  QualType SizeType = Context.getSizeType();
+  llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16);
+  IntegerLiteral *SizeLiteral =
+  new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc);
+
+  QualType BoolTy = Context.BoolTy;
+
+  BinaryOperator *binaryOperator =
+  BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression
+ SizeLiteral, // Right-hand side expression
+ BO_LE,   // Binary operator kind (<=)
+ BoolTy,  // Result type (bool)
+ VK_LValue,   // Value kind
+ OK_Ordinary, // Object kind
+ NameLoc, // Source location of 
operator
+ FPOptionsOverride());
+
+  return binaryOperator;
+}
+
+Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,
+ TemplateTypeParmDecl *T) {
+  ASTContext &Context = S.getASTContext();
+
+  // first get the "sizeof(T) <= 16" expression, as a binary operator
+  BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T);
+  // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin
+  // and return a binary operator that evaluates the builtin on the given
+  // template type parameter 'T'
+  return SizeOfLEQ16;
+}
+
+ConceptDecl *constructTypedBufferConceptDecl(Sema &S) {
+  DeclContext *DC = S.CurContext;
+  ASTContext &Context = S.getASTContext();
+  SourceLocation DeclLoc = SourceLocation();
+
+  IdentifierInfo &IsValidLineVectorII =
+  Context.Idents.get("is_valid_line_vector");
+  IdentifierInfo &ElementTypeII = Context.Idents.get("element_type");
+  TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create(
+  Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc,
+  /*depth=*/0,
+  /*position=*/0,
+  /*id=*/&ElementTypeII,
+  /*Typename=*/true,
+  /*ParameterPack=*/false);
+
+  T->setDeclContext(DC);
+  T->setReferenced();
+
+  // Create and Attach Template Parameter List to ConceptDecl
+  TemplateParameterList *ConceptParams = TemplateParameterList::Create(
+  Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr);
+
+  DeclarationName DeclName = DeclarationName(&IsValidLineVectorII);
+  Expr *ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T);
+
+  // Create a ConceptDecl
+  ConceptDecl *CD =
+  ConceptDecl::Create(Context, Context.getTranslationUnitDecl(), DeclLoc,
+  DeclName, ConceptParams, ConstraintExpr);
+
+  // Attach the template parameter list to the ConceptDecl
+  CD->setTemplateParameters(ConceptParams);
+
+  // Add the concept declaration to the Translation Unit Decl
+  Context.getTranslationUnitDecl()->addDecl(CD);
+
+  return CD;
+}
+
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
+  ConceptDecl *CD = constructTypedBufferConceptDecl(*SemaPtr);

hekota wrote:

I'd probably use a more descriptive name here, like `TypeBufferConcept` since 
as we'll need to have one for RawBuffers as well, right?

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread David Olsen via cfe-commits

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


[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-31 Thread Brad Richardson via cfe-commits

everythingfunctional wrote:

> @everythingfunctional with this change and install, we are installing flang 
> with the -20 in the install dir: `-- Installing: 
> /build/source/debian/tmp/usr/lib/llvm-20/bin/flang-20`
> 
> it should not be the case, it should be named `/usr/lib/llvm-20/bin/flang` to 
> match what is done elsewhere

Forgive me if I misunderstood or implemented this incorrectly, but I was under 
the impression (based on [an earlier 
comment](https://github.com/llvm/llvm-project/pull/110023#issuecomment-2378556647))
 that this was the intended behavior.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}
+
+mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
+  assert(cRange.isValid() && "expected a valid source range");
+  mlir::Location begin = getLoc(cRange.getBegin());
+  mlir::Location end = getLoc(cRange.getEnd());
+  SmallVector locs = {begin, end};
+  mlir::Attribute metadata;
+  return mlir::FusedLoc::get(locs, metadata, builder.getContext());
+}
+
+void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
+  const auto *global = cast(gd.getDecl());
+
+  if (const auto *fd = dyn_cast(global)) {
+// Update deferred annotations with the latest declaration if the function
+// was already used or defined.
+if (fd->hasAttr()) {
+  errorNYI(fd->getSourceRange(), "defferedAnnotations");
+}
+if (!fd->doesThisDeclarationHaveABody()) {
+  if (!fd->doesDeclarationForceExternallyVisibleDefinition())
+return;
+
+  errorNYI(fd->getSourceRange(),
+   "function declaration that forces code gen");
+  return;
+}
+  } else {
+errorNYI(global->getSourceRange(), "global variable declaration");
+  }
+
+  // TODO(CIR): Defer emitting some global definitions until later
+  buildGlobalDefinition(gd);
+}
+
+void CIRGenModule::buildGlobalFunctionDefinition(clang::GlobalDecl gd,
+ mlir::Operation *op) {
+  auto const *funcDecl = cast(gd.getDecl());
+  auto funcOp = builder.create(
+  getLoc(funcDecl->getSourceRange()), 
funcDecl->getIdentifier()->getName());
+  theModule.push_back(funcOp);
+}
+
+void CIRGenModule::buildGlobalDefinition(clang::GlobalDecl gd,
+ mlir::Operation *op) {
+  const auto *decl = cast(gd.getDecl());
+  if (const auto *fd = dyn_cast(decl)) {
+// TODO(CIR): Skip generation of CIR for functions with 
available_externally
+// linkage at -O0.
+
+if (const auto *method = dyn_cast(decl)) {
+  // Make sure to emit the definition(s) before we emit the thunks. This is
+  // necessary for the generation of certain thunks.
+  (void)method;
+  errorNYI(method->getSourceRange(), "member function");
+  return;
+}
+
+if (fd->isMultiVersion())
+  errorNYI(fd->getSourceRange(), "multiversion functions");
+buildGlobalFunctionDefinition(gd, op);
+return;
+  }
+
+  llvm_unreachable("Invalid argument to CIRGenModule::buildGlobalDefinition");
+}
 
 // Emit code for a single top level declaration.
-void CIRGenModule::buildTopLevelDecl(Decl *decl) {}
+void CIRGenModule::buildTopLevelDecl(Decl *decl) {
+
+  // Ignore dependent declarations.
+  if (decl->isTemplated())
+return;
+
+  switch (decl->getKind()) {
+  default:
+errorNYI(decl->getBeginLoc(), "declaration of kind",
+ decl->getDeclKindName());
+break;
+
+  case Decl::Function: {
+auto *fd = cast(decl);
+// Consteval functions shouldn't be emitted.
+if (!fd->isConsteval())
+  buildGlobal(fd);
+break;
+  }
+  }
+}
+
+DiagnosticBuilder CIRGenModule::errorNYI(llvm::StringRef feature) {
+  unsigned diagID = diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "ClangIR code gen NYI: %0");
+  return diags.Report(diagID) << feature;
+}
+
+DiagnosticBuilder CIRGenModule::errorNYI(SourceLocation loc,
+ llvm::StringRef feature) {
+  unsigned diagID = diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "ClangIR code gen NYI: %0");
+  return diags.Report(loc, diagID) << feature;
+}
+
+DiagnosticBuilder CIRGenModule::errorNYI(SourceLocation loc,
+ llvm::StringRef feature,
+ llvm::StringRef name) {
+  unsigned diagID = diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "ClangIR code gen NYI: %0: %1");
+  return diags.Report(loc, diagID) << feature << name;
+}
+
+DiagnosticBuilder C

[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Justin Stitt via cfe-commits


@@ -831,6 +831,28 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
   return CanonTTP;
 }
 
+/// Check if a type can have its sanitizer instrumentation elided.
+/// Determine this by its presence in a SCL alongside its specified categories.
+/// For example:
+/// ignorelist.txt>
+/// [{unsigned-integer-overflow,signed-integer-overflow}]
+/// type:*=no_sanitize
+/// type:size_t=sanitize
+/// containsType(Mask, Ty.getAsString(), "sanitize");
+
+  bool noSanitizeType =

JustinStitt wrote:

Ok since some users of `isTypeIgnoredBySanitizer()` may want to use different 
type spellings for their purposes, should that method accept a `StringRef` 
which can be conjured up by any means necessary from the callsite instead of 
within the method itself?

@vitalybuka - pinging you since your notifications are strict :)

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


[clang] [HLSL] add IsTypedResourceElementCompatible type trait (PR #113730)

2024-10-31 Thread Joshua Batista via cfe-commits

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-31 Thread Peilin Ye via cfe-commits

peilin-ye wrote:

Pushed v8 to make it generate plain (`BPF_MEM`) loads and stores if user 
requested `__ATOMIC_RELAXED`, as suggested by Yonghong.  Updated commit message 
accordingly.

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


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Vitaly Buka via cfe-commits


@@ -831,6 +831,28 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
   return CanonTTP;
 }
 
+/// Check if a type can have its sanitizer instrumentation elided.
+/// Determine this by its presence in a SCL alongside its specified categories.
+/// For example:
+/// ignorelist.txt>
+/// [{unsigned-integer-overflow,signed-integer-overflow}]
+/// type:*=no_sanitize
+/// type:size_t=sanitize
+/// containsType(Mask, Ty.getAsString(), "sanitize");
+
+  bool noSanitizeType =

vitalybuka wrote:

I tried insert "getCanonicalType()" and none of tests of this patch failed.

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


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> @vitalybuka
> 
> > Is "Test documentation build" error related?
> 
> I am noticing this documentation build failing in other [un-related Clang 
> patchsets](https://github.com/llvm/llvm-project/actions/runs/11598884769/job/32295763452?pr=114281)
>  (related to `ClangFormattedStatus`?). I don't think my docs are to blame for 
> the build failures. My doc builds work locally.
> 
> I'll check back tomorrow to see if the documentation build is still failing.

I tried inser  "canonical" and none of test failed.

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


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Vitaly Buka via cfe-commits


@@ -831,6 +831,28 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
   return CanonTTP;
 }
 
+/// Check if a type can have its sanitizer instrumentation elided.
+/// Determine this by its presence in a SCL alongside its specified categories.
+/// For example:
+/// ignorelist.txt>
+/// [{unsigned-integer-overflow,signed-integer-overflow}]
+/// type:*=no_sanitize
+/// type:size_t=sanitize
+/// containsType(Mask, Ty.getAsString(), "sanitize");
+
+  bool noSanitizeType =

vitalybuka wrote:

I guess qual typ, as-is,  is OK, and we can left out `getCanonicalType()` and 
let callers to insert that.
So `Ty.getUnqualifiedType().getAsString(getPrintingPolicy());` is LGTM

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


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Justin Stitt via cfe-commits

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `dot4add_i8packed` intrinsic (PR #113623)

2024-10-31 Thread Steven Perron via cfe-commits


@@ -1,48 +1,59 @@
-; RUN: llc -O0 -mtriple=spirv32v1.3-vulkan-unknown %s -o - | FileCheck %s
+; RUN: llc -O0 -mtriple=spirv32v1.6-vulkan-unknown %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-DOT
+; RUN: llc -O0 -mtriple=spirv32-vulkan-unknown 
-spirv-ext=+SPV_KHR_integer_dot_product %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-DOT
+; RUN: llc -O0 -mtriple=spirv32-vulkan-unknown %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-EXP
 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32v1.3-vulkan-unknown %s -o - 
-filetype=obj | spirv-val %}
 
 ; CHECK-DAG: %[[#int_32:]] = OpTypeInt 32 0
-; CHECK-DAG: %[[#int_8:]] = OpTypeInt 8 0
-; CHECK-DAG: %[[#zero:]] = OpConstantNull %[[#int_8]]
-; CHECK-DAG: %[[#eight:]] = OpConstant %[[#int_8]] 8
-; CHECK-DAG: %[[#sixteen:]] = OpConstant %[[#int_8]] 16
-; CHECK-DAG: %[[#twentyfour:]] = OpConstant %[[#int_8]] 24
+; CHECK-EXP-DAG: %[[#int_8:]] = OpTypeInt 8 0
+; CHECK-EXP-DAG: %[[#zero:]] = OpConstantNull %[[#int_8]]
+; CHECK-EXP-DAG: %[[#eight:]] = OpConstant %[[#int_8]] 8
+; CHECK-EXP-DAG: %[[#sixteen:]] = OpConstant %[[#int_8]] 16
+; CHECK-EXP-DAG: %[[#twentyfour:]] = OpConstant %[[#int_8]] 24
+
 ; CHECK-LABEL: Begin function test_dot
 define noundef i32 @test_dot(i32 noundef %a, i32 noundef %b, i32 noundef %c) {
 entry:
 ; CHECK: %[[#A:]] = OpFunctionParameter %[[#int_32]]
 ; CHECK: %[[#B:]] = OpFunctionParameter %[[#int_32]]
 ; CHECK: %[[#C:]] = OpFunctionParameter %[[#int_32]]
 
+; Test that we use the dot product op when capabilities allow
+
+; CHECK-DOT: %[[#DOT:]] = OpDot %[[#int_32]] %[[#A]] %[[#B]]

s-perron wrote:

You might also need to add the capabilities that are enabled by the extensions 
in the Vulkan code as is done for OpenCL. It might be good to more it to 
`initAvailableCapabilities` since it will be the same for both.

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


[clang] [HLSL] add IsTypedResourceElementCompatible type trait (PR #113730)

2024-10-31 Thread Joshua Batista via cfe-commits

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `dot4add_i8packed` intrinsic (PR #113623)

2024-10-31 Thread Steven Perron via cfe-commits


@@ -1694,6 +1701,110 @@ bool 
SPIRVInstructionSelector::selectIntegerDot(Register ResVReg,
   return Result;
 }
 
+template 
+bool SPIRVInstructionSelector::selectDot4AddPacked(Register ResVReg,
+   const SPIRVType *ResType,
+   MachineInstr &I) const {
+  assert(I.getNumOperands() == 5);
+  assert(I.getOperand(2).isReg());
+  assert(I.getOperand(3).isReg());
+  assert(I.getOperand(4).isReg());
+  MachineBasicBlock &BB = *I.getParent();
+
+  Register Dot = MRI->createVirtualRegister(&SPIRV::IDRegClass);
+  bool Result = BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpDot))

s-perron wrote:

No you do not have to update the mlir code.

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


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Justin Stitt via cfe-commits


@@ -831,6 +831,28 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
   return CanonTTP;
 }
 
+/// Check if a type can have its sanitizer instrumentation elided.
+/// Determine this by its presence in a SCL alongside its specified categories.
+/// For example:
+/// ignorelist.txt>
+/// [{unsigned-integer-overflow,signed-integer-overflow}]
+/// type:*=no_sanitize
+/// type:size_t=sanitize
+/// https://github.com/llvm/llvm-project/pull/107332
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-31 Thread Justin Stitt via cfe-commits

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


[clang] Initialize SmallVector variable (PR #114434)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Arvind Sudarsanam (asudarsa)


Changes



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


1 Files Affected:

- (modified) clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp (+1-1) 


``diff
diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp 
b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index 0639b95c76e218..fa37cbeb56316c 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -237,7 +237,7 @@ Expected 
linkDeviceInputFiles(ArrayRef InputFiles,
 // will be linked with input device files.
 // The list of files and its location are passed from driver.
 Expected> getSYCLDeviceLibs(const ArgList &Args) {
-  SmallVector DeviceLibFiles;
+  SmallVector DeviceLibFiles{};
   StringRef LibraryPath;
   if (Arg *A = Args.getLastArg(OPT_library_path_EQ))
 LibraryPath = A->getValue();

``




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


[clang] Initialize SmallVector variable (PR #114434)

2024-10-31 Thread Arvind Sudarsanam via cfe-commits

https://github.com/asudarsa created 
https://github.com/llvm/llvm-project/pull/114434

None

>From 9cfc10768adf19e41b22cd6a9fb2c781fdf4498e Mon Sep 17 00:00:00 2001
From: Arvind Sudarsanam 
Date: Thu, 31 Oct 2024 10:34:06 -0700
Subject: [PATCH] Initialize SmallVector variable

Signed-off-by: Arvind Sudarsanam 
---
 clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp 
b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index 0639b95c76e218..fa37cbeb56316c 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -237,7 +237,7 @@ Expected 
linkDeviceInputFiles(ArrayRef InputFiles,
 // will be linked with input device files.
 // The list of files and its location are passed from driver.
 Expected> getSYCLDeviceLibs(const ArgList &Args) {
-  SmallVector DeviceLibFiles;
+  SmallVector DeviceLibFiles{};
   StringRef LibraryPath;
   if (Arg *A = Args.getLastArg(OPT_library_path_EQ))
 LibraryPath = A->getValue();

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-10-31 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> > I do have a ticket open to change the IRBuilder to check the function 
> > definition and set the strictfp mode automatically. But I pooched the 
> > branch on my end so I'll need to open a new ticket, hopefully this year. 
> > That still leaves hundreds of cases that need to be manually corrected.
> 
> The attribute `strictfp` requires refinement, which is outside of the 
> proposed changes and needs to be discussed separately. In particular a 
> function that changes FP environmet, but then restores it should not require 
> `strictfp` environment. It means `strictfp` should not be assigned 
> automatically.

Without the strictfp attribute the inliner will be allowed to inline that 
function that changes the FP environment into a function that is non-strictfp. 
Since we don't have FP barriers we'll then have optimizations moving 
instructions into and out of the inlined body. This can result in incorrect 
trap behavior, incorrect rounding happening, whatever, depending on how the FP 
environment is modified. So the strictfp attribute is required, period. What we 
need to do is reword the description in the LangRef to make this more clear.

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


[clang] [Clang][SYCL] Introduce clang-sycl-linker to link SYCL offloading device code (Part 1 of many) (PR #112245)

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

llvm-ci wrote:

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

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86761 of 86762 tests, 88 workers --
Testing:  0.. 10
FAIL: Clang :: Interpreter/inline-virtual.cpp (12531 of 86761)
 TEST 'Clang :: Interpreter/inline-virtual.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 6: cat 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl
 -Xcc -fno-rtti -Xcc -fno-sized-deallocation  | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl
 -Xcc -fno-rtti -Xcc -fno-sized-deallocation
+ cat 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
JIT session error: In graph incr_module_20-jitted-objectbuffer, section 
.text._ZN1AC2Ei: relocation target "_ZTV1A" at address 0x6cb11830e000 is out of 
range of Delta32 fixup at 0x70b118c2f082 (_ZN1AC2Ei, 0x70b118c2f070 + 0x12)
JIT session error: Failed to materialize symbols: { (main, { 
DW.ref.__gxx_personality_v0 }) }
error: Failed to materialize symbols: { (main, { _ZN1AC2Ei, a1, 
DW.ref.__gxx_personality_v0, $.incr_module_20.__inits.0, 
__orc_init_func.incr_module_20 }) }
JIT session error: Failed to materialize symbols: { (main, { a1 }) }
error: Failed to materialize symbols: { (main, { $.incr_module_21.__inits.0, 
__orc_init_func.incr_module_21 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_20 
}) }
JIT session error: Failed to materialize symbols: { (main, { _ZN1AD2Ev }) }
error: Failed to materialize symbols: { (main, { 
__orc_init_func.incr_module_25, a2, $.incr_module_25.__inits.0 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_25 
}) }
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp:22:11:
 error: CHECK: expected string not found in input
// CHECK: ~A(1)
  ^
:1:1: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-

[clang] cd8d507 - [RISCV] Pull __builtin_riscv_clz/ctz out of a nested switch. NFC

2024-10-31 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2024-10-31T11:01:58-07:00
New Revision: cd8d507b074e8d30f6c9925a24224673b2908a51

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

LOG: [RISCV] Pull __builtin_riscv_clz/ctz out of a nested switch. NFC

The nested switch exists to share setting IntrinsicsTypes to {ResultType}.
clz/ctz return before we reach that so they can just be in the top
level switch.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fb721fd2be9b8e..038057d2164ced 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -22398,10 +22398,6 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
   default: llvm_unreachable("unexpected builtin ID");
   case RISCV::BI__builtin_riscv_orc_b_32:
   case RISCV::BI__builtin_riscv_orc_b_64:
-  case RISCV::BI__builtin_riscv_clz_32:
-  case RISCV::BI__builtin_riscv_clz_64:
-  case RISCV::BI__builtin_riscv_ctz_32:
-  case RISCV::BI__builtin_riscv_ctz_64:
   case RISCV::BI__builtin_riscv_clmul_32:
   case RISCV::BI__builtin_riscv_clmul_64:
   case RISCV::BI__builtin_riscv_clmulh_32:
@@ -22423,24 +22419,6 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
 case RISCV::BI__builtin_riscv_orc_b_64:
   ID = Intrinsic::riscv_orc_b;
   break;
-case RISCV::BI__builtin_riscv_clz_32:
-case RISCV::BI__builtin_riscv_clz_64: {
-  Function *F = CGM.getIntrinsic(Intrinsic::ctlz, Ops[0]->getType());
-  Value *Result = Builder.CreateCall(F, {Ops[0], Builder.getInt1(false)});
-  if (Result->getType() != ResultType)
-Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
-   "cast");
-  return Result;
-}
-case RISCV::BI__builtin_riscv_ctz_32:
-case RISCV::BI__builtin_riscv_ctz_64: {
-  Function *F = CGM.getIntrinsic(Intrinsic::cttz, Ops[0]->getType());
-  Value *Result = Builder.CreateCall(F, {Ops[0], Builder.getInt1(false)});
-  if (Result->getType() != ResultType)
-Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
-   "cast");
-  return Result;
-}
 
 // Zbc
 case RISCV::BI__builtin_riscv_clmul_32:
@@ -22515,6 +22493,25 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
 ID = Intrinsic::riscv_sm3p1;
 break;
 
+  case RISCV::BI__builtin_riscv_clz_32:
+  case RISCV::BI__builtin_riscv_clz_64: {
+Function *F = CGM.getIntrinsic(Intrinsic::ctlz, Ops[0]->getType());
+Value *Result = Builder.CreateCall(F, {Ops[0], Builder.getInt1(false)});
+if (Result->getType() != ResultType)
+  Result =
+  Builder.CreateIntCast(Result, ResultType, /*isSigned*/ false, 
"cast");
+return Result;
+  }
+  case RISCV::BI__builtin_riscv_ctz_32:
+  case RISCV::BI__builtin_riscv_ctz_64: {
+Function *F = CGM.getIntrinsic(Intrinsic::cttz, Ops[0]->getType());
+Value *Result = Builder.CreateCall(F, {Ops[0], Builder.getInt1(false)});
+if (Result->getType() != ResultType)
+  Result =
+  Builder.CreateIntCast(Result, ResultType, /*isSigned*/ false, 
"cast");
+return Result;
+  }
+
   // Zihintntl
   case RISCV::BI__builtin_riscv_ntl_load: {
 llvm::Type *ResTy = ConvertType(E->getType());



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


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-10-31 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd created 
https://github.com/llvm/llvm-project/pull/114435

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

>From ebbb513f4f938c8d17a21b6061a815ffc7d8b004 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 31 Oct 2024 16:09:30 +
Subject: [PATCH] [PS5][Driver] Pass layout metrics to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add them
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 14 --
 clang/test/Driver/ps5-linker.c | 18 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-31 Thread via cfe-commits

yonghong-song wrote:

I remembered I mentioned earlier that for __ATOMIC_RELAXED, we should just use 
plain load/store. But I have the following example,

```
[yhs@devbig309.ftw3 ~/tmp4]$ cat atomic.c
long bar(unsigned char *ptr) {
return __atomic_load_n(ptr, __ATOMIC_RELAXED);
}
$ llvm-objdump -d atomic.o

atomic.o:   file format elf64-bpf

Disassembly of section .text:

 :
   0:   d3 10 00 00 12 00 00 00 w0 = load_acquire((u8 *)(r1 + 0x0))
   1:   95 00 00 00 00 00 00 00 exit
$
```

For fetch_and_*() operations if it is __ATOMIC_RELAXED, the code will be 
different from other atomic flavor.
I think for load_acquire and store_release case, we should not use 
load_acquire/store_release if it is __ATOMIC_RELAXED, and should just use plain 
load and store.

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


[clang] [Clang][SYCL] Introduce clang-sycl-linker to link SYCL offloading device code (Part 1 of many) (PR #112245)

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

llvm-ci wrote:

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

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86759 tests, 88 workers --
Testing:  0.. 10
FAIL: Clang :: Driver/clang-sycl-linker-test.cpp (10605 of 86759)
 TEST 'Clang :: Driver/clang-sycl-linker-test.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 4: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang 
--driver-mode=g++ -emit-llvm -c 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
+ /home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang 
--driver-mode=g++ -emit-llvm -c 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
RUN: at line 5: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang 
--driver-mode=g++ -emit-llvm -c 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
+ /home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang 
--driver-mode=g++ -emit-llvm -c 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
RUN: at line 6: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang-sycl-linker
 --dry-run -triple spirv64 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 -o a.spv 2>&1| 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/clang/test/Driver/clang-sycl-linker-test.cpp
 --check-prefix=SIMPLE
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang-sycl-linker
 --dry-run -triple spirv64 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 
/home/b/sanitizer-x86_64-linux-b

[clang] [HLSL][NFC] Cleanup - removed unused function, includes and param, fix typos (PR #113649)

2024-10-31 Thread Finn Plummer via cfe-commits

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


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


[clang] [Clang][Sema] Always use latest redeclaration of primary template (PR #114258)

2024-10-31 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

> Yup, that fixes the issue. I've also confirmed that reverting the fix brings 
> back the crash!

Great!

> It is weird that you were unable to repro this 🤔 (or rather that it was also 
> crashing when you reverted the original patch...) Are you 100% sure you 
> recompiled LLDB after reverting?

So... I usually compile clang with msvc on windows (I would use clang-cl if 
VS2022 didn't hang when debugging). I've spent many hours trying to get LLDB to 
compile using my current environment without success, so I instead compile in 
WSL. Since 
`lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py`
 is unsupported on Linux, I just commented out `@skipIfLinux` so the test will 
at least run. The test fails for me locally, but when the patch is applied it 
doesn't crash.

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-31 Thread Peilin Ye via cfe-commits

peilin-ye wrote:

Sure Yonghong, I can include that in this PR.  Similarly, since we cannot have 
both `relaxed_load` and 
`relaxed_load`, I'll keep it `zext` (`BPF_MEM` | 
`BPF_LDX`) for now.  For example:
```c
int foo(char *ptr) {
return __atomic_load_n(ptr, __ATOMIC_RELAXED);
}
```
This'll be compiled into:
```
 :
   0:   71 11 00 00 00 00 00 00 w1 = *(u8 *)(r1 + 0x0)
   1:   bc 10 08 00 00 00 00 00 w0 = (s8)w1
   2:   95 00 00 00 00 00 00 00 exit
```


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


[clang] [llvm] [X86][AMX] Support AMX-TRANSPOSE (PR #113532)

2024-10-31 Thread Feng Zou via cfe-commits


@@ -0,0 +1,248 @@
+/* ===--- amxtransposeintrin.h - AMX_TRANSPOSE intrinsics -*- C++ 
-*-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ * 
===---===
+ */
+
+#ifndef __IMMINTRIN_H
+#error "Never use  directly; use  instead."
+#endif /* __IMMINTRIN_H */
+
+#ifndef __AMX_TRANSPOSEINTRIN_H
+#define __AMX_TRANSPOSEINTRIN_H
+#ifdef __x86_64__
+
+#define __DEFAULT_FN_ATTRS_TRANSPOSE   
\
+  __attribute__((__always_inline__, __nodebug__, __target__("amx-transpose")))
+
+#define _tile_2rpntlvwz0(tdst, base, stride)   
\
+  __builtin_ia32_t2rpntlvwz0(tdst, base, stride)
+#define _tile_2rpntlvwz0t1(tdst, base, stride) 
\
+  __builtin_ia32_t2rpntlvwz0t1(tdst, base, stride)
+#define _tile_2rpntlvwz1(tdst, base, stride)   
\
+  __builtin_ia32_t2rpntlvwz1(tdst, base, stride)
+#define _tile_2rpntlvwz1t1(tdst, base, stride) 
\
+  __builtin_ia32_t2rpntlvwz1t1(tdst, base, stride)
+
+/// Transpose 32-bit elements from \a src and write the result to \a dst.
+///
+/// \headerfile 
+///
+/// \code
+/// void __tile_transposed(__tile dst, __tile src);

fzou1 wrote:

Remove extra underline: __tile_transposed -> _tile_transposed.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -53,6 +53,7 @@ class CIRGenerator : public clang::ASTConsumer {
   ~CIRGenerator() override;
   void Initialize(clang::ASTContext &astCtx) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
+  mlir::ModuleOp getModule();

erichkeane wrote:

slightly suspicious about the name 'get module' (like the problems we have with 
`get context` everywhere in clang being ambiguous).  But willing to see what 
others have to say.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}
+
+mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
+  assert(cRange.isValid() && "expected a valid source range");
+  mlir::Location begin = getLoc(cRange.getBegin());
+  mlir::Location end = getLoc(cRange.getEnd());
+  SmallVector locs = {begin, end};
+  mlir::Attribute metadata;
+  return mlir::FusedLoc::get(locs, metadata, builder.getContext());
+}
+
+void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
+  const auto *global = cast(gd.getDecl());
+
+  if (const auto *fd = dyn_cast(global)) {
+// Update deferred annotations with the latest declaration if the function
+// was already used or defined.
+if (fd->hasAttr()) {
+  errorNYI(fd->getSourceRange(), "defferedAnnotations");
+}
+if (!fd->doesThisDeclarationHaveABody()) {
+  if (!fd->doesDeclarationForceExternallyVisibleDefinition())
+return;
+
+  errorNYI(fd->getSourceRange(),
+   "function declaration that forces code gen");
+  return;
+}
+  } else {
+errorNYI(global->getSourceRange(), "global variable declaration");
+  }
+
+  // TODO(CIR): Defer emitting some global definitions until later
+  buildGlobalDefinition(gd);
+}
+
+void CIRGenModule::buildGlobalFunctionDefinition(clang::GlobalDecl gd,
+ mlir::Operation *op) {
+  auto const *funcDecl = cast(gd.getDecl());
+  auto funcOp = builder.create(
+  getLoc(funcDecl->getSourceRange()), 
funcDecl->getIdentifier()->getName());
+  theModule.push_back(funcOp);
+}
+
+void CIRGenModule::buildGlobalDefinition(clang::GlobalDecl gd,
+ mlir::Operation *op) {
+  const auto *decl = cast(gd.getDecl());
+  if (const auto *fd = dyn_cast(decl)) {
+// TODO(CIR): Skip generation of CIR for functions with 
available_externally
+// linkage at -O0.
+
+if (const auto *method = dyn_cast(decl)) {
+  // Make sure to emit the definition(s) before we emit the thunks. This is
+  // necessary for the generation of certain thunks.
+  (void)method;
+  errorNYI(method->getSourceRange(), "member function");
+  return;
+}
+
+if (fd->isMultiVersion())
+  errorNYI(fd->getSourceRange(), "multiversion functions");
+buildGlobalFunctionDefinition(gd, op);
+return;
+  }
+
+  llvm_unreachable("Invalid argument to CIRGenModule::buildGlobalDefinition");
+}
 
 // Emit code for a single top level declaration.
-void CIRGenModule::buildTopLevelDecl(Decl *decl) {}
+void CIRGenModule::buildTopLevelDecl(Decl *decl) {
+
+  // Ignore dependent declarations.
+  if (decl->isTemplated())
+return;
+
+  switch (decl->getKind()) {
+  default:
+errorNYI(decl->getBeginLoc(), "declaration of kind",
+ decl->getDeclKindName());
+break;
+
+  case Decl::Function: {
+auto *fd = cast(decl);
+// Consteval functions shouldn't be emitted.
+if (!fd->isConsteval())
+  buildGlobal(fd);
+break;
+  }
+  }
+}
+
+DiagnosticBuilder CIRGenModule::errorNYI(llvm::StringRef feature) {
+  unsigned diagID = diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "ClangIR code gen NYI: %0");

erichkeane wrote:

```suggestion
  "ClangIR code gen Not Yet 
Implemented: %0");
```

Same for the rest here, I'd prefer we are better about this for user/early 
adopter readability.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}
+
+mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
+  assert(cRange.isValid() && "expected a valid source range");
+  mlir::Location begin = getLoc(cRange.getBegin());
+  mlir::Location end = getLoc(cRange.getEnd());
+  SmallVector locs = {begin, end};

erichkeane wrote:

I'd suggest just using an init-list for the locs on line 49 if possible.  it 
takes an ArrayRef, so anything 'array like' should work fine.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -10,4 +10,57 @@
 //
 
//===--===//
 
-#include 
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+
+#include "mlir/Support/LogicalResult.h"
+
+#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"

erichkeane wrote:

Alphabetization concerns again.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -16,4 +16,87 @@
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
 
+include "mlir/Interfaces/ControlFlowInterfaces.td"
+include "mlir/Interfaces/FunctionInterfaces.td"
+include "mlir/Interfaces/InferTypeOpInterface.td"
+include "mlir/Interfaces/LoopLikeInterface.td"
+include "mlir/Interfaces/MemorySlotInterfaces.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
+
+include "mlir/IR/BuiltinAttributeInterfaces.td"

erichkeane wrote:

opposite alphabetism selected here.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -13,4 +13,22 @@
 #ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 #define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/OpDefinition.h"
+#include "mlir/Interfaces/CallInterfaces.h"
+#include "mlir/Interfaces/ControlFlowInterfaces.h"
+#include "mlir/Interfaces/FunctionInterfaces.h"
+#include "mlir/Interfaces/InferTypeOpInterface.h"
+#include "mlir/Interfaces/LoopLikeInterface.h"
+#include "mlir/Interfaces/MemorySlotInterfaces.h"
+#include "mlir/Interfaces/SideEffectInterfaces.h"
+
+#include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
+
+#define GET_OP_CLASSES

erichkeane wrote:

Can you explain what this means/does?  It isn't clear to me.  Also, REALLY 
generic name for something that should be CIR specific.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}
+
+mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
+  assert(cRange.isValid() && "expected a valid source range");
+  mlir::Location begin = getLoc(cRange.getBegin());
+  mlir::Location end = getLoc(cRange.getEnd());
+  SmallVector locs = {begin, end};
+  mlir::Attribute metadata;
+  return mlir::FusedLoc::get(locs, metadata, builder.getContext());
+}
+
+void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
+  const auto *global = cast(gd.getDecl());
+
+  if (const auto *fd = dyn_cast(global)) {
+// Update deferred annotations with the latest declaration if the function
+// was already used or defined.
+if (fd->hasAttr()) {
+  errorNYI(fd->getSourceRange(), "defferedAnnotations");
+}
+if (!fd->doesThisDeclarationHaveABody()) {

erichkeane wrote:

Should we make sure we're looking at the 'latest' declaration before we ask 
this?  You could otherwise get the 'canonical' declaration (or a first, etc, if 
the body of the referring declrefexpr was formed before the definition exists) 
that doesn't have a definition, despite it being defined later.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -13,4 +13,22 @@
 #ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 #define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
 
+#include "mlir/IR/Builders.h"

erichkeane wrote:

These should be alphabetical, but IDK if capitalization is considered?  But by 
pure alphabetism, `Interfaces` should be before `IR`.



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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}
+
+mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
+  assert(cRange.isValid() && "expected a valid source range");
+  mlir::Location begin = getLoc(cRange.getBegin());
+  mlir::Location end = getLoc(cRange.getEnd());
+  SmallVector locs = {begin, end};
+  mlir::Attribute metadata;
+  return mlir::FusedLoc::get(locs, metadata, builder.getContext());
+}
+
+void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
+  const auto *global = cast(gd.getDecl());
+
+  if (const auto *fd = dyn_cast(global)) {
+// Update deferred annotations with the latest declaration if the function
+// was already used or defined.
+if (fd->hasAttr()) {
+  errorNYI(fd->getSourceRange(), "defferedAnnotations");
+}
+if (!fd->doesThisDeclarationHaveABody()) {
+  if (!fd->doesDeclarationForceExternallyVisibleDefinition())
+return;
+
+  errorNYI(fd->getSourceRange(),
+   "function declaration that forces code gen");
+  return;
+}
+  } else {
+errorNYI(global->getSourceRange(), "global variable declaration");
+  }
+
+  // TODO(CIR): Defer emitting some global definitions until later
+  buildGlobalDefinition(gd);
+}
+
+void CIRGenModule::buildGlobalFunctionDefinition(clang::GlobalDecl gd,
+ mlir::Operation *op) {
+  auto const *funcDecl = cast(gd.getDecl());
+  auto funcOp = builder.create(

erichkeane wrote:

This is called `buildGlobalFunctionDefinition`, but never looks a the 
definition?  Is this intended to be just for 'defined' functions, or do we mean 
declaration?

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


[clang] [clang][bytecode] Add more checks to _ai32_* builtins (PR #114412)

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

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

>From 946f978b15746b3e1561d4e9001a0cd966315959 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 31 Oct 2024 16:00:31 +0100
Subject: [PATCH] [clang][bytecode] Add more checks to _ai32_* builtins

They are called in a few different forms that we don't support.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 15 +--
 clang/test/CodeGen/builtins-hexagon.c|  1 +
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b00d2a1768b6b7..2bffe43212a4a4 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1253,7 +1253,7 @@ static bool interp__builtin_ia32_bextr(InterpState &S, 
CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
-  if (!Call->getArg(0)->getType()->isIntegerType() ||
+  if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() 
||
   !Call->getArg(1)->getType()->isIntegerType())
 return false;
 
@@ -1285,7 +1285,9 @@ static bool interp__builtin_ia32_bzhi(InterpState &S, 
CodePtr OpPC,
   const Function *Func,
   const CallExpr *Call) {
   QualType CallType = Call->getType();
-  if (!CallType->isIntegerType())
+  if (Call->getNumArgs() != 0 || !Call->getArg(0)->getType()->isIntegerType() 
||
+  !Call->getArg(1)->getType()->isIntegerType() ||
+  !CallType->isIntegerType())
 return false;
 
   PrimType ValT = *S.Ctx.classify(Call->getArg(0));
@@ -1310,7 +1312,7 @@ static bool interp__builtin_ia32_lzcnt(InterpState &S, 
CodePtr OpPC,
const Function *Func,
const CallExpr *Call) {
   QualType CallType = Call->getType();
-  if (!CallType->isIntegerType())
+  if (!CallType->isIntegerType() || 
!Call->getArg(0)->getType()->isIntegerType())
 return false;
 
   APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1323,7 +1325,8 @@ static bool interp__builtin_ia32_tzcnt(InterpState &S, 
CodePtr OpPC,
const Function *Func,
const CallExpr *Call) {
   QualType CallType = Call->getType();
-  if (!CallType->isIntegerType())
+  if (!CallType->isIntegerType() ||
+  !Call->getArg(0)->getType()->isIntegerType())
 return false;
 
   APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1335,7 +1338,7 @@ static bool interp__builtin_ia32_pdep(InterpState &S, 
CodePtr OpPC,
   const InterpFrame *Frame,
   const Function *Func,
   const CallExpr *Call) {
-  if (!Call->getArg(0)->getType()->isIntegerType() ||
+  if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() 
||
   !Call->getArg(1)->getType()->isIntegerType())
 return false;
 
@@ -1360,7 +1363,7 @@ static bool interp__builtin_ia32_pext(InterpState &S, 
CodePtr OpPC,
   const InterpFrame *Frame,
   const Function *Func,
   const CallExpr *Call) {
-  if (!Call->getArg(0)->getType()->isIntegerType() ||
+  if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() 
||
   !Call->getArg(1)->getType()->isIntegerType())
 return false;
 
diff --git a/clang/test/CodeGen/builtins-hexagon.c 
b/clang/test/CodeGen/builtins-hexagon.c
index 52073f27ae70f5..9040a779926b27 100644
--- a/clang/test/CodeGen/builtins-hexagon.c
+++ b/clang/test/CodeGen/builtins-hexagon.c
@@ -1,5 +1,6 @@
 // REQUIRES: hexagon-registered-target
 // RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 
-target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 
-target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - 
-fexperimental-new-constant-interpreter | FileCheck %s
 
 void test() {
   int v64 __attribute__((__vector_size__(64)));

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


[clang] Initialize SmallVector variable (PR #114434)

2024-10-31 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

Since `SmallVector DeviceLibFiles;` is default initialized to an 
empty vector,
this change seems unnecessary.

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


[clang] [Clang][Sema] Always use latest redeclaration of primary template (PR #114258)

2024-10-31 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@felipepiovezan I tested without this patch applied and was still seeing 
crashes... could you perhaps see if 
https://github.com/sdkrystian/llvm-project/tree/reapply-use-latest-primary 
fixes the regression?

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


[clang] [clang][bytecode] Diagnose delete with non-virtual dtor (PR #114373)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... in the base class.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.cpp (+18) 
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+10) 


``diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 513d4512b45cff..3094d7986f9986 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1002,6 +1002,13 @@ static bool RunDestructors(InterpState &S, CodePtr OpPC, 
const Block *B) {
   return runRecordDestructor(S, OpPC, Pointer(const_cast(B)), Desc);
 }
 
+static bool hasVirtualDestructor(QualType T) {
+  if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
+if (const CXXDestructorDecl *DD = RD->getDestructor())
+  return DD->isVirtual();
+  return false;
+}
+
 bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
   bool IsGlobalDelete) {
   if (!CheckDynamicMemoryAllocation(S, OpPC))
@@ -1019,9 +1026,20 @@ bool Free(InterpState &S, CodePtr OpPC, bool 
DeleteIsArrayForm,
   return true;
 
 // Remove base casts.
+QualType InitialType = Ptr.getType();
 while (Ptr.isBaseClass())
   Ptr = Ptr.getBase();
 
+// For the non-array case, the types must match if the static type
+// does not have a virtual destructor.
+if (!DeleteIsArrayForm && Ptr.getType() != InitialType &&
+!hasVirtualDestructor(InitialType)) {
+  S.FFDiag(S.Current->getSource(OpPC),
+   diag::note_constexpr_delete_base_nonvirt_dtor)
+  << InitialType << Ptr.getType();
+  return false;
+}
+
 if (!Ptr.isRoot() || Ptr.isOnePastEnd() || Ptr.isArrayElement()) {
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   S.FFDiag(Loc, diag::note_constexpr_delete_subobject)
diff --git a/clang/test/AST/ByteCode/new-delete.cpp 
b/clang/test/AST/ByteCode/new-delete.cpp
index 94fe2d4497df6a..31c8da93a3a643 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -569,6 +569,16 @@ namespace CastedDelete {
 return a;
   }
   static_assert(vdtor_1() == 1);
+
+  constexpr int foo() { // both-error {{never produces a constant expression}}
+  struct S {};
+  struct T : S {};
+  S *p = new T();
+  delete p; // both-note 2{{delete of object with dynamic type 'T' through 
pointer to base class type 'S' with non-virtual destructor}}
+  return 1;
+  }
+  static_assert(foo() == 1); // both-error {{not an integral constant 
expression}} \
+ // both-note {{in call to}}
 }
 
 constexpr void use_after_free_2() { // both-error {{never produces a constant 
expression}}

``




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


[clang-tools-extra] [clang-tidy] support `return c ? a : b;` in bugprone-return-const-ref-from-parameter (PR #107657)

2024-10-31 Thread Julian Schmidt via cfe-commits

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread David Olsen via cfe-commits

dkolsen-pgi wrote:

> Is it at all possible to write a test to exercise the new functionality,

Yes, The change that I just committed includes updating the existing test to 
verify that a `cir.func` op is generated correctly.


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


[clang-tools-extra] Add bugprone-sprintf-overlap (PR #114244)

2024-10-31 Thread via cfe-commits


@@ -0,0 +1,23 @@
+.. title:: clang-tidy - bugprone-undefined-sprintf-overlap
+
+bugprone-undefined-sprintf-overlap
+==
+
+Warns if any arguments to the sprintf family of functions overlap with the

EugeneZelenko wrote:

Please synchronize with statement in Release Notes.

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


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

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


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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)

2024-10-31 Thread Helena Kotas via cfe-commits


@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder {
 S.Context, Builder.Record->getDeclContext(), SourceLocation(),
 SourceLocation(), /* TemplateDepth */ 0, Position,
 &S.Context.Idents.get(Name, tok::TokenKind::identifier),
-/* Typename */ false,
-/* ParameterPack */ false);
+/* Typename */ true,
+/* ParameterPack */ false,
+/* HasTypeConstraint*/ false);
 if (!DefaultValue.isNull())
   Decl->setDefaultArgument(
   S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(),
  SourceLocation()));
-
+Decl->setReferenced();

hekota wrote:

`referenced' means the declaration is referenced/used somewhere in the source 
code, you should not be setting it here.

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


[clang] Initialize SmallVector variable (PR #114434)

2024-10-31 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 commented:

A default constructed vector should just be empty, I don't think it would cause 
the issue the sanitizer is seeing.

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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -53,6 +53,7 @@ class CIRGenerator : public clang::ASTConsumer {
   ~CIRGenerator() override;
   void Initialize(clang::ASTContext &astCtx) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
+  mlir::ModuleOp getModule();

erichkeane wrote:

Ok, that seems fair.  We definitely have a few places where `getContext` means 
something ambiguous, so wanted to make sure this WOULDN'T be.  


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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread David Olsen via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}

dkolsen-pgi wrote:

I am guessing that the MLIR location type doesn't have any notion of multiple 
nested locations due to macro expansions.  So we can't represent the full 
complexity of macros here.  The outermost location seems like the right one to 
choose.  (I am not familiar with either the Clang location type or the MLIR 
location type, so I welcome being corrected here.)


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


[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)

2024-10-31 Thread Erich Keane via cfe-commits


@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
-  target(astCtx.getTargetInfo()) {}
+: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+  diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+  assert(cLoc.isValid() && "expected valid source location");
+  const SourceManager &sm = astCtx.getSourceManager();
+  PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+  StringRef filename = pLoc.getFilename();
+  return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+   pLoc.getLine(), pLoc.getColumn());
+}

erichkeane wrote:

I'll leave this open for Aaron to comment on.  IIRC, the source location stored 
in the AST is going to be the location of the macro, which can make diagnostics 
awkward/confusing if what happens is inside the expansion, but if MLIR can't 
comprehend "in expansion of..." then this is perhaps as good as we can do.

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


  1   2   3   4   5   6   >