[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-11-21 Thread Chris White via cfe-commits

whiteio wrote:

I'll update my changes to fix the other tests that are failing this evening, 
sorry about that, should have ran the rest of them after making the change.

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


[clang] [Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments (PR #114684)

2024-11-21 Thread Haojian Wu via cfe-commits


@@ -32,6 +32,25 @@ void test_invalid_call(int s) {
   int var = some_func(undef1);
 }
 
+int some_func2(int a, int b);
+void test_invalid_call_2() {
+  // CHECK:   -RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '' 
lvalue (ADL) = 'some_func2'
+  some_func2(,);
+
+  // CHECK:   -RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '' 
lvalue (ADL) = 'some_func2'
+  some_func2(,,);
+
+  // CHECK:   `-RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '' 
lvalue (ADL) = 'some_func2'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  some_func2(1,);
+
+  // CHECK-NOT: `-RecoveryExpr

hokein wrote:

nit: maybe add a `FIXME: recover for this case`, otherwise it is unclear 
whether `CEHCK-NOT` is intended or not.

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


[clang] [Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments (PR #114684)

2024-11-21 Thread Haojian Wu via cfe-commits

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

Thanks, looks good.

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


[clang] [Clang] eliminate shadowing warnings for parameters using deducing this (PR #114813)

2024-11-21 Thread via cfe-commits

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


[clang] [llvm] Adjust MSVC disabled optimization pragmas to be _MSC_VER only (PR #116704)

2024-11-21 Thread Simon Pilgrim via cfe-commits

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


[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-x86_64-debian` 
running on `lldb-x86_64-debian` while building `clang-tools-extra,clang` at 
step 4 "build".

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


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

```
Step 4 (build) failure: build (failure)

```



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


[clang] [llvm] Adjust MSVC disabled optimization pragmas to be _MSC_VER only (PR #116704)

2024-11-21 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon updated 
https://github.com/llvm/llvm-project/pull/116704

>From 5eed16e1a10b3d078252791c6eb95c9c74585acf Mon Sep 17 00:00:00 2001
From: Simon Pilgrim 
Date: Mon, 18 Nov 2024 22:30:53 +
Subject: [PATCH] Adjust MSVC disabled optimization pragmas to be _MSC_VER only

Alter the #ifdef values from #110986 and #115292 to use _MSC_VER instead of 
_WIN32 to stop the pragmas being used on gcc/mingw builds

Noticed by @mstorsjo
---
 clang/lib/AST/ByteCode/Interp.cpp   | 4 ++--
 llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 339af0c873a8e4..1d2b5301ecd73b 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1588,7 +1588,7 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, bool 
HasIndeterminateBits,
 }
 
 // https://github.com/llvm/llvm-project/issues/102513
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma optimize("", off)
 #endif
 bool Interpret(InterpState &S, APValue &Result) {
@@ -1616,7 +1616,7 @@ bool Interpret(InterpState &S, APValue &Result) {
   }
 }
 // https://github.com/llvm/llvm-project/issues/102513
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma optimize("", on)
 #endif
 
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 10dad7675f4eaf..8512fd9ae40172 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -32,7 +32,7 @@ using namespace llvm;
 #define PASS_NAME "AArch64 Instruction Selection"
 
 // https://github.com/llvm/llvm-project/issues/114425
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma inline_depth(0)
 #endif
 

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


[clang] [llvm] Adjust MSVC disabled optimization pragmas to be _MSC_VER only (PR #116704)

2024-11-21 Thread Martin Storsjö via cfe-commits

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

LGTM, thanks!

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


[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`cross-project-tests-sie-ubuntu-dwarf5` running on `doug-worker-1b` while 
building `clang-tools-extra,clang` at step 5 "build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
244.189 [120/8/86] Linking CXX shared library lib/libLTO.so.20.0git
244.206 [119/8/87] Creating library symlink lib/libLTO.so
244.881 [118/8/88] Linking CXX executable bin/llvm-profdata
245.180 [117/8/89] Linking CXX static library lib/libclangBasic.a
245.219 [116/8/90] Linking CXX static library lib/liblldbVersion.a
245.621 [115/8/91] Linking CXX executable bin/llvm-lto
245.770 [114/8/92] Linking CXX executable bin/apinotes-test
245.928 [113/8/93] Linking CXX static library lib/libclangFrontend.a
246.467 [112/8/94] Linking CXX executable bin/clang-offload-bundler
246.601 [111/8/95] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
FAILED: 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 
/opt/ccache/bin/g++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/source/Commands
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Commands
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/include
 -I/usr/include/python3.10 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/../clang/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/../clang/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/source
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic 
-Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull 
-Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move 
-Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-unknown-pragmas -Wno-strict-aliasing 
-Wno-stringop-truncation -O3 -DNDEBUG  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -std=c++17 -MD -MT 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -MF 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o.d
 -o 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -c 
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:
 In member function ‘virtual void 
CommandObjectTargetModulesDumpClangPCMInfo::DoExecute(lldb_private::Args&, 
lldb_private::CommandReturnObject&)’:
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:2203:31:
 error: no matching function for call to 
‘clang::CompilerInstance::createDiagnostics()’
 2203 | compiler.createDiagnostics();
  | ~~^~
In file included from 
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:62:
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:687:8:
 note: candidate: ‘void 
clang::CompilerInstance::createDiagnostics(llvm::vfs::FileSystem&, 
clang::DiagnosticConsumer*, bool)’
  687 |   void createDiagnostics(llvm::vfs::FileSystem &VFS,
  |^
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:687:8:
 note:   candidate expects 3 arguments, 0 provided
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:710:3:
 note: candidate: ‘static llvm::IntrusiveRefCntPtr 
clang::CompilerInstance::createDiagnostics(llvm::

[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`cross-project-tests-sie-ubuntu` running on `doug-worker-1a` while building 
`clang-tools-extra,clang` at step 5 "build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
277.254 [120/8/86] Creating library symlink lib/libLTO.so
277.993 [119/8/87] Linking CXX executable bin/llvm-profdata
278.283 [118/8/88] Linking CXX static library lib/libclangBasic.a
278.298 [117/8/89] Linking CXX static library lib/liblldbVersion.a
278.486 [116/8/90] Linking CXX static library lib/libclangFrontend.a
278.548 [115/8/91] Linking CXX static library lib/libclangInstallAPI.a
279.170 [114/8/92] Linking CXX static library lib/libclangCodeGen.a
279.222 [113/8/93] Linking CXX static library lib/libclangRewriteFrontend.a
279.314 [112/8/94] Linking CXX static library lib/libclangTooling.a
279.326 [111/8/95] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
FAILED: 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 
/opt/ccache/bin/g++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/tools/lldb/source/Commands
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/source/Commands
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/tools/lldb/include
 -I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/include 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/include
 -I/usr/include/python3.8 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../clang/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/tools/lldb/../clang/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/source
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/tools/lldb/source
 -isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move 
-Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor 
-Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-unknown-pragmas -Wno-strict-aliasing 
-Wno-stringop-truncation -O3 -DNDEBUG  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -std=c++17 -MD -MT 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -MF 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o.d
 -o 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -c 
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:
 In member function ‘virtual void 
CommandObjectTargetModulesDumpClangPCMInfo::DoExecute(lldb_private::Args&, 
lldb_private::CommandReturnObject&)’:
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:2203:32:
 error: no matching function for call to 
‘clang::CompilerInstance::createDiagnostics()’
 2203 | compiler.createDiagnostics();
  |^
In file included from 
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:62:
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:687:8:
 note: candidate: ‘void 
clang::CompilerInstance::createDiagnostics(llvm::vfs::FileSystem&, 
clang::DiagnosticConsumer*, bool)’
  687 |   void createDiagnostics(llvm::vfs::FileSystem &VFS,
  |^
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:687:8:
 note:   candidate expects 3 arguments, 0 provided
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:710:3:
 note: candidate: ‘static llvm::IntrusiveRefCntPtr 
clang::CompilerInstance::createDiagnostics(llvm::vfs::FileSystem&, 
clang::DiagnosticOptions*, clang::DiagnosticConsumer*, bool, const 
clang

[clang] [Clang] eliminate shadowing warnings for parameters using deducing this (PR #114813)

2024-11-21 Thread Oleksandr T. via cfe-commits

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

>From 91ff2b4226110ea35c78f0f1b6ff89b4bec2c788 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 4 Nov 2024 17:38:46 +0200
Subject: [PATCH 1/5] [Clang] eliminate shadowing warnings for parameters using
 deducing this

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaDecl.cpp  |  7 +--
 clang/test/SemaCXX/cxx2b-warn-shadow.cpp | 10 ++
 3 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx2b-warn-shadow.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1372e49dfac03c..af8288ee8a8296 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,6 +464,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits shadowing warnings for parameter names using deducing this 
(#GH95707).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1aa3e8edfe1b13..38b07b15eb3eb2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8236,11 +8236,14 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   DeclContext *NewDC = D->getDeclContext();
 
   if (FieldDecl *FD = dyn_cast(ShadowedDecl)) {
-// Fields are not shadowed by variables in C++ static methods.
-if (CXXMethodDecl *MD = dyn_cast(NewDC))
+if (CXXMethodDecl *MD = dyn_cast(NewDC)) {
+  // Fields are not shadowed by variables in C++ static methods.
   if (MD->isStatic())
 return;
 
+  if (!MD->getParent()->isLambda() && MD->isExplicitObjectMemberFunction())
+return;
+}
 // Fields shadowed by constructor parameters are a special case. Usually
 // the constructor initializes the field with the parameter.
 if (isa(NewDC))
diff --git a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp 
b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
new file mode 100644
index 00..0cf47f3848979c
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2b -Wshadow-all %s
+
+namespace GH95707 {
+struct Foo {
+  int a; // expected-note {{previous declaration is here}}
+
+  void f1(this auto &self, int a) { self.a = a; }
+  void f2(int a) { } // expected-warning {{declaration shadows a field of 
'GH95707::Foo'}}
+};
+} // namespace GH95707

>From 849515a74f1c82845b0baa100729aa80bf236f66 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 5 Nov 2024 15:33:14 +0200
Subject: [PATCH 2/5] update tests/release notes

---
 clang/docs/ReleaseNotes.rst  | 2 +-
 clang/test/SemaCXX/cxx2b-warn-shadow.cpp | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index af8288ee8a8296..5ecde32bb70429 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,7 +464,7 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
-- Clang now omits shadowing warnings for parameter names using deducing this 
(#GH95707).
+- Clang now omits shadowing warnings for parameter names in explicit object 
member functions (#GH95707).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp 
b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
index 0cf47f3848979c..19db49a4566fa7 100644
--- a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
+++ b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
@@ -6,5 +6,8 @@ struct Foo {
 
   void f1(this auto &self, int a) { self.a = a; }
   void f2(int a) { } // expected-warning {{declaration shadows a field of 
'GH95707::Foo'}}
+  void f3() {
+[&](this auto &self, int x) { }; // expected-warning {{expression result 
unused}}
+  }
 };
 } // namespace GH95707

>From 2a2cb900b090d4bb2f1e66c3e027cd947d8053c4 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 6 Nov 2024 12:18:00 +0200
Subject: [PATCH 3/5] remove unnesessary warning

---
 clang/test/SemaCXX/cxx2b-warn-shadow.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp 
b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
index 19db49a4566fa7..e6615e969910e2 100644
--- a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
+++ b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
@@ -7,7 +7,7 @@ struct Foo {
   void f1(this auto &self, int a) { self.a = a; }
   void f2(int a) { } // expected-warning {{declaration shadows a field of 
'GH95707::Foo'}}
   void f3() {
-[&](this auto &self, int x) { }; // expected-warning {{expression result 
unused}}
+(void)[&](this auto &self, int x) { };
   }
 };
 } // namespace GH95707

>From fa897f136484fedb96a2eb38e344611a363d415d Mon Sep 17 00:00:00

[clang] [Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments (PR #114684)

2024-11-21 Thread Oleksandr T. via cfe-commits

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

>From d95d0fdb22ae2ad162f89cb211f313cea6c6474a Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 2 Nov 2024 23:54:35 +0200
Subject: [PATCH 1/6] [Clang] enhance error recovery with RecoveryExpr for
 trailing commas in call arguments

---
 clang/lib/Parse/ParseExpr.cpp|  3 +++
 clang/test/AST/ast-dump-recovery.cpp | 17 -
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 4570a18bc0d5e5..5fccd2ae106015 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3705,6 +3705,9 @@ bool Parser::ParseExpressionList(SmallVectorImpl 
&Exprs,
 Token Comma = Tok;
 ConsumeToken();
 checkPotentialAngleBracketDelimiter(Comma);
+
+if (Tok.is(tok::r_paren))
+  break;
   }
   if (SawError) {
 // Ensure typos get diagnosed when errors were encountered while parsing 
the
diff --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index a88dff471d9f04..1876f4ace32a5a 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -9,7 +9,7 @@ int some_func(int *);
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
 // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
 int invalid_call = some_func(123);
-void test_invalid_call(int s) {
+void test_invalid_call_1(int s) {
   // CHECK:  CallExpr {{.*}} '' contains-errors
   // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
   // CHECK-NEXT: |-RecoveryExpr {{.*}} 
@@ -32,6 +32,21 @@ void test_invalid_call(int s) {
   int var = some_func(undef1);
 }
 
+int some_func2(int a, int b);
+void test_invalid_call_2() {
+  // CHECK:   `-RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '' 
lvalue (ADL) = 'some_func2'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  some_func2(1, );
+}
+
+void test_invalid_call_3() {
+  // CHECK:   `-RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '' 
lvalue (ADL) = 'some_func2'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  some_func2(1);
+}
+
 int ambig_func(double);
 int ambig_func(float);
 

>From 2b45d342c7e2327c525b681a0e4069132dcd430d Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 20 Nov 2024 11:47:13 +0200
Subject: [PATCH 2/6] explicity handle of trailing commas to improve recovery
 and ensure proper processing of prior erroneous expressions

---
 clang/include/clang/Parse/Parser.h   |  3 ++-
 clang/lib/Parse/ParseDecl.cpp|  5 +++--
 clang/lib/Parse/ParseExpr.cpp| 19 +++
 clang/test/AST/ast-dump-recovery.cpp | 11 ---
 4 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 045ee754a242b3..d3838a4cc8418c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1934,7 +1934,8 @@ class Parser : public CodeCompletionHandler {
llvm::function_ref ExpressionStarts =
llvm::function_ref(),
bool FailImmediatelyOnInvalidExpr = false,
-   bool EarlyTypoCorrection = false);
+   bool EarlyTypoCorrection = false,
+   bool *HasTrailingComma = nullptr);
 
   /// ParseSimpleExpressionList - A simple comma-separated list of expressions,
   /// used for misc language extensions.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index aa5c2d28d429ac..ae8611207b2609 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2890,8 +2890,9 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
   // ProduceConstructorSignatureHelp only on VarDecls.
   ExpressionStarts = SetPreferredType;
 }
-
-bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
+bool HasTrailingComma = false;
+bool SawError =
+ParseExpressionList(Exprs, ExpressionStarts, HasTrailingComma);
 
 if (SawError) {
   if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) 
{
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 5fccd2ae106015..736484ded8383c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2199,10 +2199,17 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
   };
   if (OpKind == tok::l_paren || !LHS.isInvalid()) {
 if (Tok.isNot(tok::r_paren)) {
-  if (ParseExpressionList(ArgExprs, [&] {
+  bool HasTrailingComma = false;
+  bool HasError = ParseExpressionList(
+  ArgExprs,
+  [&] {
 PreferredType.enterFunctionArgument(Tok.getLocation(),
 RunSignature

[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-x86_64-debian-dylib` 
running on `gribozavr4` while building `clang-tools-extra,clang` at step 5 
"build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
84.693 [142/31/6875] Linking CXX static library lib/libclangDoc.a
84.739 [141/31/6876] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/index/YAMLSerialization.cpp.o
84.945 [141/30/6877] Linking CXX executable bin/clang-doc
85.141 [141/29/6878] Building CXX object 
tools/clang/tools/extra/clangd/fuzzer/CMakeFiles/clangd-fuzzer.dir/clangd-fuzzer.cpp.o
85.416 [141/28/6879] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/index/StdLib.cpp.o
85.420 [141/27/6880] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/index/Serialization.cpp.o
86.351 [141/26/6881] Building CXX object 
tools/lldb/tools/lldb-instr/CMakeFiles/lldb-instr.dir/Instrument.cpp.o
86.372 [140/26/6882] Building CXX object 
tools/clang/tools/extra/clangd/index/dex/dexp/CMakeFiles/dexp.dir/Dexp.cpp.o
86.528 [140/25/6883] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/TUScheduler.cpp.o
86.547 [140/24/6884] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
FAILED: 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++ 
-DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/source/Commands 
-I/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source/Commands 
-I/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/include 
-I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/include 
-I/b/1/llvm-x86_64-debian-dylib/build/include 
-I/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/include 
-I/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/../clang/include 
-I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/../clang/include 
-I/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source 
-I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/source -isystem 
/usr/include/libxml2 -fPIC -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-unknown-pragmas -Wno-strict-aliasing 
-Wno-vla-extension -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti 
-UNDEBUG -std=c++17 -MD -MT 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -MF 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o.d
 -o 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -c 
/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:2203:14:
 error: no matching member function for call to 'createDiagnostics'
compiler.createDiagnostics();
~^
/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:687:8:
 note: candidate function not viable: requires at least argument 'VFS', but no 
arguments were provided
  void createDiagnostics(llvm::vfs::FileSystem &VFS,
   ^
/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/../clang/include/clang/Frontend/CompilerInstance.h:710:3:
 note: candidate function not viable: requires at least 2 arguments, but 0 were 
provided
  createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
  ^
1 error generated.
86.551 [140/23/6885] Building CXX object 
tools/clang/tools/extra/clangd/indexer/CMakeFiles/clangd-indexer.dir/IndexerMain.cpp.o
86.649 [140/22/6886] Linking CXX executable bin/lldb-instr
87.382 [140/21/6887] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/index/Background.cpp.o
87.967 [140/20/6888] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/index/SymbolCollector.cpp.o
88.821 [140/19/6889] Building CXX object 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/refactor/Rename.cpp.o
89.510 [140/18/6890] Building CXX object 
tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/RenamerClangTidyCheck.cpp.o
90.461 [140/17/6891] 

[clang] Fix redundant macro expansion checks in ASTMatchers (PR #117143)

2024-11-21 Thread via cfe-commits

https://github.com/mandymimi created 
https://github.com/llvm/llvm-project/pull/117143

A performance issue was descibed in #114521 

**Root Cause**: The function getExpansionLocOfMacro is responsible for finding 
the expansion location of macros. When dealing with macro parameters, it 
recursively calls itself to check the expansion of macro arguments. This 
recursive logic redundantly checks previous macro expansions, leading to 
significant performance degradation when macros are heavily nested.
Solution
**Modification**: Track already processed macros during recursion.
Implementation Details:
Introduced a data structure to record processed macros.
Before each recursive call, check if the macro has already been processed to 
avoid redundant calculations.
**Testing**: 
1. refer to #114521 
Finder->addMatcher(expr(isExpandedFromMacro("NULL")).bind("E"), this);
run clang-tidy on freecad/src/Mod/Path/App/AreaPyImp.cpp 
clang-tidy src/Mod/Path/App/AreaPyImp.cpp -checks=-*,testchecker 
-p=build/compile_commands.json 
checker runs normally
2. check-clang-unit pass

>From 9922502941d1a518ad596b18cb332a99178823a4 Mon Sep 17 00:00:00 2001
From: wangmi 
Date: Thu, 21 Nov 2024 11:25:35 +
Subject: [PATCH] Fix redundant macro expansion checks in ASTMatchers

---
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 84 ++-
 1 file changed, 61 insertions(+), 23 deletions(-)

diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 46dd44e6f2b24f..80eb82949831bc 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -136,7 +137,8 @@ class IdDynMatcher : public DynMatcherInterface {
   bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const override {
 bool Result = InnerMatcher->dynMatches(DynNode, Finder, Builder);
-if (Result) Builder->setBinding(ID, DynNode);
+if (Result)
+  Builder->setBinding(ID, DynNode);
 return Result;
   }
 
@@ -354,7 +356,8 @@ bool DynTypedMatcher::canConvertTo(ASTNodeKind To) const {
   auto TypeKind = ASTNodeKind::getFromNodeKind();
   /// Mimic the implicit conversions of Matcher<>.
   /// - From Matcher to Matcher
-  if (From.isSame(TypeKind) && To.isSame(QualKind)) return true;
+  if (From.isSame(TypeKind) && To.isSame(QualKind))
+return true;
   /// - From Matcher to Matcher
   return From.isBaseOf(To);
 }
@@ -440,8 +443,8 @@ optionallyVariadicOperator(const DynTypedNode &DynNode, 
ASTMatchFinder *Finder,
   return true;
 }
 
-inline static
-std::vector vectorFromRefs(ArrayRef NameRefs) {
+inline static std::vector
+vectorFromRefs(ArrayRef NameRefs) {
   std::vector Names;
   Names.reserve(NameRefs.size());
   for (auto *Name : NameRefs)
@@ -454,8 +457,8 @@ Matcher hasAnyNameFunc(ArrayRef NameRefs) {
   new internal::HasNameMatcher(vectorFromRefs(NameRefs)));
 }
 
-Matcher hasAnySelectorFunc(
-ArrayRef NameRefs) {
+Matcher
+hasAnySelectorFunc(ArrayRef NameRefs) {
   return hasAnySelectorMatcher(vectorFromRefs(NameRefs));
 }
 
@@ -697,27 +700,61 @@ static bool isTokenAtLoc(const SourceManager &SM, const 
LangOptions &LangOpts,
   return !Invalid && Text == TokenText;
 }
 
-std::optional
-getExpansionLocOfMacro(StringRef MacroName, SourceLocation Loc,
-   const ASTContext &Context) {
+namespace {
+struct SourceLocationHash {
+  std::size_t operator()(const SourceLocation &Loc) const {
+return Loc.getHashValue();
+  }
+};
+
+struct SourceLocationEqual {
+  bool operator()(const SourceLocation &LHS, const SourceLocation &RHS) const {
+return LHS == RHS;
+  }
+};
+
+} // namespace
+
+static std::optional getExpansionLocOfMacroRecursive(
+StringRef MacroName, SourceLocation Loc, const ASTContext &Context,
+std::unordered_set
+&CheckedLocations) {
   auto &SM = Context.getSourceManager();
   const LangOptions &LangOpts = Context.getLangOpts();
   while (Loc.isMacroID()) {
+if (CheckedLocations.count(Loc)) {
+  return std::nullopt;
+}
+CheckedLocations.insert(Loc);
 SrcMgr::ExpansionInfo Expansion =
 SM.getSLocEntry(SM.getFileID(Loc)).getExpansion();
-if (Expansion.isMacroArgExpansion())
+if (Expansion.isMacroArgExpansion()) {
   // Check macro argument for an expansion of the given macro. For example,
   // `F(G(3))`, where `MacroName` is `G`.
-  if (std::optional ArgLoc = getExpansionLocOfMacro(
-  MacroName, Expansion.getSpellingLoc(), Context))
+  if (std::optional ArgLoc =
+  getExpansionLocOfMacroRecursive(MacroName,
+  Expansion.getSpellingLoc(),
+  Context, CheckedLocations)) {
 return ArgLoc;
+  }
+}
 Loc = Expansion.getExpansionLocStart();
-   

[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-21 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@sdkrystian, can you, please, re-review this patch? It seems like I fixed your 
test

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


[clang] Fix redundant macro expansion checks in ASTMatchers (PR #117143)

2024-11-21 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above (PR #117149)

2024-11-21 Thread Dipesh Sharma via cfe-commits

https://github.com/dipeshs809 created 
https://github.com/llvm/llvm-project/pull/117149

Since `__STDC_NO_THREADS__` is a reserved identifier,
- If `MSVC version < 17.9`
- C version < C11(201112L)
- When `` is unavailable `!__has_include()` is 
`__has_include` is defined.

Closes #115529 

>From a8dfbecffdf67a6ed5f5df4bff5405b0ac708da0 Mon Sep 17 00:00:00 2001
From: dipeshs809 
Date: Thu, 21 Nov 2024 17:48:22 +0530
Subject: [PATCH] [clang] guard __STDC_NO_THREADS__ defination for MSVCVersion
 2022 17.9 and above

---
 clang/include/clang/Basic/LangOptions.h |  1 +
 clang/lib/Basic/Targets/OSTargets.cpp   | 15 +--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..114a5d34a008bd 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -144,6 +144,7 @@ class LangOptionsBase {
 MSVC2019_5 = 1925,
 MSVC2019_8 = 1928,
 MSVC2022_3 = 1933,
+MSVC2022_9 = 1939,
   };
 
   enum SYCLMajorVersion {
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..f8d974e9979e4d 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -248,8 +248,19 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 Builder.defineMacro("_KERNEL_MODE");
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
-  Builder.defineMacro("__STDC_NO_THREADS__");
-
+  // Define __STDC_NO_THREADS__ based on MSVC version, threads.h availability,
+  // and language standard.
+  if (!Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_9)) {
+Builder.defineMacro("__STDC_NO_THREADS__");
+  } else {
+#if defined(__has_include) && !__has_include()
+Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
+Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+  }
+  // Builder.defineMacro("__STDC_NO_THREADS__");
   // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
   // users of the execution character set defined at compile time.
   // The value given is the Windows Code Page Identifier:

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


[clang] [lld] [llvm] [Windows] Add support for emitting PGO/LTO magic strings in the Windows PE debug directory (PR #114260)

2024-11-21 Thread Mikołaj Piróg via cfe-commits

mikolaj-pirog wrote:

Gently pinging @aganea @MaskRay @HaohaiWen. If there are no objections to this 
patch, I would like to merge it

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


[clang] d800ea7 - Adjust MSVC disabled optimization pragmas to be _MSC_VER only (#116704)

2024-11-21 Thread via cfe-commits

Author: Simon Pilgrim
Date: 2024-11-21T13:33:13Z
New Revision: d800ea7cb12245f65f886e18545ba83355825246

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

LOG: Adjust MSVC disabled optimization pragmas to be _MSC_VER only (#116704)

Alter the #ifdef values from #110986 and #115292 to use _MSC_VER instead of 
_WIN32 to stop the pragmas being used on gcc/mingw builds

Noticed by @mstorsjo

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.cpp
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 339af0c873a8e4..1d2b5301ecd73b 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1588,7 +1588,7 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, bool 
HasIndeterminateBits,
 }
 
 // https://github.com/llvm/llvm-project/issues/102513
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma optimize("", off)
 #endif
 bool Interpret(InterpState &S, APValue &Result) {
@@ -1616,7 +1616,7 @@ bool Interpret(InterpState &S, APValue &Result) {
   }
 }
 // https://github.com/llvm/llvm-project/issues/102513
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma optimize("", on)
 #endif
 

diff  --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 10dad7675f4eaf..8512fd9ae40172 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -32,7 +32,7 @@ using namespace llvm;
 #define PASS_NAME "AArch64 Instruction Selection"
 
 // https://github.com/llvm/llvm-project/issues/114425
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma inline_depth(0)
 #endif
 



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


[clang] [clang][ARM] disable frame pointers by default for bare metal ARM targets (PR #117140)

2024-11-21 Thread Ties Stuij via cfe-commits


@@ -148,6 +151,9 @@ static bool isARMBareMetal(const llvm::Triple &Triple) {
 
   return true;
 }
+} // namespace clang

stuij wrote:

thanks! done!

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


[clang] [llvm] [IR] Add TargetExtType::CanBeLocal property (PR #99016)

2024-11-21 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/99016

>From c2eda0aaeeaf9c8711cf64830df9bb3fee842f80 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Tue, 16 Jul 2024 11:29:05 +0100
Subject: [PATCH 1/5] [IR] Add TargetExtType::CanBeAlloca property

Add a property to allow marking target extension types that cannot be
used in an alloca instruction, similar to CanBeGlobal for global
variables.
---
 llvm/include/llvm/IR/DerivedTypes.h   | 2 ++
 llvm/lib/IR/Type.cpp  | 6 --
 llvm/lib/IR/Verifier.cpp  | 6 ++
 llvm/test/Assembler/target-type-properties.ll | 8 
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/IR/DerivedTypes.h 
b/llvm/include/llvm/IR/DerivedTypes.h
index 01f76d49327808..054cb370bc316c 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -769,6 +769,8 @@ class TargetExtType : public Type {
 HasZeroInit = 1U << 0,
 /// This type may be used as the value type of a global variable.
 CanBeGlobal = 1U << 1,
+/// This type may be used as the allocated type of an alloca instruction.
+CanBeAlloca = 1U << 2,
   };
 
   /// Returns true if the target extension type contains the given property.
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 9ddccce7f959c7..3f94ca95d2d8a0 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -826,12 +826,14 @@ static TargetTypeInfo getTargetTypeInfo(const 
TargetExtType *Ty) {
 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal);
   if (Name.starts_with("spirv."))
 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
-  TargetExtType::CanBeGlobal);
+  TargetExtType::CanBeGlobal,
+  TargetExtType::CanBeAlloca);
 
   // Opaque types in the AArch64 name space.
   if (Name == "aarch64.svcount")
 return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
-  TargetExtType::HasZeroInit);
+  TargetExtType::HasZeroInit,
+  TargetExtType::CanBeAlloca);
 
   return TargetTypeInfo(Type::getVoidTy(C));
 }
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index c095e47996ba17..ab932b591b638e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4285,6 +4285,12 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
   SmallPtrSet Visited;
   Check(AI.getAllocatedType()->isSized(&Visited),
 "Cannot allocate unsized type", &AI);
+  // Check if it's a target extension type that disallows being used in an
+  // alloca.
+  if (auto *TTy = dyn_cast(AI.getAllocatedType())) {
+Check(TTy->hasProperty(TargetExtType::CanBeAlloca),
+  "Alloca has illegal target extension type", &AI);
+  }
   Check(AI.getArraySize()->getType()->isIntegerTy(),
 "Alloca array size must have integer type", &AI);
   if (MaybeAlign A = AI.getAlign()) {
diff --git a/llvm/test/Assembler/target-type-properties.ll 
b/llvm/test/Assembler/target-type-properties.ll
index 49c9d812f1cf4a..eae5eec04da856 100644
--- a/llvm/test/Assembler/target-type-properties.ll
+++ b/llvm/test/Assembler/target-type-properties.ll
@@ -1,6 +1,7 @@
 ; RUN: split-file %s %t
 ; RUN: not llvm-as < %t/zeroinit-error.ll -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-ZEROINIT %s
 ; RUN: not llvm-as < %t/global-var.ll -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-GLOBALVAR %s
+; RUN: not llvm-as < %t/alloca.ll -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-ALLOCA %s
 ; Check target extension type properties are verified in the assembler.
 
 ;--- zeroinit-error.ll
@@ -14,3 +15,10 @@ define void @foo() {
 ;--- global-var.ll
 @global = external global target("unknown_target_type")
 ; CHECK-GLOBALVAR: Global @global has illegal target extension type
+
+;--- alloca.ll
+define void @foo() {
+  %val = alloca target("spirv.Image")
+; CHECK-ALLOCA: Alloca has illegal target extension type
+  ret void
+}

>From 73839348def7318183e24022bc00fd2705d51e3b Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Wed, 21 Aug 2024 10:34:32 +0100
Subject: [PATCH 2/5] Rename to CanBeLocal. Check byval arguments.

---
 llvm/include/llvm/IR/DerivedTypes.h   |  5 +++--
 llvm/lib/IR/Type.cpp  |  4 ++--
 llvm/lib/IR/Verifier.cpp  | 12 +---
 llvm/test/Assembler/target-type-properties.ll |  5 +
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/IR/DerivedTypes.h 
b/llvm/include/llvm/IR/DerivedTypes.h
index 054cb370bc316c..46f812dda16c9e 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -769,8 +769,9 @@ class TargetExtType : public Type {
 HasZeroInit = 1U << 0,
 /// This type may be used as the value type of a global variable.
 CanBeGlobal = 1U << 1,
-

[clang] [Clang] [Parser] Fixing all callers of `ParseExternalDeclaration` that didn't parse gnu attributes (PR #117148)

2024-11-21 Thread Mathys Gasnier via cfe-commits

https://github.com/Mathys-Gasnier created 
https://github.com/llvm/llvm-project/pull/117148

Not all callers of `ParseExternalDeclaration` were parsing gnu attributes, this 
caused issues with namespaces declarations attributes needing to be in a 
specific order (See #73890).
This PR fixes this in namespaces, exports, and three other places. It also adds 
a test to ensure a non-regression of this behavior.

Fixes: #73890 

>From 086b2e21da4febd31789fe717bae526af625627e Mon Sep 17 00:00:00 2001
From: Mathys-Gasnier 
Date: Thu, 21 Nov 2024 11:08:41 +0100
Subject: [PATCH] [Clang] [Parser] Fixing all callers of
 `ParseExternalDeclaration` that didn't parse gnu attributes

---
 clang/lib/Parse/ParseDeclCXX.cpp | 24 +++-
 clang/lib/Parse/ParseObjc.cpp|  8 +---
 clang/lib/Parse/ParseOpenMP.cpp  |  8 +---
 clang/lib/Parse/Parser.cpp   |  8 +---
 clang/test/Parser/cxx-attributes.cpp |  3 +++
 5 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 010ac9c1a3e3a9..4f050d6632c356 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -267,9 +267,11 @@ void Parser::ParseInnerNamespace(const 
InnerNamespaceInfoList &InnerNSs,
 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
Tok.isNot(tok::eof)) {
   ParsedAttributes DeclAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(DeclAttrs);
-  ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
-  ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+  while (MaybeParseCXX11Attributes(DeclAttrs) ||
+  MaybeParseGNUAttributes(DeclSpecAttrs))
+;
+  ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
 }
 
 // The caller is what called check -- we are simply calling
@@ -468,9 +470,11 @@ Decl *Parser::ParseExportDeclaration() {
   if (Tok.isNot(tok::l_brace)) {
 // FIXME: Factor out a ParseExternalDeclarationWithAttrs.
 ParsedAttributes DeclAttrs(AttrFactory);
-MaybeParseCXX11Attributes(DeclAttrs);
-ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
-ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
+ParsedAttributes DeclSpecAttrs(AttrFactory);
+while (MaybeParseCXX11Attributes(DeclAttrs) ||
+MaybeParseGNUAttributes(DeclSpecAttrs))
+  ;
+ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
 return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl,
  SourceLocation());
   }
@@ -481,9 +485,11 @@ Decl *Parser::ParseExportDeclaration() {
   while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
  Tok.isNot(tok::eof)) {
 ParsedAttributes DeclAttrs(AttrFactory);
-MaybeParseCXX11Attributes(DeclAttrs);
-ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
-ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
+ParsedAttributes DeclSpecAttrs(AttrFactory);
+while (MaybeParseCXX11Attributes(DeclAttrs) ||
+MaybeParseGNUAttributes(DeclSpecAttrs))
+  ;
+ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
   }
 
   T.consumeClose();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index bcbf4dfbabafa8..ec0572d58b3552 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2287,10 +2287,12 @@ 
Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
 ObjCImplParsingDataRAII ObjCImplParsing(*this, ObjCImpDecl);
 while (!ObjCImplParsing.isFinished() && !isEofOrEom()) {
   ParsedAttributes DeclAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(DeclAttrs);
-  ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+  while (MaybeParseCXX11Attributes(DeclAttrs) ||
+  MaybeParseGNUAttributes(DeclSpecAttrs))
+;
   if (DeclGroupPtrTy DGP =
-  ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs)) {
+  ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs)) {
 DeclGroupRef DG = DGP.get();
 DeclsInGroup.append(DG.begin(), DG.end());
   }
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b91928063169ee..debfc7bd898864 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2314,10 +2314,12 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
 assert(TagType == DeclSpec::TST_unspecified);
-ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
-MaybeParseCXX11Attributes(Attrs);
+ParsedAttributes DeclSpecAttrs(AttrFactory);
+while (MaybeParseCXX11Attributes(Attrs) ||
+MaybeParseGNUAttributes(DeclSpecAttrs))
+

[clang] [llvm] [AArch64] Implement intrinsics for F1CVTL/F2CVTL and BF1CVTL/BF2CVTL (PR #116959)

2024-11-21 Thread via cfe-commits

https://github.com/SpencerAbson updated 
https://github.com/llvm/llvm-project/pull/116959

>From 296492155525985942e1a0fc56b6f0db34e8a7a4 Mon Sep 17 00:00:00 2001
From: Spencer Abson 
Date: Wed, 20 Nov 2024 10:57:49 +
Subject: [PATCH 1/4] [AArch64] Add intrinsics for F1CVTL/F2CVTL and
 BF1CVTL/BF2CVTL

---
 clang/include/clang/Basic/TargetBuiltins.h|  1 +
 clang/include/clang/Basic/arm_sme.td  |  7 ++
 clang/include/clang/Basic/arm_sve_sme_incl.td |  2 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  4 +
 .../fp8-intrinsics/acle_sme2_fp8_cvt.c| 81 +++
 clang/utils/TableGen/SveEmitter.cpp   |  6 ++
 llvm/include/llvm/IR/IntrinsicsAArch64.td | 17 
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp| 34 
 llvm/lib/Target/AArch64/SMEInstrFormats.td|  2 +-
 .../AArch64/sme2-fp8-intrinsics-cvt.ll| 48 +++
 10 files changed, 201 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-cvt.ll

diff --git a/clang/include/clang/Basic/TargetBuiltins.h 
b/clang/include/clang/Basic/TargetBuiltins.h
index 89ebf5758a5b55..a14fd2c4b224d8 100644
--- a/clang/include/clang/Basic/TargetBuiltins.h
+++ b/clang/include/clang/Basic/TargetBuiltins.h
@@ -336,6 +336,7 @@ namespace clang {
 bool isTupleSet() const { return Flags & IsTupleSet; }
 bool isReadZA() const { return Flags & IsReadZA; }
 bool isWriteZA() const { return Flags & IsWriteZA; }
+bool setsFPMR() const { return Flags & SetsFPMR; }
 bool isReductionQV() const { return Flags & IsReductionQV; }
 uint64_t getBits() const { return Flags; }
 bool isFlagSet(uint64_t Flag) const { return Flags & Flag; }
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 0f689e82bdb742..8e7e4395411c6c 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -824,4 +824,11 @@ let SMETargetGuard = "sme-lutv2" in {
   def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, 
"aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>;
 }
 
+let SMETargetGuard = "sme2,fp8" in {
+  // Convert from half-precision/BFloat16 to deinterleaved FP8 multi-vector
+  def SVF1CVTL: Inst<"svcvtl1_f16[_mf8]_x2_fpm",  "2~n", "h", MergeNone, 
"aarch64_sme_fp8_f1cvtl_x2",  [IsStreaming, IsOverloadNone, SetsFPMR], []>;
+  def SVF1CVTL_BF : Inst<"svcvtl1_bf16[_mf8]_x2_fpm", "2~n", "b", MergeNone, 
"aarch64_sme_fp8_bf1cvtl_x2", [IsStreaming, IsOverloadNone, SetsFPMR], []>;
+  def SVF2CVTL: Inst<"svcvtl2_f16[_mf8]_x2_fpm",  "2~n", "h", MergeNone, 
"aarch64_sme_fp8_f2cvtl_x2",  [IsStreaming, IsOverloadNone, SetsFPMR], []>;
+  def SVF2CVTL_BF : Inst<"svcvtl2_bf16[_mf8]_x2_fpm", "2~n", "b", MergeNone, 
"aarch64_sme_fp8_bf2cvtl_x2", [IsStreaming, IsOverloadNone, SetsFPMR], []>;
+}
 } // let SVETargetGuard = InvalidMode
diff --git a/clang/include/clang/Basic/arm_sve_sme_incl.td 
b/clang/include/clang/Basic/arm_sve_sme_incl.td
index 50911fb63e818e..7fdf732e506a2e 100644
--- a/clang/include/clang/Basic/arm_sve_sme_incl.td
+++ b/clang/include/clang/Basic/arm_sve_sme_incl.td
@@ -103,6 +103,7 @@ include "arm_immcheck_incl.td"
 // M: svfloat32_t
 // N: svfloat64_t
 // $: svbfloat16_t
+// ~: svmfloat8_t
 
 // J: Prefetch type (sv_prfop)
 
@@ -235,6 +236,7 @@ def IsInOutZA   : 
FlagType<0x2000>;
 def IsInZT0 : FlagType<0x4000>;
 def IsOutZT0: FlagType<0x8000>;
 def IsInOutZT0  : FlagType<0x1>;
+def SetsFPMR: FlagType<0x2>;
 
 defvar InvalidMode = "";
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0916e14f182ddd..568ba0ade6422f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -11182,6 +11182,10 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
BuiltinID == SME::BI__builtin_sme_svstr_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
+  // Emit set FPMR for intrinsics that require it
+  if (TypeFlags.setsFPMR())
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_set_fpmr),
+   Ops.pop_back_val());
   // Handle builtins which require their multi-vector operands to be swapped
   swapCommutativeSMEOperands(BuiltinID, Ops);
 
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
new file mode 100644
index 00..da2a505a897996
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
@@ -0,0 +1,81 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -trip

[clang] [llvm] Adjust MSVC disabled optimization pragmas to be _MSC_VER only (PR #116704)

2024-11-21 Thread Simon Pilgrim via cfe-commits


@@ -1616,7 +1616,7 @@ bool Interpret(InterpState &S, APValue &Result) {
   }
 }
 // https://github.com/llvm/llvm-project/issues/102513
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma optimize("", on)

RKSimon wrote:

nice catch!

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


[clang] [clang][bytecode] Check FromPtr in BitCastPtr (PR #117142)

2024-11-21 Thread Timm Baeder via cfe-commits

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


[clang] [clang] constexpr built-in reduce `or` and `xor` function. (PR #116976)

2024-11-21 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/116976

>From 4d13a8267dd5d0e99063bb088a85406af5266c80 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Wed, 20 Nov 2024 22:07:35 +0800
Subject: [PATCH 1/3] constexpr reduce or/xor

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/include/clang/Basic/Builtins.td|  4 ++--
 clang/lib/AST/ExprConstant.cpp   | 12 +++-
 clang/test/Sema/constant_builtins_vector.cpp | 20 
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 999c88455b64a5..98ed21d09305b2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_add`` function can now be used in constant expressions.
 - ``__builtin_reduce_mul`` function can now be used in constant expressions.
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
+- ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index aa65f94e68f9c3..daf90b9570160e 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1486,13 +1486,13 @@ def ReduceMinimum : Builtin {
 
 def ReduceXor : Builtin {
   let Spellings = ["__builtin_reduce_xor"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def ReduceOr : Builtin {
   let Spellings = ["__builtin_reduce_or"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 33206f5cda2021..261de141637020 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13529,7 +13529,9 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 
   case Builtin::BI__builtin_reduce_add:
   case Builtin::BI__builtin_reduce_mul:
-  case Builtin::BI__builtin_reduce_and: {
+  case Builtin::BI__builtin_reduce_and:
+  case Builtin::BI__builtin_reduce_or:
+  case Builtin::BI__builtin_reduce_xor: {
 APValue Source;
 if (!EvaluateAsRValue(Info, E->getArg(0), Source))
   return false;
@@ -13558,6 +13560,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 Reduced &= Source.getVectorElt(EltNum).getInt();
 break;
   }
+  case Builtin::BI__builtin_reduce_or: {
+Reduced |= Source.getVectorElt(EltNum).getInt();
+break;
+  }
+  case Builtin::BI__builtin_reduce_xor: {
+Reduced ^= Source.getVectorElt(EltNum).getInt();
+break;
+  }
   }
 }
 
diff --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index 7063c290479f6c..e84d09b24672b4 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -777,3 +777,23 @@ 
static_assert(__builtin_reduce_and((vector4int){(int)~0x, (int)~0x22
 static_assert(__builtin_reduce_and((vector4long){(long 
long)~0xL, (long long)~0xL, (long 
long)~0xL, (long long)-1}) == 0xL);
 static_assert(__builtin_reduce_and((vector4uint){0xU, 0xU, 
0xU, 0xU}) == 0U);
 static_assert(__builtin_reduce_and((vector4ulong){0xUL, 
0xUL, 0xUL, 0xUL}) == 0L);
+
+static_assert(__builtin_reduce_or((vector4char){}) == 0);
+static_assert(__builtin_reduce_or((vector4char){(char)0x11, (char)0x22, 
(char)0x44, (char)0x88}) == (char)0xFF);
+static_assert(__builtin_reduce_or((vector4short){(short)0x, (short)0x, 
(short)0x, (short)0x}) == (short)0x);
+static_assert(__builtin_reduce_or((vector4int){(int)0x, 
(int)0x, (int)0x, (int)0x}) == (int)0x);
+static_assert(__builtin_reduce_or((vector4long){(long 
long)0xL, (long long)0xL, (long 
long)0xL, (long long)0xL}) == (long 
long)0xL);
+static_assert(__builtin_reduce_or((vector4char){(char)0, (char)0x22, 
(char)0x44, (char)0x88}) == ~0x11);
+static_assert(__builtin_reduce_or((vector4short){(short)0x, (short)0, 
(short)0x, (short)0x}) == ~0x);
+static_assert(__builtin_reduce_or((vector4int){(int)0x, 
(int)0x, (int)0, (int)0x}) == ~0x);
+static_assert(__builtin_reduce_or((vector4long){(long 
long)0xL, (long long)0xL, (long 
long)0xL, (long lo

[clang] [clang][bytecode] Check FromPtr in BitCastPtr (PR #117142)

2024-11-21 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] [HLSL] Implement WaveActiveAnyTrue intrinsic (PR #115902)

2024-11-21 Thread Ashley Coleman via cfe-commits


@@ -1949,24 +1949,36 @@ bool SPIRVInstructionSelector::selectSign(Register 
ResVReg,
   return Result;
 }
 
+bool SPIRVInstructionSelector::selectWaveOpInst(Register ResVReg,
+const SPIRVType *ResType,
+MachineInstr &I,
+unsigned Opcode) const {
+  MachineBasicBlock &BB = *I.getParent();
+  SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
+
+  auto BMI = BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
+ .addDef(ResVReg)
+ .addUse(GR.getSPIRVTypeID(ResType))
+ .addUse(GR.getOrCreateConstInt(SPIRV::Scope::Subgroup, I,
+IntTy, TII));
+
+  for (unsigned j = 2; j < I.getNumOperands(); j++) {

V-FEXrt wrote:

I'm a die hard vim user >.< 

But I do already have clangd setup and I think I can set that up to do the same

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


[clang] [clang][bytecode] Initialize bases when bitcasting (PR #117179)

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


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

>From 30d56c5522516e1d4b3fdb69c8aae67db8df5d69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 8 Nov 2024 14:37:56 +0100
Subject: [PATCH 1/3] [clang][bytecode] Handle bitcasts involving bitfields

---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  |  88 
 clang/lib/AST/ByteCode/BitcastBuffer.h|  67 +++
 clang/lib/AST/ByteCode/Boolean.h  |   4 +-
 clang/lib/AST/ByteCode/Integral.h |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 250 --
 clang/lib/AST/CMakeLists.txt  |   1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 437 ++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 104 +
 .../unittests/AST/ByteCode/BitcastBuffer.cpp  |  83 
 clang/unittests/AST/ByteCode/CMakeLists.txt   |   1 +
 10 files changed, 790 insertions(+), 246 deletions(-)
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.cpp
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 create mode 100644 clang/unittests/AST/ByteCode/BitcastBuffer.cpp

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..093f2b2c224093
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,88 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+void BitcastBuffer::pushData(const std::byte *In, size_t BitOffset,
+ size_t BitWidth, Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth; ++It) {
+bool BitValue = bitof(In, It);
+if (!BitValue)
+  continue;
+
+unsigned DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + It;
+else
+  DstBit = size() - BitOffset - BitWidth + It;
+
+unsigned DstByte = (DstBit / 8);
+Data[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(unsigned BitOffset, unsigned BitWidth,
+unsigned FullBitWidth, Endian TargetEndianness) const {
+  assert(BitWidth <= FullBitWidth);
+  assert(fullByte(FullBitWidth));
+  auto Out = std::make_unique(FullBitWidth / 8);
+
+  for (unsigned It = 0; It != BitWidth; ++It) {
+unsigned BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + It;
+else
+  BitIndex = size() - BitWidth - BitOffset + It;
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+unsigned DstBit = It;
+unsigned DstByte = (DstBit / 8);
+Out[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..0cc7d5909c47e4
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,67 @@
+//===- BitcastBuffer.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit

[clang] [Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments (PR #114684)

2024-11-21 Thread Haojian Wu via cfe-commits

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


[clang] 925e195 - [Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments (#114684)

2024-11-21 Thread via cfe-commits

Author: Oleksandr T.
Date: 2024-11-22T08:46:46+01:00
New Revision: 925e1956cd5039fa2489b802d2e247c34175

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

LOG: [Clang] enhance error recovery with RecoveryExpr for trailing commas in 
call arguments (#114684)

Fixes #100921

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseExpr.cpp
clang/test/AST/ast-dump-recovery.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c81de341937ca..4847437ef1f8bd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,6 +578,8 @@ Improvements to Clang's diagnostics
 
 - Clang now omits shadowing warnings for parameter names in explicit object 
member functions (#GH95707).
 
+- Improved error recovery for function call arguments with trailing commas 
(#GH100921).
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 045ee754a242b3..d3838a4cc8418c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1934,7 +1934,8 @@ class Parser : public CodeCompletionHandler {
llvm::function_ref ExpressionStarts =
llvm::function_ref(),
bool FailImmediatelyOnInvalidExpr = false,
-   bool EarlyTypoCorrection = false);
+   bool EarlyTypoCorrection = false,
+   bool *HasTrailingComma = nullptr);
 
   /// ParseSimpleExpressionList - A simple comma-separated list of expressions,
   /// used for misc language extensions.

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 4570a18bc0d5e5..736484ded8383c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2199,10 +2199,17 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
   };
   if (OpKind == tok::l_paren || !LHS.isInvalid()) {
 if (Tok.isNot(tok::r_paren)) {
-  if (ParseExpressionList(ArgExprs, [&] {
+  bool HasTrailingComma = false;
+  bool HasError = ParseExpressionList(
+  ArgExprs,
+  [&] {
 PreferredType.enterFunctionArgument(Tok.getLocation(),
 RunSignatureHelp);
-  })) {
+  },
+  /*FailImmediatelyOnInvalidExpr*/ false,
+  /*EarlyTypoCorrection*/ false, &HasTrailingComma);
+
+  if (HasError && !HasTrailingComma) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);
 // If we got an error when parsing expression list, we don't call
 // the CodeCompleteCall handler inside the parser. So call it here
@@ -3662,7 +3669,8 @@ void Parser::injectEmbedTokens() {
 bool Parser::ParseExpressionList(SmallVectorImpl &Exprs,
  llvm::function_ref ExpressionStarts,
  bool FailImmediatelyOnInvalidExpr,
- bool EarlyTypoCorrection) {
+ bool EarlyTypoCorrection,
+ bool *HasTrailingComma) {
   bool SawError = false;
   while (true) {
 if (ExpressionStarts)
@@ -3705,6 +3713,12 @@ bool Parser::ParseExpressionList(SmallVectorImpl 
&Exprs,
 Token Comma = Tok;
 ConsumeToken();
 checkPotentialAngleBracketDelimiter(Comma);
+
+if (Tok.is(tok::r_paren)) {
+  if (HasTrailingComma)
+*HasTrailingComma = true;
+  break;
+}
   }
   if (SawError) {
 // Ensure typos get diagnosed when errors were encountered while parsing 
the

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index a88dff471d9f04..43884622240269 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -9,7 +9,7 @@ int some_func(int *);
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
 // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
 int invalid_call = some_func(123);
-void test_invalid_call(int s) {
+void test_invalid_call_1(int s) {
   // CHECK:  CallExpr {{.*}} '' contains-errors
   // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
   // CHECK-NEXT: |-RecoveryExpr {{.*}} 
@@ -32,6 +32,26 @@ void test_invalid_call(int s) {
   int var = some_func(undef1);
 }
 
+int some_func2(int a, int b);
+void test_invalid_call_2() {
+  // CHECK:   -RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '' 
lvalue (ADL) = 'some_func2'
+  some_func2(,);
+
+  // CHECK:   -RecoveryExpr {{.*

[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-21 Thread Utkarsh Saxena via cfe-commits


@@ -366,3 +366,82 @@ void use() {
   capture3(std::string(), x3); // expected-warning {{object whose reference is 
captured by 'x3' will be destroyed at the end of the full-expression}}
 }
 } // namespace temporary_views
+
+// 
+// Inferring annotation for STL containers
+// 

usx95 wrote:

Done.

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


[clang] 994c544 - doc: Clarify that ffile-prefix-map applies to fcoverage-prefix-map, too [NFC] (#117135)

2024-11-21 Thread via cfe-commits

Author: maflcko
Date: 2024-11-22T08:43:42+01:00
New Revision: 994c544c18c86cbdb6536aae5d27ef7e2f592486

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

LOG: doc: Clarify that ffile-prefix-map applies to fcoverage-prefix-map, too 
[NFC] (#117135)

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_...@721217.xyz>

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..01a3ad0943b4cc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4405,7 +4405,7 @@ def fcoverage_prefix_map_EQ
 HelpText<"remap file source paths  to  in coverage mapping. If 
there are multiple options, prefix replacement is applied in reverse order 
starting from the last one">;
 def ffile_prefix_map_EQ
   : Joined<["-"], "ffile-prefix-map=">, Group,
-HelpText<"remap file source paths in debug info, predefined preprocessor "
+HelpText<"remap file source paths in debug info, coverage mapping, 
predefined preprocessor "
  "macros and __builtin_FILE(). Implies -ffile-reproducible.">;
 def fmacro_prefix_map_EQ
   : Joined<["-"], "fmacro-prefix-map=">, Group,



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


[clang] doc: Clarify that ffile-prefix-map applies to fcoverage-prefix-map, too [NFC] (PR #117135)

2024-11-21 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Check getFunctionTypeLoc() for validity in InlayHintVisitor (PR #117296)

2024-11-21 Thread Younan Zhang via cfe-commits

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

Thanks.

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


[clang] [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (PR #117225)

2024-11-21 Thread via cfe-commits

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


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


[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> Second, this scheme reduces the expected number of hash collisions within 
> each arity, compared against the expected number of collisions (0.01383765) 
> for the 32-bit hashing scheme that includes all arities. The table below 
> shows the expected number of collisions for each arity, given the number of 
> unique indirect callable function types within that arity in the same Ubuntu 
> 24.04 server kernel discussed above.

The collisions vary a lot with different number of function types. It looks to 
me more smooth if we use 2 bits to distinguish 4 cases: 1, 2, 3 and 0 or others.

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


[clang] [Clang][AST] Add Test Cases for Reference Qualifiers in Opr Overload (PR #102878)

2024-11-21 Thread via cfe-commits

charan-003 wrote:

hi, i want to work on it


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


[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> @phoebewang and @lvwr I also noticed that there is this code in LLVM:
> 
> https://github.com/llvm/llvm-project/blob/9ba6672b9f0e82a1f6d4100dc832c84447ea545c/llvm/lib/Transforms/Utils/ModuleUtils.cpp#L202-L214
> 
> . As far as I can tell, this code is not triggered when I build the Linux 
> kernel with `-fsanitize=kcfi`.
> When is this code triggered? And do you think it is necessary to additionally 
> implement the arity-enhancement to this code?

I'm not familar with KCFI. I find it's added by @samitolvanen in 
https://github.com/llvm/llvm-project/commit/e1c36bde0551977d4b2efae032af6dfc4b2b3936.
 I think you should triger it with attached test case.

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


[clang] [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (PR #117225)

2024-11-21 Thread via cfe-commits


@@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
  New && New->isArray()) {
   if (auto ArraySize = New->getArraySize())
 Exprs.push_back(*ArraySize);
-}
+} else if (const auto *Mte = dyn_cast(OriginalE))
+  Exprs.push_back(Mte->getSubExpr());

Sirraide wrote:

```suggestion
} else if (const auto *MTE = dyn_cast(OriginalE))
  Exprs.push_back(MTE->getSubExpr());
```
Actually, very small nit that I missed at first, but everything else lgtm.

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


[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Scott Constable (scottconstable)


Changes

Kernel Control Flow Integrity (kCFI) is a feature that hardens indirect calls 
by comparing a 32-bit hash of the function pointer's type against a hash of the 
target function's type. If the hashes do not match, the kernel may panic (or 
log the hash check failure, depending on the kernel's configuration). These 
hashes are computed at compile time by applying the xxHash64 algorithm to each 
mangled canonical function (or function pointer) type, then truncating the 
result to 32 bits.

Like any hashing scheme, hash collisions are possible. For example, a commodity 
Linux kernel configured for Ubuntu 24.04 server has 141,617 total indirect call 
targets, with 10,903 unique function types. With a 32-bit kCFI hash, the 
expected number of collisions is 10,903-2^32+2^32*(1-1/(2^32))^10,903 = 
0.01383765 (see https://courses.cs.duke.edu/cps102/spring09/Lectures/L-18.pdf 
for the formula). This number can balloon with the addition of drivers and 
kernel modules.

This patch reduces both the expected number of collisions and the potential 
impact of a collision by augmenting the hash with an arity value that indicates 
how many parameters the function has at the ABI level. Specifically, the patch 
further truncates the kCFI hash down to 29 bits, then concatenates a 3-bit 
arity indicator as follows:

| Arity Indicator | Description |
| --- | --- |
| 0 | 0 parameters |
| 1 | 1 parameter in RDI |
| 2 | 2 parameters in RDI and RSI |
| 3 | 3 parameters in RDI, RSI, and RDX |
| 4 | 4 parameters in RDI, RSI, RDX, and RCX |
| 5 | 5 parameters in RDI, RSI, RDX, RCX, and R8 |
| 6 | 6 parameters in RDI, RSI, RDX, RCX, R8, and R9 |
| 7 | At least one parameter may be passed on the stack |

This scheme enhances security in two ways. First, it prevents a j-arity 
function pointer from being used to call a k-arity function, unless j=k. The 
current 32-bit kCFI hash does not prevent, for example, a 2-arity fptr from 
calling a 3-arity target if the kCFI hashes collide. If this were to happen, 
then potentially malicious stale/dead data in RDX at the call site could 
suddenly become live as the third parameter at the call target.

Second, this scheme reduces the expected number of hash collisions within each 
arity, compared against the expected number of collisions (0.01383765) for the 
32-bit hashing scheme that includes all arities. The table below shows the 
expected number of collisions for each arity, given the number of unique 
indirect callable function types within that arity in the same Ubuntu 24.04 
server kernel discussed above.

| Arity | Unique Indirect Callable Function Types | Number of Expected 
Collisions |
| - | --- | - |
| 0 | 32 |  0.0092 |
| 1 | 2492 |  0.00578125 |
| 2 | 3775 | 0.01326841 |
| 3 | 2547 | 0.00603931 |
| 4 | 1169 | 0.00127162 |
| 5 | 519 | 0.00025038 |
| 6 | 221 | 0.4528 |
| 7 | 148 | 0.2026 |

One additional benefit of this patch is that it can benefit other CFI 
approaches that build on kCFI, such as FineIBT. For example, this proposed 
enhancement to FineIBT must be able to infer (at kernel init time) which 
registers are live at an indirect call target: 
https://lkml.org/lkml/2024/9/27/982. If the arity bits are available in the 
kCFI type ID, then this information is trivial to infer.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+28-3) 
- (modified) clang/test/CodeGen/kcfi-normalize.c (+12-6) 
- (modified) clang/test/CodeGen/kcfi.c (+19-3) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b854eeb62a80ce..7cc6f120ec39a9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2183,7 +2183,8 @@ llvm::ConstantInt 
*CodeGenModule::CreateCrossDsoCfiTypeId(llvm::Metadata *MD) {
 }
 
 llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) {
-  if (auto *FnType = T->getAs())
+  auto *FnType = T->getAs();
+  if (FnType)
 T = getContext().getFunctionType(
 FnType->getReturnType(), FnType->getParamTypes(),
 FnType->getExtProtoInfo().withExceptionSpec(EST_None));
@@ -2196,8 +2197,32 @@ llvm::ConstantInt 
*CodeGenModule::CreateKCFITypeId(QualType T) {
   if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
 Out << ".normalized";
 
-  return llvm::ConstantInt::get(Int32Ty,
-
static_cast(llvm::xxHash64(OutName)));
+  uint32_t OutHash = static_cast(llvm::xxHash64(OutName));
+  const auto &Triple = getTarget().getTriple();
+  if (Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be passed
+  

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-21 Thread via cfe-commits

https://github.com/Sirraide commented:

I think this might honestly be fine the way it is now, but I’d like for e.g. 
@AaronBallman to take a look at this too before approving it since he’s more 
familiar w/ C than me.

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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-21 Thread via cfe-commits

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


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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-21 Thread Oleksandr T. via cfe-commits


@@ -4892,16 +4898,17 @@ CFGBlock 
*CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
   return Visit(E->getSubExpr(), asc);
 }
 
-CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
+CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   AddStmtChoice asc) {
   // If the constructor takes objects as arguments by value, we need to 
properly
   // construct these objects. Construction contexts we find here aren't for the
   // constructor C, they're for its arguments only.
-  findConstructionContextsForArguments(C);
+  findConstructionContextsForArguments(E);
 
-  autoCreateBlock();
-  appendConstructor(Block, C);
-  return VisitChildren(C);
+  createConstructorBlock(E->getConstructor());
+  appendConstructor(Block, E);

a-tarasyuk wrote:

@Sirraide Thanks. I've moved these changes to `appendConstructor`

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


[clang] Recommit "[TargetVersion] Only enable on RISC-V and AArch64" (#117110)" (PR #117128)

2024-11-21 Thread Piyou Chen via cfe-commits

https://github.com/BeMg created https://github.com/llvm/llvm-project/pull/117128

Remain InheritableAttr to avoid the warning `TypePrinter.cpp:1953:10: warning: 
enumeration value ‘TargetVersion’ not handled in switch`

origin messenge

[TargetVersion] Only enable on RISC-V and AArch64 (#115991) Address #115000.

This patch constrains the target_version feature to work only on RISC-V and 
AArch64 to prevent crashes in Clang.



>From 515663c0d1acede11ef60a588801a02369743bd3 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Wed, 20 Nov 2024 23:08:47 -0800
Subject: [PATCH] Recommit "[TargetVersion] Only enable on RISC-V and AArch64"
 (#117110)"

origin messenge

[TargetVersion] Only enable on RISC-V and AArch64 (#115991)
Address #115000.

This patch constrains the target_version feature to work only on RISC-V
and AArch64 to prevent crashes in Clang.

-

Co-authored-by: Aaron Ballman 
---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/include/clang/Basic/Attr.td | 2 +-
 clang/test/Sema/attr-target-version-unsupported.c | 4 
 3 files changed, 7 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/attr-target-version-unsupported.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 999c88455b64a5..a2ff05438c949a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -459,6 +459,8 @@ Attribute Changes in Clang
 - Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to 
lifetimebound, this can be
   used to specify when a reference to a function parameter is captured by 
another capturing entity ``X``.
 
+- The ``target_version`` attribute is now only supported for AArch64 and 
RISC-V architectures.
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 634253d0032560..14009826f2c550 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3297,7 +3297,7 @@ def Target : InheritableAttr {
   }];
 }
 
-def TargetVersion : InheritableAttr {
+def TargetVersion : InheritableAttr, 
TargetSpecificAttr> {
   let Spellings = [GCC<"target_version">];
   let Args = [StringArgument<"NamesStr">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
diff --git a/clang/test/Sema/attr-target-version-unsupported.c 
b/clang/test/Sema/attr-target-version-unsupported.c
new file mode 100644
index 00..7cf8172f5272e6
--- /dev/null
+++ b/clang/test/Sema/attr-target-version-unsupported.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+
+//expected-warning@+1 {{unknown attribute 'target_version' ignored}}
+int __attribute__((target_version("aes"))) foo(void) { return 3; }

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


[clang] Recommit "[TargetVersion] Only enable on RISC-V and AArch64" (#117110)" (PR #117128)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Piyou Chen (BeMg)


Changes

Remain InheritableAttr to avoid the warning `TypePrinter.cpp:1953:10: warning: 
enumeration value ‘TargetVersion’ not handled in switch`

origin messenge

[TargetVersion] Only enable on RISC-V and AArch64 (#115991) Address 
#115000.

This patch constrains the target_version feature to work only on RISC-V and 
AArch64 to prevent crashes in Clang.



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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/Attr.td (+1-1) 
- (added) clang/test/Sema/attr-target-version-unsupported.c (+4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 999c88455b64a5..a2ff05438c949a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -459,6 +459,8 @@ Attribute Changes in Clang
 - Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to 
lifetimebound, this can be
   used to specify when a reference to a function parameter is captured by 
another capturing entity ``X``.
 
+- The ``target_version`` attribute is now only supported for AArch64 and 
RISC-V architectures.
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 634253d0032560..14009826f2c550 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3297,7 +3297,7 @@ def Target : InheritableAttr {
   }];
 }
 
-def TargetVersion : InheritableAttr {
+def TargetVersion : InheritableAttr, 
TargetSpecificAttr> {
   let Spellings = [GCC<"target_version">];
   let Args = [StringArgument<"NamesStr">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
diff --git a/clang/test/Sema/attr-target-version-unsupported.c 
b/clang/test/Sema/attr-target-version-unsupported.c
new file mode 100644
index 00..7cf8172f5272e6
--- /dev/null
+++ b/clang/test/Sema/attr-target-version-unsupported.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+
+//expected-warning@+1 {{unknown attribute 'target_version' ignored}}
+int __attribute__((target_version("aes"))) foo(void) { return 3; }

``




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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-21 Thread Oleksandr T. via cfe-commits

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

>From f63263a1aa4873a63918649ea92352eb5cfe66eb Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 9 Nov 2024 00:41:13 +0200
Subject: [PATCH 1/4] [Clang] skip warnings for constructors marked with the
 [[noreturn]] attribute

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Analysis/CFG.cpp| 15 ++-
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp | 12 
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..11d0e35d12a786 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -527,6 +527,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` 
attribute (#GH63009).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..4d83f04c23060a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -4889,16 +4889,21 @@ CFGBlock 
*CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
   return Visit(E->getSubExpr(), asc);
 }
 
-CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
+CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   AddStmtChoice asc) {
   // If the constructor takes objects as arguments by value, we need to 
properly
   // construct these objects. Construction contexts we find here aren't for the
   // constructor C, they're for its arguments only.
-  findConstructionContextsForArguments(C);
+  findConstructionContextsForArguments(E);
 
-  autoCreateBlock();
-  appendConstructor(Block, C);
-  return VisitChildren(C);
+  CXXConstructorDecl *C = E->getConstructor();
+  if (C && C->isNoReturn())
+Block = createNoReturnBlock();
+  else
+autoCreateBlock();
+
+  appendConstructor(Block, E);
+  return VisitChildren(E);
 }
 
 CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index 56920ea8e8cf20..a96224dd03e360 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -49,3 +49,15 @@ void check() {
   test_type(g);
   test_type(h); // expected-note {{instantiation}}
 }
+
+namespace GH63009 {
+struct S {
+  [[noreturn]] S() { throw int {}; }
+};
+
+int test_no_return_constructor() { S(); } // ok
+
+int main() {
+  test_no_return_constructor();
+}
+}

>From 99582e7e30048b07dba57d0c284acf209f53b83e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 21 Nov 2024 01:25:43 +0200
Subject: [PATCH 2/4] suppress warnings for constructor expressions with the
 [[noreturn]] attribute

---
 clang/lib/Analysis/CFG.cpp| 16 --
 .../dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp | 11 +++---
 clang/test/SemaCXX/warn-missing-noreturn.cpp  | 22 +++
 3 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 4d83f04c23060a..35cf8c49bd27eb 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -760,6 +760,12 @@ class CFGBuilder {
   void cleanupConstructionContext(Expr *E);
 
   void autoCreateBlock() { if (!Block) Block = createBlock(); }
+  void createConstructorBlock(CXXConstructorDecl *C) {
+if (C && C->isNoReturn())
+  Block = createNoReturnBlock();
+else
+  autoCreateBlock();
+  };
   CFGBlock *createBlock(bool add_successor = true);
   CFGBlock *createNoReturnBlock();
 
@@ -4830,7 +4836,7 @@ CFGBlock 
*CFGBuilder::VisitCXXConstructExpr(CXXConstructExpr *C,
   // constructor C, they're for its arguments only.
   findConstructionContextsForArguments(C);
 
-  autoCreateBlock();
+  createConstructorBlock(C->getConstructor());
   appendConstructor(Block, C);
 
   return VisitChildren(C);
@@ -4896,13 +4902,9 @@ CFGBlock 
*CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   // constructor C, they're for its arguments only.
   findConstructionContextsForArguments(E);
 
-  CXXConstructorDecl *C = E->getConstructor();
-  if (C && C->isNoReturn())
-Block = createNoReturnBlock();
-  else
-autoCreateBlock();
-
+  createConstructorBlock(E->getConstructor());
   appendConstructor(Block, E);
+
   return VisitChildren(E);
 }
 
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index a96224dd03e360..afcb133e48a1a8 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clan

[clang] [clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls in SourceManager, and use the equivalent Report() overload instead (PR #116937)

2024-11-21 Thread Utkarsh Saxena via cfe-commits

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


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


[clang] [clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls in SourceManager, and use the equivalent Report() overload instead (PR #116937)

2024-11-21 Thread Boaz Brickner via cfe-commits

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


[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread Sebastian Österlund via cfe-commits


@@ -2196,8 +2197,32 @@ llvm::ConstantInt 
*CodeGenModule::CreateKCFITypeId(QualType T) {
   if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
 Out << ".normalized";
 
-  return llvm::ConstantInt::get(Int32Ty,
-
static_cast(llvm::xxHash64(OutName)));
+  uint32_t OutHash = static_cast(llvm::xxHash64(OutName));
+  const auto &Triple = getTarget().getTriple();
+  if (Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux()) {

sirmc wrote:

-> `if (FnType && Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux())`

Just to make sure that FnType isn't a null pointer.

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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-21 Thread Helmut Januschka via cfe-commits

hjanuschka wrote:

@nicovank  hows the protocol to get the other reviewers in?, should i ping them 
 - or should i just practice patience?

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


[clang] bc7f24c - [clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls in SourceManager, and use the equivalent Report() overload instead (#116937)

2024-11-21 Thread via cfe-commits

Author: Boaz Brickner
Date: 2024-11-21T09:41:09+01:00
New Revision: bc7f24cd8d6180ba297ea33ef5b4631a1bd26aea

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

LOG: [clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls 
in SourceManager, and use the equivalent Report() overload instead (#116937)

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 9b983cefbcf4ca..6e588ce63d813f 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -665,7 +665,7 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo 
&Info,
   LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, Info));
   if (NextLocalOffset + Length + 1 <= NextLocalOffset ||
   NextLocalOffset + Length + 1 > CurrentLoadedOffset) {
-Diag.Report(SourceLocation(), diag::err_sloc_space_too_large);
+Diag.Report(diag::err_sloc_space_too_large);
 // FIXME: call `noteSLocAddressSpaceUsage` to report details to users and
 // use a source location from `Info` to point at an error.
 // Currently, both cause Clang to run indefinitely, this needs to be fixed.
@@ -2295,7 +2295,7 @@ void SourceManager::noteSLocAddressSpaceUsage(
   uint64_t LoadedUsage = MaxLoadedOffset - CurrentLoadedOffset;
   int UsagePercent = static_cast(100.0 * double(LocalUsage + LoadedUsage) 
/
   MaxLoadedOffset);
-  Diag.Report(SourceLocation(), diag::note_total_sloc_usage)
+  Diag.Report(diag::note_total_sloc_usage)
   << LocalUsage << LoadedUsage << (LocalUsage + LoadedUsage)
   << UsagePercent;
 
@@ -2311,7 +2311,7 @@ void SourceManager::noteSLocAddressSpaceUsage(
 
   // Describe any remaining usage not reported in the per-file usage.
   if (ReportedSize != CountedSize) {
-Diag.Report(SourceLocation(), diag::note_file_misc_sloc_usage)
+Diag.Report(diag::note_file_misc_sloc_usage)
 << (SortedUsage.end() - SortedEnd) << CountedSize - ReportedSize;
   }
 }



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


[clang] [Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments (PR #114684)

2024-11-21 Thread Oleksandr T. via cfe-commits


@@ -3705,6 +3713,12 @@ bool Parser::ParseExpressionList(SmallVectorImpl 
&Exprs,
 Token Comma = Tok;
 ConsumeToken();
 checkPotentialAngleBracketDelimiter(Comma);
+
+if (Tok.is(tok::r_paren)) {
+  if (HasTrailingComma)
+*HasTrailingComma = true;
+  break;
+}

a-tarasyuk wrote:

@zyn0217 To handle a trailing comma, the previous token has to be a comma, and 
the next one a `r_paren`.

https://github.com/llvm/llvm-project/blob/46f43b6d92e49b80df13e8a537a95767ffbaac9f/clang/lib/Parse/ParseExpr.cpp#L3702-L3707



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


[clang] [clang-shlib] Add symbol versioning to all symbols (PR #110758)

2024-11-21 Thread Nikita Popov via cfe-commits

nikic wrote:

Closing this in favor of the merged 
https://github.com/llvm/llvm-project/pull/116556.

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


[clang] [LoongArch] Add conditional compilation for FP approximation intrinsics (PR #117132)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp   -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

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


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

>From 7b6b8c76b1438154f07794be4883625da8e9bd03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 8 Nov 2024 14:37:56 +0100
Subject: [PATCH 1/2] [clang][bytecode] Handle bitcasts involving bitfields

---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  |  88 
 clang/lib/AST/ByteCode/BitcastBuffer.h|  67 +++
 clang/lib/AST/ByteCode/Boolean.h  |   4 +-
 clang/lib/AST/ByteCode/Integral.h |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 250 --
 clang/lib/AST/CMakeLists.txt  |   1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 437 ++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 104 +
 .../unittests/AST/ByteCode/BitcastBuffer.cpp  |  83 
 clang/unittests/AST/ByteCode/CMakeLists.txt   |   1 +
 10 files changed, 790 insertions(+), 246 deletions(-)
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.cpp
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 create mode 100644 clang/unittests/AST/ByteCode/BitcastBuffer.cpp

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..093f2b2c224093
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,88 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+void BitcastBuffer::pushData(const std::byte *In, size_t BitOffset,
+ size_t BitWidth, Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth; ++It) {
+bool BitValue = bitof(In, It);
+if (!BitValue)
+  continue;
+
+unsigned DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + It;
+else
+  DstBit = size() - BitOffset - BitWidth + It;
+
+unsigned DstByte = (DstBit / 8);
+Data[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(unsigned BitOffset, unsigned BitWidth,
+unsigned FullBitWidth, Endian TargetEndianness) const {
+  assert(BitWidth <= FullBitWidth);
+  assert(fullByte(FullBitWidth));
+  auto Out = std::make_unique(FullBitWidth / 8);
+
+  for (unsigned It = 0; It != BitWidth; ++It) {
+unsigned BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + It;
+else
+  BitIndex = size() - BitWidth - BitOffset + It;
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+unsigned DstBit = It;
+unsigned DstByte = (DstBit / 8);
+Out[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..0cc7d5909c47e4
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,67 @@
+//===- BitcastBuffer.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit in the given sequence of

[clang] doc: Clarify that ffile-prefix-map applies to fcoverage-prefix-map, too [NFC] (PR #117135)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (maflcko)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..01a3ad0943b4cc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4405,7 +4405,7 @@ def fcoverage_prefix_map_EQ
 HelpText<"remap file source paths  to  in coverage mapping. If 
there are multiple options, prefix replacement is applied in reverse order 
starting from the last one">;
 def ffile_prefix_map_EQ
   : Joined<["-"], "ffile-prefix-map=">, Group,
-HelpText<"remap file source paths in debug info, predefined preprocessor "
+HelpText<"remap file source paths in debug info, coverage mapping, 
predefined preprocessor "
  "macros and __builtin_FILE(). Implies -ffile-reproducible.">;
 def fmacro_prefix_map_EQ
   : Joined<["-"], "fmacro-prefix-map=">, Group,

``




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


[clang] [clang-shlib] Add symbol versioning to all symbols (PR #110758)

2024-11-21 Thread Nikita Popov via cfe-commits

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


[clang] doc: Clarify that ffile-prefix-map applies to fcoverage-prefix-map, too [NFC] (PR #117135)

2024-11-21 Thread via cfe-commits

maflcko wrote:

I think this was just forgotten when the option was introduced initially in 
c3324450b2043 (under a different name)

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


[clang] [lld] [llvm] [RISCV] Make A implies Zaamo and Zalrsc (PR #116907)

2024-11-21 Thread Sam Elliott via cfe-commits

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


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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

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


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

>From 7b6b8c76b1438154f07794be4883625da8e9bd03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 8 Nov 2024 14:37:56 +0100
Subject: [PATCH 1/2] [clang][bytecode] Handle bitcasts involving bitfields

---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  |  88 
 clang/lib/AST/ByteCode/BitcastBuffer.h|  67 +++
 clang/lib/AST/ByteCode/Boolean.h  |   4 +-
 clang/lib/AST/ByteCode/Integral.h |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 250 --
 clang/lib/AST/CMakeLists.txt  |   1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 437 ++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 104 +
 .../unittests/AST/ByteCode/BitcastBuffer.cpp  |  83 
 clang/unittests/AST/ByteCode/CMakeLists.txt   |   1 +
 10 files changed, 790 insertions(+), 246 deletions(-)
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.cpp
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 create mode 100644 clang/unittests/AST/ByteCode/BitcastBuffer.cpp

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..093f2b2c224093
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,88 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+void BitcastBuffer::pushData(const std::byte *In, size_t BitOffset,
+ size_t BitWidth, Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth; ++It) {
+bool BitValue = bitof(In, It);
+if (!BitValue)
+  continue;
+
+unsigned DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + It;
+else
+  DstBit = size() - BitOffset - BitWidth + It;
+
+unsigned DstByte = (DstBit / 8);
+Data[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(unsigned BitOffset, unsigned BitWidth,
+unsigned FullBitWidth, Endian TargetEndianness) const {
+  assert(BitWidth <= FullBitWidth);
+  assert(fullByte(FullBitWidth));
+  auto Out = std::make_unique(FullBitWidth / 8);
+
+  for (unsigned It = 0; It != BitWidth; ++It) {
+unsigned BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + It;
+else
+  BitIndex = size() - BitWidth - BitOffset + It;
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+unsigned DstBit = It;
+unsigned DstByte = (DstBit / 8);
+Out[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..0cc7d5909c47e4
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,67 @@
+//===- BitcastBuffer.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit in the given sequence of

[clang] [llvm] Introduce symbol versioning for clang-cpp (PR #116556)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running 
on `aix-ppc64` while building `clang,llvm` at step 3 "clean-build-dir".

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


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

```
Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out)
Step 5 (build-unified-tree) failure: build (failure)
...
6334.752 [370/10/4830] Building CXX object 
tools/llvm-modextract/CMakeFiles/llvm-modextract.dir/llvm-modextract.cpp.o
6334.829 [369/10/4831] Building CXX object 
tools/llvm-ml/CMakeFiles/llvm-ml.dir/llvm-ml.cpp.o
6334.907 [368/10/4832] Building CXX object 
tools/llvm-ml/CMakeFiles/llvm-ml.dir/Disassembler.cpp.o
6334.990 [367/10/4833] Building CXX object 
tools/llvm-mt/CMakeFiles/llvm-mt.dir/llvm-mt.cpp.o
6335.028 [366/10/4834] Linking CXX executable bin/arcmt-test
6335.092 [365/10/4835] Building ObjdumpOpts.inc...
6335.248 [364/10/4836] Building CXX object 
tools/llvm-opt-fuzzer/CMakeFiles/llvm-opt-fuzzer.dir/DummyOptFuzzer.cpp.o
6335.281 [363/10/4837] Building OtoolOpts.inc...
6336.440 [362/10/4838] Building CXX object 
tools/llvm-objcopy/CMakeFiles/llvm-objcopy.dir/llvm-objcopy-driver.cpp.o
6343.285 [361/10/4839] Linking CXX shared library lib/libclang-cpp.a
FAILED: lib/libclang-cpp.a 
: && "/opt/freeware/share/cmake-3.26/Modules/Platform/AIX/ExportImportList" -o 
tools/clang/tools/clang-shlib/CMakeFiles/clang-cpp.dir/exports.exp -c 
/usr/local/clang-17.0.2/bin/clang++  
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ASTSourceDescriptor.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Builtins.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CLWarnings.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CharInfo.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CodeGenOptions.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Cuda.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/DarwinSDKInfo.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Diagnostic.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/DiagnosticIDs.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/DiagnosticOptions.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ExpressionTraits.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileEntry.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileManager.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileSystemStatCache.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/IdentifierTable.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/LangOptions.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/LangStandards.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/MakeSupport.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Module.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ObjCRuntime.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OpenCLOptions.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OpenMPKinds.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OperatorPrecedence.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ParsedAttrInfo.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ProfileList.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/NoSanitizeList.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SanitizerSpecialCaseList.cpp.o
 tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Sanitizers.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Sarif.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SourceLocation.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SourceManager.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SourceMgrAdapter.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Stack.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/StackExhaustionHandler.cpp.o
 tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/TargetID.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/TargetInfo.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/AArch64.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/AMDGPU.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/ARC.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/ARM.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/AVR.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/BPF.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/CSKY.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/DirectX.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/Hexagon.cpp.o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targ

[clang] doc: Clarify that ffile-prefix-map applies to fcoverage-prefix-map, too [NFC] (PR #117135)

2024-11-21 Thread via cfe-commits

https://github.com/maflcko created 
https://github.com/llvm/llvm-project/pull/117135

None

>From 7ebb194996a402edfb181d13ebf7ec0cedd638e3 Mon Sep 17 00:00:00 2001
From: MarcoFalke <*~=`'#}+{/-|&$^_...@721217.xyz>
Date: Thu, 21 Nov 2024 10:28:02 +0100
Subject: [PATCH] doc: Clarify that ffile-prefix-map applies to
 fcoverage-prefix-map, too

---
 clang/include/clang/Driver/Options.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..01a3ad0943b4cc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4405,7 +4405,7 @@ def fcoverage_prefix_map_EQ
 HelpText<"remap file source paths  to  in coverage mapping. If 
there are multiple options, prefix replacement is applied in reverse order 
starting from the last one">;
 def ffile_prefix_map_EQ
   : Joined<["-"], "ffile-prefix-map=">, Group,
-HelpText<"remap file source paths in debug info, predefined preprocessor "
+HelpText<"remap file source paths in debug info, coverage mapping, 
predefined preprocessor "
  "macros and __builtin_FILE(). Implies -ffile-reproducible.">;
 def fmacro_prefix_map_EQ
   : Joined<["-"], "fmacro-prefix-map=">, Group,

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


[clang] [NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8… (PR #114804)

2024-11-21 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/114804

>From fc97e36c08964c42debda9ad1a289d15b5327d23 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Wed, 30 Oct 2024 16:20:16 +
Subject: [PATCH 1/4] [NFC][Clang][AArch64]Refactor implementation of Neon
 vectors  MFloat8x8 and MFloat8x16

This patch removes the builtins for MFloat8x8 and Mfloat8x16 and build these 
types
the same way the other neon vectors are build. It uses the scalar type(mfloat8).
---
 clang/include/clang/AST/Type.h|  5 +++
 .../clang/Basic/AArch64SVEACLETypes.def   |  2 -
 clang/include/clang/Basic/TargetBuiltins.h|  4 +-
 clang/include/clang/Basic/arm_neon_incl.td|  1 +
 clang/lib/AST/ItaniumMangle.cpp   |  2 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  5 +++
 clang/lib/CodeGen/Targets/AArch64.cpp |  7 +---
 clang/lib/Sema/SemaARM.cpp|  2 +
 clang/lib/Sema/SemaExpr.cpp   |  5 +++
 clang/lib/Sema/SemaType.cpp   |  3 +-
 clang/test/CodeGen/arm-mfp8.c |  4 +-
 clang/test/Sema/arm-mfp8.cpp  | 27 ++--
 clang/utils/TableGen/NeonEmitter.cpp  | 41 ---
 14 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 8979129017163b..8e76d19495a6a6 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2534,6 +2534,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isFloat32Type() const;
   bool isDoubleType() const;
   bool isBFloat16Type() const;
+  bool isMFloat8Type() const;
   bool isFloat128Type() const;
   bool isIbm128Type() const;
   bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
@@ -8542,6 +8543,10 @@ inline bool Type::isBFloat16Type() const {
   return isSpecificBuiltinType(BuiltinType::BFloat16);
 }
 
+inline bool Type::isMFloat8Type() const {
+  return isSpecificBuiltinType(BuiltinType::MFloat8);
+}
+
 inline bool Type::isFloat128Type() const {
   return isSpecificBuiltinType(BuiltinType::Float128);
 }
diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 063cac1f4a58ee..2dd2754e778d60 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -201,8 +201,6 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", 
SveBoolx4, SveBoolx4T
 SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
 
 AARCH64_VECTOR_TYPE_MFLOAT("__mfp8", "__mfp8", MFloat8, MFloat8Ty, 1, 8, 1)
-AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x8_t", "__MFloat8x8_t", MFloat8x8, 
MFloat8x8Ty, 8, 8, 1)
-AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x16_t", "__MFloat8x16_t", MFloat8x16, 
MFloat8x16Ty, 16, 8, 1)
 
 #undef SVE_VECTOR_TYPE
 #undef SVE_VECTOR_TYPE_BFLOAT
diff --git a/clang/include/clang/Basic/TargetBuiltins.h 
b/clang/include/clang/Basic/TargetBuiltins.h
index 89ebf5758a5b55..86432601115d44 100644
--- a/clang/include/clang/Basic/TargetBuiltins.h
+++ b/clang/include/clang/Basic/TargetBuiltins.h
@@ -200,7 +200,8 @@ namespace clang {
   Float16,
   Float32,
   Float64,
-  BFloat16
+  BFloat16,
+  MFloat8
 };
 
 NeonTypeFlags(unsigned F) : Flags(F) {}
@@ -222,6 +223,7 @@ namespace clang {
   switch (getEltType()) {
   case Int8:
   case Poly8:
+  case MFloat8:
 return 8;
   case Int16:
   case Float16:
diff --git a/clang/include/clang/Basic/arm_neon_incl.td 
b/clang/include/clang/Basic/arm_neon_incl.td
index b088e0794cdea3..fd800e5a6278e4 100644
--- a/clang/include/clang/Basic/arm_neon_incl.td
+++ b/clang/include/clang/Basic/arm_neon_incl.td
@@ -218,6 +218,7 @@ def OP_UNAVAILABLE : Operation {
 // h: half-float
 // d: double
 // b: bfloat16
+// m: mfloat8
 //
 // Typespec modifiers
 // --
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 14bc260d0245fb..2858202426f1ee 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3901,6 +3901,8 @@ static StringRef mangleAArch64VectorBase(const 
BuiltinType *EltType) {
 return "Float64";
   case BuiltinType::BFloat16:
 return "Bfloat16";
+  case BuiltinType::MFloat8:
+return "Mfloat8";
   default:
 llvm_unreachable("Unexpected vector element base type");
   }
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e03cb6e8c3c861..278c3b17110740 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6594,6 +6594,7 @@ static llvm::FixedVectorType *GetNeonType(CodeGenFunction 
*CGF,
   switch (TypeFlags.getEltType()) {
   case NeonTypeFlags::Int8:
   case NeonTypeFlags::Poly8:
+  case NeonTypeFlags::MFloat8:
 return llvm::FixedVectorType

[clang] bbafe59 - [LoongArch] Add conditional compilation for FP approximation intrinsics (#117132)

2024-11-21 Thread via cfe-commits

Author: Ami-zhang
Date: 2024-11-21T17:39:28+08:00
New Revision: bbafe590880e6efb9e6b9e587d7dea7c19e7809b

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

LOG: [LoongArch] Add conditional compilation for FP approximation intrinsics 
(#117132)

Introduce a check for `__loongarch_frecipe` macro around the FP
approximation intrinsic implementation. This ensures that these
intrinsics are only included when this macro is defined, providing
better flexibility and control over the usage of FP approximation
instructions.

Added: 


Modified: 
clang/lib/Headers/larchintrin.h
clang/lib/Headers/lasxintrin.h
clang/lib/Headers/lsxintrin.h

Removed: 




diff  --git a/clang/lib/Headers/larchintrin.h b/clang/lib/Headers/larchintrin.h
index f4218295919a0d..a1247d12e21f8f 100644
--- a/clang/lib/Headers/larchintrin.h
+++ b/clang/lib/Headers/larchintrin.h
@@ -228,17 +228,31 @@ extern __inline void
   ((void)__builtin_loongarch_ldpte_d((long int)(_1), (_2)))
 #endif
 
-#define __frecipe_s(/*float*/ _1)  
\
-  (float)__builtin_loongarch_frecipe_s((float)_1)
+#ifdef __loongarch_frecipe
+extern __inline float
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frecipe_s(float _1) {
+  return __builtin_loongarch_frecipe_s(_1);
+}
 
-#define __frecipe_d(/*double*/ _1) 
\
-  (double)__builtin_loongarch_frecipe_d((double)_1)
+extern __inline double
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frecipe_d(double _1) {
+  return __builtin_loongarch_frecipe_d(_1);
+}
 
-#define __frsqrte_s(/*float*/ _1)  
\
-  (float)__builtin_loongarch_frsqrte_s((float)_1)
+extern __inline float
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frsqrte_s(float _1) {
+  return __builtin_loongarch_frsqrte_s(_1);
+}
 
-#define __frsqrte_d(/*double*/ _1) 
\
-  (double)__builtin_loongarch_frsqrte_d((double)_1)
+extern __inline double
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frsqrte_d(double _1) {
+  return __builtin_loongarch_frsqrte_d(_1);
+}
+#endif
 
 #ifdef __cplusplus
 }

diff  --git a/clang/lib/Headers/lasxintrin.h b/clang/lib/Headers/lasxintrin.h
index c065ea92a2dd52..85020d82829e2a 100644
--- a/clang/lib/Headers/lasxintrin.h
+++ b/clang/lib/Headers/lasxintrin.h
@@ -1726,18 +1726,6 @@ extern __inline
   return (__m256d)__builtin_lasx_xvfrecip_d((v4f64)_1);
 }
 
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
-__lasx_xvfrecipe_s(__m256 _1) {
-  return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1);
-}
-
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
-__lasx_xvfrecipe_d(__m256d _1) {
-  return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1);
-}
-
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
 __lasx_xvfrint_s(__m256 _1) {
@@ -1762,18 +1750,6 @@ extern __inline
   return (__m256d)__builtin_lasx_xvfrsqrt_d((v4f64)_1);
 }
 
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
-__lasx_xvfrsqrte_s(__m256 _1) {
-  return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1);
-}
-
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
-__lasx_xvfrsqrte_d(__m256d _1) {
-  return (__m256d)__builtin_lasx_xvfrsqrte_d((v4f64)_1);
-}
-
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
 __lasx_xvflogb_s(__m256 _1) {
@@ -3866,6 +3842,32 @@ extern __inline
   return (__m256i)__builtin_lasx_xvfcmp_sun_s((v8f32)_1, (v8f32)_2);
 }
 
+#if defined(__loongarch_frecipe)
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
+__lasx_xvfrecipe_s(__m256 _1) {
+  return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
+__lasx_xvfrecipe_d(__m256d _1) {
+  return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
+__lasx_xvfrsqrte_s(__m256 _1) {
+  return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
+__lasx_xvfrsqrte_d(__m256d _1) {
+  return (__m256d)__builtin_lasx_xvfrsqrte_d((v4f64)_1);
+}
+#endif
+
 #define __lasx_xvpickve_d_f(/*__m256d*/ _1, /*ui2*/ _2)
\
   ((__m256d)__builtin_l

[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

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


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

>From 7b6b8c76b1438154f07794be4883625da8e9bd03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 8 Nov 2024 14:37:56 +0100
Subject: [PATCH 1/2] [clang][bytecode] Handle bitcasts involving bitfields

---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  |  88 
 clang/lib/AST/ByteCode/BitcastBuffer.h|  67 +++
 clang/lib/AST/ByteCode/Boolean.h  |   4 +-
 clang/lib/AST/ByteCode/Integral.h |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 250 --
 clang/lib/AST/CMakeLists.txt  |   1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 437 ++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 104 +
 .../unittests/AST/ByteCode/BitcastBuffer.cpp  |  83 
 clang/unittests/AST/ByteCode/CMakeLists.txt   |   1 +
 10 files changed, 790 insertions(+), 246 deletions(-)
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.cpp
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 create mode 100644 clang/unittests/AST/ByteCode/BitcastBuffer.cpp

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..093f2b2c224093
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,88 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+void BitcastBuffer::pushData(const std::byte *In, size_t BitOffset,
+ size_t BitWidth, Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth; ++It) {
+bool BitValue = bitof(In, It);
+if (!BitValue)
+  continue;
+
+unsigned DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + It;
+else
+  DstBit = size() - BitOffset - BitWidth + It;
+
+unsigned DstByte = (DstBit / 8);
+Data[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(unsigned BitOffset, unsigned BitWidth,
+unsigned FullBitWidth, Endian TargetEndianness) const {
+  assert(BitWidth <= FullBitWidth);
+  assert(fullByte(FullBitWidth));
+  auto Out = std::make_unique(FullBitWidth / 8);
+
+  for (unsigned It = 0; It != BitWidth; ++It) {
+unsigned BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + It;
+else
+  BitIndex = size() - BitWidth - BitOffset + It;
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+unsigned DstBit = It;
+unsigned DstByte = (DstBit / 8);
+Out[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..0cc7d5909c47e4
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,67 @@
+//===- BitcastBuffer.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit in the given sequence of

[clang] [LoongArch] Add conditional compilation for FP approximation intrinsics (PR #117132)

2024-11-21 Thread Lu Weining via cfe-commits

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


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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

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


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

>From 7b6b8c76b1438154f07794be4883625da8e9bd03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 8 Nov 2024 14:37:56 +0100
Subject: [PATCH 1/2] [clang][bytecode] Handle bitcasts involving bitfields

---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  |  88 
 clang/lib/AST/ByteCode/BitcastBuffer.h|  67 +++
 clang/lib/AST/ByteCode/Boolean.h  |   4 +-
 clang/lib/AST/ByteCode/Integral.h |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 250 --
 clang/lib/AST/CMakeLists.txt  |   1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 437 ++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 104 +
 .../unittests/AST/ByteCode/BitcastBuffer.cpp  |  83 
 clang/unittests/AST/ByteCode/CMakeLists.txt   |   1 +
 10 files changed, 790 insertions(+), 246 deletions(-)
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.cpp
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 create mode 100644 clang/unittests/AST/ByteCode/BitcastBuffer.cpp

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..093f2b2c224093
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,88 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+void BitcastBuffer::pushData(const std::byte *In, size_t BitOffset,
+ size_t BitWidth, Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth; ++It) {
+bool BitValue = bitof(In, It);
+if (!BitValue)
+  continue;
+
+unsigned DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + It;
+else
+  DstBit = size() - BitOffset - BitWidth + It;
+
+unsigned DstByte = (DstBit / 8);
+Data[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(unsigned BitOffset, unsigned BitWidth,
+unsigned FullBitWidth, Endian TargetEndianness) const {
+  assert(BitWidth <= FullBitWidth);
+  assert(fullByte(FullBitWidth));
+  auto Out = std::make_unique(FullBitWidth / 8);
+
+  for (unsigned It = 0; It != BitWidth; ++It) {
+unsigned BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + It;
+else
+  BitIndex = size() - BitWidth - BitOffset + It;
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+unsigned DstBit = It;
+unsigned DstByte = (DstBit / 8);
+Out[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..0cc7d5909c47e4
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,67 @@
+//===- BitcastBuffer.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit in the given sequence of

[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

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



@@ -0,0 +1,66 @@
+//===- BitcastBuffer.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit in the given sequence of bytes.
+static inline bool bitof(const std::byte *B, unsigned BitIndex) {
+  return (B[BitIndex / 8] & (std::byte{1} << (BitIndex % 8))) != std::byte{0};
+}
+
+/// Returns whether \p N is a full byte offset or size.
+static inline bool fullByte(unsigned N) { return N % 8 == 0; }
+
+/// Track what bits have been initialized to known values and which ones
+/// have indeterminate value.
+/// All offsets are in bits.

tbaederr wrote:

Added something like this. In the end I almost didn't use the `Bytes` struct at 
all though.

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-21 Thread via cfe-commits


@@ -931,12 +935,73 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
   return {Template, AliasRhsTemplateArgs};
 }
 
+struct InheritedConstructorDeductionInfo {
+  // Class template for which we are declaring deduction guides
+  // This is `C` in the standard wording
+  TemplateDecl *DerivedClassTemplate;
+
+  // `template CC` in the standard wording
+  // This is the type of template that is substituted in the deduction guide
+  // return type `CC`
+  TypeSourceInfo *CCType;
+};
+
+// Build the type for a deduction guide generated from an inherited constructor
+// C++23 [over.match.class.deduct]p1.10:
+// ... the set contains the guides of A with the return type R
+// of each guide replaced with `typename CC::type` ...
+TypeSourceInfo *buildInheritedConstructorDeductionGuideType(
+Sema &SemaRef, const InheritedConstructorDeductionInfo &Info,
+TypeSourceInfo *SourceGuideTSI) {
+  auto &Context = SemaRef.Context;
+  const auto *FPT = SourceGuideTSI->getType()->getAs();
+  assert(FPT && "Source Guide type should be a FunctionProtoType");
+
+  // This substitution can fail in cases where the source return type
+  // is not dependent and the derived class is not deducible
+  Sema::SFINAETrap Trap(SemaRef);

antangelo wrote:

I have added a FIXME, I can work on a fix for it in a followup but it will 
likely need more invasive changes to the AST in order to preserve the necessary 
information.

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


[clang] [LoongArch] Add conditional compilation for FP approximation intrinsics (PR #117132)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: None (Ami-zhang)


Changes

Introduce a check for `__loongarch_frecipe` macro around the FP approximation 
intrinsic implementation. This ensures that these intrinsics are only included 
when this macro is defined, providing better flexibility and control over the 
usage of FP approximation instructions.

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


3 Files Affected:

- (modified) clang/lib/Headers/larchintrin.h (+22-8) 
- (modified) clang/lib/Headers/lasxintrin.h (+26-24) 
- (modified) clang/lib/Headers/lsxintrin.h (+26-24) 


``diff
diff --git a/clang/lib/Headers/larchintrin.h b/clang/lib/Headers/larchintrin.h
index f4218295919a0d..a1247d12e21f8f 100644
--- a/clang/lib/Headers/larchintrin.h
+++ b/clang/lib/Headers/larchintrin.h
@@ -228,17 +228,31 @@ extern __inline void
   ((void)__builtin_loongarch_ldpte_d((long int)(_1), (_2)))
 #endif
 
-#define __frecipe_s(/*float*/ _1)  
\
-  (float)__builtin_loongarch_frecipe_s((float)_1)
+#ifdef __loongarch_frecipe
+extern __inline float
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frecipe_s(float _1) {
+  return __builtin_loongarch_frecipe_s(_1);
+}
 
-#define __frecipe_d(/*double*/ _1) 
\
-  (double)__builtin_loongarch_frecipe_d((double)_1)
+extern __inline double
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frecipe_d(double _1) {
+  return __builtin_loongarch_frecipe_d(_1);
+}
 
-#define __frsqrte_s(/*float*/ _1)  
\
-  (float)__builtin_loongarch_frsqrte_s((float)_1)
+extern __inline float
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frsqrte_s(float _1) {
+  return __builtin_loongarch_frsqrte_s(_1);
+}
 
-#define __frsqrte_d(/*double*/ _1) 
\
-  (double)__builtin_loongarch_frsqrte_d((double)_1)
+extern __inline double
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frsqrte_d(double _1) {
+  return __builtin_loongarch_frsqrte_d(_1);
+}
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/clang/lib/Headers/lasxintrin.h b/clang/lib/Headers/lasxintrin.h
index c065ea92a2dd52..85020d82829e2a 100644
--- a/clang/lib/Headers/lasxintrin.h
+++ b/clang/lib/Headers/lasxintrin.h
@@ -1726,18 +1726,6 @@ extern __inline
   return (__m256d)__builtin_lasx_xvfrecip_d((v4f64)_1);
 }
 
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
-__lasx_xvfrecipe_s(__m256 _1) {
-  return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1);
-}
-
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
-__lasx_xvfrecipe_d(__m256d _1) {
-  return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1);
-}
-
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
 __lasx_xvfrint_s(__m256 _1) {
@@ -1762,18 +1750,6 @@ extern __inline
   return (__m256d)__builtin_lasx_xvfrsqrt_d((v4f64)_1);
 }
 
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
-__lasx_xvfrsqrte_s(__m256 _1) {
-  return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1);
-}
-
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
-__lasx_xvfrsqrte_d(__m256d _1) {
-  return (__m256d)__builtin_lasx_xvfrsqrte_d((v4f64)_1);
-}
-
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
 __lasx_xvflogb_s(__m256 _1) {
@@ -3866,6 +3842,32 @@ extern __inline
   return (__m256i)__builtin_lasx_xvfcmp_sun_s((v8f32)_1, (v8f32)_2);
 }
 
+#if defined(__loongarch_frecipe)
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
+__lasx_xvfrecipe_s(__m256 _1) {
+  return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
+__lasx_xvfrecipe_d(__m256d _1) {
+  return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
+__lasx_xvfrsqrte_s(__m256 _1) {
+  return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
+__lasx_xvfrsqrte_d(__m256d _1) {
+  return (__m256d)__builtin_lasx_xvfrsqrte_d((v4f64)_1);
+}
+#endif
+
 #define __lasx_xvpickve_d_f(/*__m256d*/ _1, /*ui2*/ _2)
\
   ((__m256d)__builtin_lasx_xvpickve_d_f((v4f64)(_1), (_2)))
 
diff --git a/clang/lib/Headers/lsxintrin.h b/clang/lib/Headers/lsxintrin.h
index f020b0c18f0d29..a9b19223fc4be8 100644
--- a/clang/lib/Headers/lsxintrin.h
+++ b/clang/lib/Headers/lsxintrin.h
@@ -1776,18 +1776,6 

[clang] [LoongArch] Add conditional compilation for FP approximation intrinsics (PR #117132)

2024-11-21 Thread via cfe-commits

https://github.com/Ami-zhang created 
https://github.com/llvm/llvm-project/pull/117132

Introduce a check for `__loongarch_frecipe` macro around the FP approximation 
intrinsic implementation. This ensures that these intrinsics are only included 
when this macro is defined, providing better flexibility and control over the 
usage of FP approximation instructions.

>From 420c38ba2c8234ffe17fc9629ae721570c3c06ef Mon Sep 17 00:00:00 2001
From: Ami-zhang 
Date: Thu, 21 Nov 2024 16:11:41 +0800
Subject: [PATCH] [LoongArch] Add conditional compilation for FP approximation
 intrinsics

Introduce a check for `__loongarch_frecipe` macro around the FP approximation
intrinsic implementation. This ensures that these intrinsics are only
included when this macro is defined, providing better flexibility and
control over the usage of FP approximation instructions.
---
 clang/lib/Headers/larchintrin.h | 30 ++--
 clang/lib/Headers/lasxintrin.h  | 50 +
 clang/lib/Headers/lsxintrin.h   | 50 +
 3 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/clang/lib/Headers/larchintrin.h b/clang/lib/Headers/larchintrin.h
index f4218295919a0d..a1247d12e21f8f 100644
--- a/clang/lib/Headers/larchintrin.h
+++ b/clang/lib/Headers/larchintrin.h
@@ -228,17 +228,31 @@ extern __inline void
   ((void)__builtin_loongarch_ldpte_d((long int)(_1), (_2)))
 #endif
 
-#define __frecipe_s(/*float*/ _1)  
\
-  (float)__builtin_loongarch_frecipe_s((float)_1)
+#ifdef __loongarch_frecipe
+extern __inline float
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frecipe_s(float _1) {
+  return __builtin_loongarch_frecipe_s(_1);
+}
 
-#define __frecipe_d(/*double*/ _1) 
\
-  (double)__builtin_loongarch_frecipe_d((double)_1)
+extern __inline double
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frecipe_d(double _1) {
+  return __builtin_loongarch_frecipe_d(_1);
+}
 
-#define __frsqrte_s(/*float*/ _1)  
\
-  (float)__builtin_loongarch_frsqrte_s((float)_1)
+extern __inline float
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frsqrte_s(float _1) {
+  return __builtin_loongarch_frsqrte_s(_1);
+}
 
-#define __frsqrte_d(/*double*/ _1) 
\
-  (double)__builtin_loongarch_frsqrte_d((double)_1)
+extern __inline double
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__frsqrte_d(double _1) {
+  return __builtin_loongarch_frsqrte_d(_1);
+}
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/clang/lib/Headers/lasxintrin.h b/clang/lib/Headers/lasxintrin.h
index c065ea92a2dd52..85020d82829e2a 100644
--- a/clang/lib/Headers/lasxintrin.h
+++ b/clang/lib/Headers/lasxintrin.h
@@ -1726,18 +1726,6 @@ extern __inline
   return (__m256d)__builtin_lasx_xvfrecip_d((v4f64)_1);
 }
 
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
-__lasx_xvfrecipe_s(__m256 _1) {
-  return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1);
-}
-
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
-__lasx_xvfrecipe_d(__m256d _1) {
-  return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1);
-}
-
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
 __lasx_xvfrint_s(__m256 _1) {
@@ -1762,18 +1750,6 @@ extern __inline
   return (__m256d)__builtin_lasx_xvfrsqrt_d((v4f64)_1);
 }
 
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
-__lasx_xvfrsqrte_s(__m256 _1) {
-  return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1);
-}
-
-extern __inline
-__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
-__lasx_xvfrsqrte_d(__m256d _1) {
-  return (__m256d)__builtin_lasx_xvfrsqrte_d((v4f64)_1);
-}
-
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
 __lasx_xvflogb_s(__m256 _1) {
@@ -3866,6 +3842,32 @@ extern __inline
   return (__m256i)__builtin_lasx_xvfcmp_sun_s((v8f32)_1, (v8f32)_2);
 }
 
+#if defined(__loongarch_frecipe)
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
+__lasx_xvfrecipe_s(__m256 _1) {
+  return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d
+__lasx_xvfrecipe_d(__m256d _1) {
+  return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256
+__lasx_xvfrsqrte_s(__m256 _1) {
+  return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1);
+}
+
+extern __inline
+__attribute__((__gnu_inline__, __always_inline__, __artificial_

[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread Scott Constable via cfe-commits

scottconstable wrote:

@phoebewang @lvwr Please review this PR.

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


[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Scott Constable (scottconstable)


Changes

Kernel Control Flow Integrity (kCFI) is a feature that hardens indirect calls 
by comparing a 32-bit hash of the function pointer's type against a hash of the 
target function's type. If the hashes do not match, the kernel may panic (or 
log the hash check failure, depending on the kernel's configuration). These 
hashes are computed at compile time by applying the xxHash64 algorithm to each 
mangled canonical function (or function pointer) type, then truncating the 
result to 32 bits.

Like any hashing scheme, hash collisions are possible. For example, a commodity 
Linux kernel configured for Ubuntu 24.04 server has 141,617 total indirect call 
targets, with 10,903 unique function types. With a 32-bit kCFI hash, the 
expected number of collisions is 10,903-2^32+2^32*(1-1/(2^32))^10,903 = 
0.01383765 (see https://courses.cs.duke.edu/cps102/spring09/Lectures/L-18.pdf 
for the formula). This number can balloon with the addition of drivers and 
kernel modules.

This patch reduces both the expected number of collisions and the potential 
impact of a collision by augmenting the hash with an arity value that indicates 
how many parameters the function has at the ABI level. Specifically, the patch 
further truncates the kCFI hash down to 29 bits, then concatenates a 3-bit 
arity indicator as follows:

| Arity Indicator | Description |
| --- | --- |
| 0 | 0 parameters |
| 1 | 1 parameter in RDI |
| 2 | 2 parameters in RDI and RSI |
| 3 | 3 parameters in RDI, RSI, and RDX |
| 4 | 4 parameters in RDI, RSI, RDX, and RCX |
| 5 | 5 parameters in RDI, RSI, RDX, RCX, and R8 |
| 6 | 6 parameters in RDI, RSI, RDX, RCX, R8, and R9 |
| 7 | At least one parameter may be passed on the stack |

This scheme enhances security in two ways. First, it prevents a j-arity 
function pointer from being used to call a k-arity function, unless j=k. The 
current 32-bit kCFI hash does not prevent, for example, a 2-arity fptr from 
calling a 3-arity target if the kCFI hashes collide. If this were to happen, 
then potentially malicious stale/dead data in RDX at the call site could 
suddenly become live as the third parameter at the call target.

Second, this scheme reduces the expected number of hash collisions within each 
arity, compared against the expected number of collisions (0.01383765) for the 
32-bit hashing scheme that includes all arities. The table below shows the 
expected number of collisions for each arity, given the number of unique 
indirect callable function types within that arity in the same Ubuntu 24.04 
server kernel discussed above.

| Arity | Unique Indirect Callable Function Types | Number of Expected 
Collisions |
| - | --- | - |
| 0 | 32 |  0.0092 |
| 1 | 2492 |  0.00578125 |
| 2 | 3775 | 0.01326841 |
| 3 | 2547 | 0.00603931 |
| 4 | 1169 | 0.00127162 |
| 5 | 519 | 0.00025038 |
| 6 | 221 | 0.4528 |
| 7 | 148 | 0.2026 |

One additional benefit of this patch is that it can benefit other CFI 
approaches that build on kCFI, such as FineIBT. For example, this proposed 
enhancement to FineIBT must be able to infer (at kernel init time) which 
registers are live at an indirect call target: 
https://lkml.org/lkml/2024/9/27/982. If the arity bits are available in the 
kCFI type ID, then this information is trivial to infer.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+28-3) 
- (modified) clang/test/CodeGen/kcfi-normalize.c (+12-6) 
- (modified) clang/test/CodeGen/kcfi.c (+19-3) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b854eeb62a80ce..7cc6f120ec39a9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2183,7 +2183,8 @@ llvm::ConstantInt 
*CodeGenModule::CreateCrossDsoCfiTypeId(llvm::Metadata *MD) {
 }
 
 llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) {
-  if (auto *FnType = T->getAs())
+  auto *FnType = T->getAs();
+  if (FnType)
 T = getContext().getFunctionType(
 FnType->getReturnType(), FnType->getParamTypes(),
 FnType->getExtProtoInfo().withExceptionSpec(EST_None));
@@ -2196,8 +2197,32 @@ llvm::ConstantInt 
*CodeGenModule::CreateKCFITypeId(QualType T) {
   if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
 Out << ".normalized";
 
-  return llvm::ConstantInt::get(Int32Ty,
-
static_cast(llvm::xxHash64(OutName)));
+  uint32_t OutHash = static_cast(llvm::xxHash64(OutName));
+  const auto &Triple = getTarget().getTriple();
+  if (Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be pa

[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-21 Thread via cfe-commits


@@ -122,3 +122,25 @@ namespace PR10801 {
 thingy(b);
   }
 }
+
+namespace GH63009 {
+struct S1 {
+  [[noreturn]] S1();
+};
+
+struct S2 {
+  [[noreturn]] ~S2();
+};
+
+int foo();
+
+int test_1() {
+  S1 s1;
+  foo();
+}
+
+int test_2() {
+  S2 s2;
+  foo();

Sirraide wrote:

Hmm, I’d expect these two functions to raise a `-Wmissing-noreturn` warning. 
That’s probably something we should investigate, but that doesn’t have to be in 
this pr imo since I’d say it’s more important that we *don’t* issue a 
`-Wreturn-type` warning here.

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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-21 Thread via cfe-commits


@@ -4892,16 +4898,17 @@ CFGBlock 
*CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
   return Visit(E->getSubExpr(), asc);
 }
 
-CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
+CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   AddStmtChoice asc) {
   // If the constructor takes objects as arguments by value, we need to 
properly
   // construct these objects. Construction contexts we find here aren't for the
   // constructor C, they're for its arguments only.
-  findConstructionContextsForArguments(C);
+  findConstructionContextsForArguments(E);
 
-  autoCreateBlock();
-  appendConstructor(Block, C);
-  return VisitChildren(C);
+  createConstructorBlock(E->getConstructor());
+  appendConstructor(Block, E);

Sirraide wrote:

I do like the addition of `createConstructorBlock()`. Now that it exists, I 
noticed the only two calls to `appendConstructor()` are right after a call to 
`createConstructorBlock()`. I think we should just inline `appendConstructor()` 
into `createConstructorBlock()` at this point.

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


[clang] [lld] [llvm] [RISCV] Make A implies Zaamo and Zalrsc (PR #116907)

2024-11-21 Thread Jim Lin via cfe-commits

https://github.com/tclin914 updated 
https://github.com/llvm/llvm-project/pull/116907

>From 08523139b789c836b22677f8e16b79910de601e4 Mon Sep 17 00:00:00 2001
From: Jim Lin 
Date: Wed, 20 Nov 2024 10:31:58 +0800
Subject: [PATCH 1/4] [RISCV] Make A implies Zaamo and Zalrsc

Ref: https://github.com/riscv/riscv-isa-manual/blob/main/src/a-st-ext.adoc.
---
 .../CodeGen/RISCV/riscv-func-attr-target.c| 20 +-
 lld/test/ELF/lto/riscv-attributes.ll  |  6 +--
 lld/test/ELF/riscv-attributes.s   | 16 
 llvm/lib/Target/RISCV/RISCVFeatures.td| 39 ++-
 llvm/test/CodeGen/RISCV/attributes.ll | 20 +-
 llvm/test/MC/RISCV/attribute-arch.s   | 14 +++
 llvm/test/MC/RISCV/attribute.s|  4 +-
 7 files changed, 60 insertions(+), 59 deletions(-)

diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c 
b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
index aeddbc4ebf6895..3e9c1d9229a66b 100644
--- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
+++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -66,16 +66,16 @@ void test_rvv_f64_type_w_zve64d() {
 }
 
 //.
-// CHECK: attributes #0 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zifencei,+zmmul,-relax,-zbb,-zfa"
 }
-// CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" 
"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 "tune-cpu"="generic-rv64" }
-// CHECK: attributes #2 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,+zmmul,-relax,-zfa"
 }
-// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zbb,+zicond,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
+// CHECK: attributes #0 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zifencei,+zmmul,-relax,-zbb,-zfa"
 }
+// CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" 
"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 "tune-cpu"="generic-rv64" }
+// CHECK: attributes #2 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa"
 }
+// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zaamo,+zalrsc,+zbb,+zicond,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
 // Make sure we append negative features if we override the arch
-// CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
+// CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
 // CHECK: attributes #5 = { 
{{.*}}"target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
-// CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,+zmmul,-relax,-zfa"
 }
+// CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa"
 }
 // CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
-// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
-// CHECK: attributes #9 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zicsr,+zifencei,+zmmul,+zve32x,+zvl32b,-relax,-zbb,-zfa"
 }
-// CHECK: attributes #11 = { 
{{.*}}"target-features"="+64bit,+a,+f,+m,+save-restore,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zvl32b,-relax,-zbb,-zfa"
 }
-// CHECK: attributes #12 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 }
+// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" 
"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
+// CHECK: attributes #9 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32x,+zvl32b,-relax,-zbb,-zfa"
 }
+// CHECK: attributes #11 = { 
{{.*}}"target-features"="+64bit,+a,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zvl32b,-relax,-zbb,-zfa"
 }
+// CHECK: attributes #12 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,

[clang] [clang][ExprConst] Reject field access with nullptr base (PR #113885)

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


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

>From 3005da1e2d25f124466743e5f7a5fc5b969f5740 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 28 Oct 2024 10:04:46 +0100
Subject: [PATCH 1/2] [clang][ExprConst] Reject field access with nullptr base

---
 clang/lib/AST/ExprConstant.cpp   | 6 +++---
 clang/test/CXX/expr/expr.const/p2-0x.cpp | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 33206f5cda2021..9215e79bd52169 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3261,8 +3261,8 @@ static bool HandleLValueDirectBase(EvalInfo &Info, const 
Expr *E, LValue &Obj,
 RL = &Info.Ctx.getASTRecordLayout(Derived);
   }
 
-  Obj.getLValueOffset() += RL->getBaseClassOffset(Base);
   Obj.addDecl(Info, E, Base, /*Virtual*/ false);
+  Obj.getLValueOffset() += RL->getBaseClassOffset(Base);
   return true;
 }
 
@@ -3286,8 +3286,8 @@ static bool HandleLValueBase(EvalInfo &Info, const Expr 
*E, LValue &Obj,
   // Find the virtual base class.
   if (DerivedDecl->isInvalidDecl()) return false;
   const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(DerivedDecl);
-  Obj.getLValueOffset() += Layout.getVBaseClassOffset(BaseDecl);
   Obj.addDecl(Info, E, BaseDecl, /*Virtual*/ true);
+  Obj.getLValueOffset() += Layout.getVBaseClassOffset(BaseDecl);
   return true;
 }
 
@@ -3330,8 +3330,8 @@ static bool HandleLValueMember(EvalInfo &Info, const Expr 
*E, LValue &LVal,
   }
 
   unsigned I = FD->getFieldIndex();
-  LVal.adjustOffset(Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I)));
   LVal.addDecl(Info, E, FD);
+  LVal.adjustOffset(Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I)));
   return true;
 }
 
diff --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp 
b/clang/test/CXX/expr/expr.const/p2-0x.cpp
index 767eee1c74f054..67160ba571f33c 100644
--- a/clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -188,7 +188,7 @@ namespace UndefinedBehavior {
 
   namespace Ptr {
 struct A {};
-struct B : A { int n; };
+struct B : A { int n; int m; };
 B a[3][3];
 constexpr B *p = a[0] + 4; // expected-error {{constant expression}} 
expected-note {{element 4 of array of 3 elements}}
 B b = {};
@@ -204,6 +204,7 @@ namespace UndefinedBehavior {
 static_assert((A*)nb == 0, "");
 static_assert((B*)na == 0, "");
 constexpr const int &nf = nb->n; // expected-error {{constant expression}} 
expected-note {{cannot access field of null pointer}}
+constexpr const int &mf = nb->m; // expected-error {{constant expression}} 
expected-note {{cannot access field of null pointer}}
 constexpr const int *np1 = (int*)nullptr + 0; // ok
 constexpr const int *np2 = &(*(int(*)[4])nullptr)[0]; // ok
 constexpr const int *np3 = &(*(int(*)[4])nullptr)[2]; // expected-error 
{{constant expression}} expected-note {{cannot perform pointer arithmetic on 
null pointer}}

>From ba67f3b2447659eb55d1835de9d9a548d966fe66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 21 Nov 2024 10:11:23 +0100
Subject: [PATCH 2/2] Add release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 999c88455b64a5..04ed3804d642e4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,17 @@ C++ Specific Potentially Breaking Changes
 // Now diagnoses with an error.
 void f(int& i [[clang::lifetimebound]]);
 
+- Clang now rejects all field accesses on null pointers in constant 
expressions. The following code
+  used to work but will now be rejected:
+
+  .. code-block:: c++
+
+struct S { int a; int b; };
+constexpr const int *p = &((S*)nullptr)->b;
+
+  Previously, this code was erroneously accepted.
+
+
 ABI Changes in This Version
 ---
 

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


[clang] Rework attr-target-x86 test (PR #117091)

2024-11-21 Thread Phoebe Wang via cfe-commits

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

Well done!

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


[clang] [clang][ARM] disable frame pointers by default for bare metal ARM targets (PR #117140)

2024-11-21 Thread Ties Stuij via cfe-commits

https://github.com/stuij updated 
https://github.com/llvm/llvm-project/pull/117140

>From 4a85a0cd98bf328f31465d47c56640abdf7ec08c Mon Sep 17 00:00:00 2001
From: Ties Stuij 
Date: Fri, 15 Nov 2024 13:19:08 +
Subject: [PATCH 1/2] [clang][ARM] disable frame pointers by default for bare
 metal ARM targets

because:
- This brings Clang in line with GCC for which this is the default for ARM
- It frees up a register, so performance increase, especially on Thumb/6-M
- It will also decrease code size
---
 clang/lib/Driver/ToolChains/BareMetal.cpp  |  8 +-
 clang/lib/Driver/ToolChains/BareMetal.h|  2 ++
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  5 
 clang/test/Driver/frame-pointer-elim.c | 29 ++
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f9a73f60973e4c..13b510e7e70994 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -128,8 +128,11 @@ BareMetal::BareMetal(const Driver &D, const llvm::Triple 
&Triple,
   }
 }
 
+namespace clang {
+namespace driver {
+namespace toolchains {
 /// Is the triple {arm,armeb,thumb,thumbeb}-none-none-{eabi,eabihf} ?
-static bool isARMBareMetal(const llvm::Triple &Triple) {
+bool isARMBareMetal(const llvm::Triple &Triple) {
   if (Triple.getArch() != llvm::Triple::arm &&
   Triple.getArch() != llvm::Triple::thumb &&
   Triple.getArch() != llvm::Triple::armeb &&
@@ -148,6 +151,9 @@ static bool isARMBareMetal(const llvm::Triple &Triple) {
 
   return true;
 }
+} // namespace clang
+} // namespace driver
+} // namespace clang
 
 /// Is the triple {aarch64.aarch64_be}-none-elf?
 static bool isAArch64BareMetal(const llvm::Triple &Triple) {
diff --git a/clang/lib/Driver/ToolChains/BareMetal.h 
b/clang/lib/Driver/ToolChains/BareMetal.h
index b385c8cf76aab0..ae09bcedd78a28 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.h
+++ b/clang/lib/Driver/ToolChains/BareMetal.h
@@ -19,6 +19,8 @@ namespace driver {
 
 namespace toolchains {
 
+bool isARMBareMetal(const llvm::Triple &Triple);
+
 class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
 public:
   BareMetal(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 8d977149e62485..8d54d0a8649cc9 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -19,6 +19,7 @@
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
 #include "Arch/X86.h"
+#include "BareMetal.h"
 #include "HIPAMD.h"
 #include "Hexagon.h"
 #include "MSP430.h"
@@ -151,6 +152,10 @@ static bool useFramePointerForTargetByDefault(const 
llvm::opt::ArgList &Args,
 }
   }
 
+  if (toolchains::isARMBareMetal(Triple)) {
+return false;
+  }
+
   return true;
 }
 
diff --git a/clang/test/Driver/frame-pointer-elim.c 
b/clang/test/Driver/frame-pointer-elim.c
index cdedcc7ae4c89f..667c47b34bc703 100644
--- a/clang/test/Driver/frame-pointer-elim.c
+++ b/clang/test/Driver/frame-pointer-elim.c
@@ -162,5 +162,34 @@
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: not %clang -### --target=riscv64-linux-android -mbig-endian -O1 -S %s 
2>&1 | \
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+
+// On ARM backend bare metal targets, frame pointer is omitted
+// RUN: %clang -### --target=arm-arm-none-eabi -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabi -S -fno-omit-frame-pointer %s 
2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S -fno-omit-frame-pointer %s 
2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### --target=arm-arm-none-eabi -S -O1 %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S -O1 %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabi -S -O1 -fno-omit-frame-pointer 
%s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S -O1 
-fno-omit-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+
+// AArch64 bare metal targets behave like hosted targets
+// RUN: %clang -### --target=aarch64-none-elf -S %s 2>&1 |  \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+// RUN: %clang -### --target=aarch64-none-elf -S -O1 %s 2>&1 |  \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+// RUN: %clang -### --target=aarch64-none-elf -S -fno-omit-frame-pointer %s 
2>&1 |  \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+// RUN: %clang -### --target=aarch64-none-elf -S -O1 -fno-omit-frame-pointer 
%s 2>&1 |  \
+// RUN:   FileCheck --check-prefix=KE

[clang] [NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8… (PR #114804)

2024-11-21 Thread via cfe-commits

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


[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building 
`clang-tools-extra,clang` at step 4 "build".

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


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

```
Step 4 (build) failure: build (failure)
...
431.158 [1335/10/5036] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectVersion.cpp.o
431.159 [1335/9/5037] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectType.cpp.o
431.167 [1335/8/5038] Building CXX object 
tools/lldb/source/Core/CMakeFiles/lldbCore.dir/AddressRange.cpp.o
431.167 [1335/7/5039] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandOptionsProcessAttach.cpp.o
431.167 [1335/6/5040] Building CXX object 
tools/lldb/source/Core/CMakeFiles/lldbCore.dir/AddressRangeListImpl.cpp.o
431.170 [1335/5/5041] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandOptionArgumentTable.cpp.o
431.173 [1335/4/5042] Building CXX object 
tools/lldb/source/Core/CMakeFiles/lldbCore.dir/Address.cpp.o
431.181 [1335/3/5043] Building CXX object 
tools/lldb/source/Core/CMakeFiles/lldbCore.dir/AddressResolver.cpp.o
431.182 [1335/2/5044] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandOptionsProcessLaunch.cpp.o
440.696 [1335/1/5045] Building CXX object 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
FAILED: 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/source/Commands
 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/source/Commands
 -I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/include 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/include 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/llvm/include 
-I/usr/include/python3.10 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/llvm/../clang/include
 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/../clang/include
 -I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/source 
-I/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/source 
-isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-unknown-pragmas -Wno-strict-aliasing 
-Wno-vla-extension -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -MF 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o.d
 -o 
tools/lldb/source/Commands/CMakeFiles/lldbCommands.dir/CommandObjectTarget.cpp.o
 -c 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
../llvm-project/lldb/source/Commands/CommandObjectTarget.cpp:2203:14: error: no 
matching member function for call to 'createDiagnostics'
 2203 | compiler.createDiagnostics();
  | ~^
../llvm-project/clang/include/clang/Frontend/CompilerInstance.h:687:8: note: 
candidate function not viable: requires at least argument 'VFS', but no 
arguments were provided
  687 |   void createDiagnostics(llvm::vfs::FileSystem &VFS,
  |^ ~~~
  688 |  DiagnosticConsumer *Client = nullptr,
  |  ~
  689 |  bool ShouldOwnClient = true);
  |  ~~~
../llvm-project/clang/include/clang/Frontend/CompilerInstance.h:710:3: note: 
candidate function not viable: requires at least 2 arguments, but 0 were 
provided
  710 |   createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
  |   ^ 
  711 | DiagnosticConsumer *Client = nullptr,
  | ~
  712 | 

[clang] ddb62d2 - [clang] constexpr built-in reduce `or` and `xor` function. (#116976)

2024-11-21 Thread via cfe-commits

Author: c8ef
Date: 2024-11-21T21:02:29+08:00
New Revision: ddb62d26cb988b6dfee545dcbd7412d297d9b99b

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

LOG: [clang] constexpr built-in reduce `or` and `xor` function. (#116976)

Part of #51787.
Follow up of #116822.

This patch adds constexpr support for the built-in reduce `or` and `xor`
functions.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.td
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/constant_builtins_vector.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index ff8e841ee53a2b..3c9078bcdf8118 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -732,6 +732,10 @@ at the end to the next power of 2.
 
 These reductions support both fixed-sized and scalable vector types.
 
+The integer reduction intrinsics, including ``__builtin_reduce_add``,
+``__builtin_reduce_mul``, ``__builtin_reduce_and``, ``__builtin_reduce_or``,
+and ``__builtin_reduce_xor``, can be called in a ``constexpr`` context.
+
 Example:
 
 .. code-block:: c++

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49464e457da681..10e27a4f4bc46f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_add`` function can now be used in constant expressions.
 - ``__builtin_reduce_mul`` function can now be used in constant expressions.
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
+- ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index aa65f94e68f9c3..daf90b9570160e 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1486,13 +1486,13 @@ def ReduceMinimum : Builtin {
 
 def ReduceXor : Builtin {
   let Spellings = ["__builtin_reduce_xor"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def ReduceOr : Builtin {
   let Spellings = ["__builtin_reduce_or"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 33206f5cda2021..261de141637020 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13529,7 +13529,9 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 
   case Builtin::BI__builtin_reduce_add:
   case Builtin::BI__builtin_reduce_mul:
-  case Builtin::BI__builtin_reduce_and: {
+  case Builtin::BI__builtin_reduce_and:
+  case Builtin::BI__builtin_reduce_or:
+  case Builtin::BI__builtin_reduce_xor: {
 APValue Source;
 if (!EvaluateAsRValue(Info, E->getArg(0), Source))
   return false;
@@ -13558,6 +13560,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 Reduced &= Source.getVectorElt(EltNum).getInt();
 break;
   }
+  case Builtin::BI__builtin_reduce_or: {
+Reduced |= Source.getVectorElt(EltNum).getInt();
+break;
+  }
+  case Builtin::BI__builtin_reduce_xor: {
+Reduced ^= Source.getVectorElt(EltNum).getInt();
+break;
+  }
   }
 }
 

diff  --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index 7063c290479f6c..e84d09b24672b4 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -777,3 +777,23 @@ 
static_assert(__builtin_reduce_and((vector4int){(int)~0x, (int)~0x22
 static_assert(__builtin_reduce_and((vector4long){(long 
long)~0xL, (long long)~0xL, (long 
long)~0xL, (long long)-1}) == 0xL);
 static_assert(__builtin_reduce_and((vector4uint){0xU, 0xU, 
0xU, 0xU}) == 0U);
 static_assert(__builtin_reduce_and((vector4ulong){0xUL, 
0xUL, 0xUL, 0xUL}) == 0L);
+
+static_assert(__builtin_reduce_or((vector4char){}) == 0);
+static_assert(__builtin_reduce_or((vector4char){(char)0x11, (char)0x22, 
(char)0x44, (char)0x88}) == (char)0xFF);
+static_assert(__builtin_reduce_or((vector4short){(short)0x, (short)0x, 
(short)0x, (short)0x}) == (short)0x);
+s

[clang] [clang] constexpr built-in reduce `or` and `xor` function. (PR #116976)

2024-11-21 Thread via cfe-commits

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-21 Thread Sudharsan Veeravalli via cfe-commits

https://github.com/svs-quic created 
https://github.com/llvm/llvm-project/pull/117169

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read and write 
CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

>From 92a3e2e9c44c03093e6050b92b938fd2a0d6886c Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Wed, 20 Nov 2024 13:24:07 +0530
Subject: [PATCH] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read
and write CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
---
 .../Driver/print-supported-extensions-riscv.c |  1 +
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  3 +-
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td| 10 +
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  1 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 44 +++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  4 ++
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +
 llvm/test/MC/RISCV/xqcicsr-invalid.s  | 27 
 llvm/test/MC/RISCV/xqcicsr-valid.s| 19 
 .../TargetParser/RISCVISAInfoTest.cpp |  1 +
 12 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..a0b93621d2fcdc 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 1317221448ea5b..a656ccd00ed482 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -329,6 +329,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
+``experimental-xqcicsr``
+  LLVM implements the `0.2 extension specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1ba3672baeed88..89e7c048592f34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-21 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-mc
@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang-driver

Author: Sudharsan Veeravalli (svs-quic)


Changes

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read and write 
CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

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


12 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/docs/ReleaseNotes.md (+2-1) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+10) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+1) 
- (added) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+44) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+4) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2) 
- (added) llvm/test/MC/RISCV/xqcicsr-invalid.s (+27) 
- (added) llvm/test/MC/RISCV/xqcicsr-valid.s (+19) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..a0b93621d2fcdc 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 1317221448ea5b..a656ccd00ed482 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -329,6 +329,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
+``experimental-xqcicsr``
+  LLVM implements the `0.2 extension specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1ba3672baeed88..89e7c048592f34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3977816ebdd49c..ed87c9604f38b1 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1338,6 +1338,16 @@ def HasVendorXwchc
   AssemblerPredicate<(all_of FeatureVendorXwchc),
  "'Xwchc' (WCH/QingKe additional compressed opcodes)">;
 
+// Qualcomm Extension(s)
+
+def FeatureVe

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sudharsan Veeravalli (svs-quic)


Changes

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read and write 
CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

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


12 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/docs/ReleaseNotes.md (+2-1) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+10) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+1) 
- (added) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+44) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+4) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2) 
- (added) llvm/test/MC/RISCV/xqcicsr-invalid.s (+27) 
- (added) llvm/test/MC/RISCV/xqcicsr-valid.s (+19) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..a0b93621d2fcdc 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 1317221448ea5b..a656ccd00ed482 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -329,6 +329,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
+``experimental-xqcicsr``
+  LLVM implements the `0.2 extension specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1ba3672baeed88..89e7c048592f34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3977816ebdd49c..ed87c9604f38b1 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1338,6 +1338,16 @@ def HasVendorXwchc
   AssemblerPredicate<(all_of FeatureVendorXwchc),
  "'Xwchc' (WCH/QingKe additional compressed opcodes)">;
 
+// Qualcomm Extension(s)
+
+def FeatureVendorXqcicsr
+: RISCVExperimentalExtension<"xqcicsr", 0, 2,
+   

[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-21 Thread Timm Baeder via cfe-commits


@@ -1138,7 +1138,7 @@ void 
Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
 
   {
 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
-PerformPendingInstantiations();
+PerformPendingInstantiations(false, true);

tbaederr wrote:

```suggestion
PerformPendingInstantiations(/*LocalOnly=*/false, /*AtEndOfTU=*/true);
```

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


[clang] [analyzer] Disable graph-trim-interval by default (PR #111843)

2024-11-21 Thread Donát Nagy via cfe-commits

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


[clang] [clang][ExprConst] Reject field access with nullptr base (PR #113885)

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


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


[clang] 685e41e - [clang][ExprConst] Reject field access with nullptr base (#113885)

2024-11-21 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-11-21T15:53:11+01:00
New Revision: 685e41e7774386b78c9527ebf70d3552aef383d7

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

LOG: [clang][ExprConst] Reject field access with nullptr base (#113885)

Reject them if the base is null, not only if the entire pointer is null.

Fixes #113821

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 084be14952cfa3..8c81de341937ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,17 @@ C++ Specific Potentially Breaking Changes
 // Now diagnoses with an error.
 void f(int& i [[clang::lifetimebound]]);
 
+- Clang now rejects all field accesses on null pointers in constant 
expressions. The following code
+  used to work but will now be rejected:
+
+  .. code-block:: c++
+
+struct S { int a; int b; };
+constexpr const int *p = &((S*)nullptr)->b;
+
+  Previously, this code was erroneously accepted.
+
+
 ABI Changes in This Version
 ---
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 261de141637020..c6a210459240a8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3261,8 +3261,8 @@ static bool HandleLValueDirectBase(EvalInfo &Info, const 
Expr *E, LValue &Obj,
 RL = &Info.Ctx.getASTRecordLayout(Derived);
   }
 
-  Obj.getLValueOffset() += RL->getBaseClassOffset(Base);
   Obj.addDecl(Info, E, Base, /*Virtual*/ false);
+  Obj.getLValueOffset() += RL->getBaseClassOffset(Base);
   return true;
 }
 
@@ -3286,8 +3286,8 @@ static bool HandleLValueBase(EvalInfo &Info, const Expr 
*E, LValue &Obj,
   // Find the virtual base class.
   if (DerivedDecl->isInvalidDecl()) return false;
   const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(DerivedDecl);
-  Obj.getLValueOffset() += Layout.getVBaseClassOffset(BaseDecl);
   Obj.addDecl(Info, E, BaseDecl, /*Virtual*/ true);
+  Obj.getLValueOffset() += Layout.getVBaseClassOffset(BaseDecl);
   return true;
 }
 
@@ -3330,8 +3330,8 @@ static bool HandleLValueMember(EvalInfo &Info, const Expr 
*E, LValue &LVal,
   }
 
   unsigned I = FD->getFieldIndex();
-  LVal.adjustOffset(Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I)));
   LVal.addDecl(Info, E, FD);
+  LVal.adjustOffset(Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I)));
   return true;
 }
 

diff  --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp 
b/clang/test/CXX/expr/expr.const/p2-0x.cpp
index 767eee1c74f054..67160ba571f33c 100644
--- a/clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -188,7 +188,7 @@ namespace UndefinedBehavior {
 
   namespace Ptr {
 struct A {};
-struct B : A { int n; };
+struct B : A { int n; int m; };
 B a[3][3];
 constexpr B *p = a[0] + 4; // expected-error {{constant expression}} 
expected-note {{element 4 of array of 3 elements}}
 B b = {};
@@ -204,6 +204,7 @@ namespace UndefinedBehavior {
 static_assert((A*)nb == 0, "");
 static_assert((B*)na == 0, "");
 constexpr const int &nf = nb->n; // expected-error {{constant expression}} 
expected-note {{cannot access field of null pointer}}
+constexpr const int &mf = nb->m; // expected-error {{constant expression}} 
expected-note {{cannot access field of null pointer}}
 constexpr const int *np1 = (int*)nullptr + 0; // ok
 constexpr const int *np2 = &(*(int(*)[4])nullptr)[0]; // ok
 constexpr const int *np3 = &(*(int(*)[4])nullptr)[2]; // expected-error 
{{constant expression}} expected-note {{cannot perform pointer arithmetic on 
null pointer}}



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


[clang] [clang][SME] Ignore flatten for callees with mismatched streaming attributes (PR #116391)

2024-11-21 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/116391

>From 90daf9c544bcb776c8a68ad504ba5eda50eafe8a Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Fri, 15 Nov 2024 14:35:41 +
Subject: [PATCH 1/3] [clang][SME] Ignore flatten for callees mismatched
 streaming attributes

If `__attribute__((flatten))` is used on a function don't inline any
callees with incompatible streaming attributes. Without this check,
clang may produce incorrect code when `flatten` is used in code with
streaming functions.

Note: The docs for flatten say it can be ignored when inlining is
impossible: "causes calls within the attributed function to be inlined
unless it is impossible to do so".
---
 clang/lib/CodeGen/CGCall.cpp  | 11 ++-
 clang/lib/CodeGen/TargetInfo.h|  9 +++
 clang/lib/CodeGen/Targets/AArch64.cpp | 64 +---
 .../AArch64/sme-flatten-streaming-attrs.c | 74 +++
 4 files changed, 143 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/AArch64/sme-flatten-streaming-attrs.c

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 8f4f5d3ed81601..b8a968fdf4e9eb 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5112,9 +5112,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 
   // Some architectures (such as x86-64) have the ABI changed based on
   // attribute-target/features. Give them a chance to diagnose.
-  CGM.getTargetCodeGenInfo().checkFunctionCallABI(
-  CGM, Loc, dyn_cast_or_null(CurCodeDecl),
-  dyn_cast_or_null(TargetDecl), CallArgs, RetTy);
+  const FunctionDecl *CallerDecl = dyn_cast_or_null(CurCodeDecl);
+  const FunctionDecl *CalleeDecl = dyn_cast_or_null(TargetDecl);
+  CGM.getTargetCodeGenInfo().checkFunctionCallABI(CGM, Loc, CallerDecl,
+  CalleeDecl, CallArgs, RetTy);
 
   // 1. Set up the arguments.
 
@@ -5705,7 +5706,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // FIXME: should this really take priority over __try, below?
   if (CurCodeDecl && CurCodeDecl->hasAttr() &&
   !InNoInlineAttributedStmt &&
-  !(TargetDecl && TargetDecl->hasAttr())) {
+  !(TargetDecl && TargetDecl->hasAttr()) &&
+  !CGM.getTargetCodeGenInfo().wouldInliningViolateFunctionCallABI(
+  CallerDecl, CalleeDecl)) {
 Attrs =
 Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::AlwaysInline);
   }
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 373f8b8a80fdb1..23ff476b0e33ce 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -98,6 +98,15 @@ class TargetCodeGenInfo {
 const CallArgList &Args,
 QualType ReturnType) const {}
 
+  /// Returns true if inlining the function call would produce incorrect code
+  /// for the current target and should be ignored (even with the always_inline
+  /// or flatten attributes).
+  virtual bool
+  wouldInliningViolateFunctionCallABI(const FunctionDecl *Caller,
+  const FunctionDecl *Callee) const {
+return false;
+  }
+
   /// Determines the size of struct _Unwind_Exception on this platform,
   /// in 8-bit units.  The Itanium ABI defines this as:
   ///   struct _Unwind_Exception {
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 9320c6ef06efab..a9ea84b6575f92 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -177,6 +177,9 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
 const FunctionDecl *Callee, const CallArgList 
&Args,
 QualType ReturnType) const override;
 
+  bool wouldInliningViolateFunctionCallABI(
+  const FunctionDecl *Caller, const FunctionDecl *Callee) const override;
+
 private:
   // Diagnose calls between functions with incompatible Streaming SVE
   // attributes.
@@ -1143,12 +1146,20 @@ void AArch64TargetCodeGenInfo::checkFunctionABI(
   }
 }
 
-void AArch64TargetCodeGenInfo::checkFunctionCallABIStreaming(
-CodeGenModule &CGM, SourceLocation CallLoc, const FunctionDecl *Caller,
-const FunctionDecl *Callee) const {
-  if (!Caller || !Callee || !Callee->hasAttr())
-return;
+enum class ArmStreamingInlinability : uint8_t {
+  Ok = 0,
+  IncompatibleStreamingModes = 1,
+  MismatchedStreamingCompatibility = 1 << 1,
+  CalleeHasNewZA = 1 << 2,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/CalleeHasNewZA),
+};
 
+/// Determines if there are any streaming ABI issues with inlining \p Callee
+/// into \p Caller. Returns the issues in the ArmStreamingInlinability bit enum
+/// (multiple bits can be set).
+static ArmStreamingInlinability
+GetArmStreamingInlinability(const FunctionDecl *Caller,
+  

[clang] Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

2024-11-21 Thread Oleksandr T. via cfe-commits

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

>From 5e24d212f797b5fa1b6da1526c807046373d3c21 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:13:17 +0200
Subject: [PATCH 1/3] [Clang] skip default argument instantiation for
 non-defining friend declarations to meet [dcl.fct.default] p4

---
 clang/docs/ReleaseNotes.rst   |  2 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 ++
 clang/test/CXX/temp/temp.res/p4.cpp   | 43 +++
 3 files changed, 49 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0c43ff11f7bae..e8cf6fc50a1290 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -636,6 +636,8 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
+  friend declarations. (#GH113324).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..200519c71c57ab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,10 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  if (FD->getFriendObjectKind() != Decl::FOK_None &&
+  !FD->getTemplateInstantiationPattern())
+return true;
+
   // Instantiate the expression.
   //
   // FIXME: Pass in a correct Pattern argument, otherwise
diff --git a/clang/test/CXX/temp/temp.res/p4.cpp 
b/clang/test/CXX/temp/temp.res/p4.cpp
index f54d8649f5da88..cf6c45b4c351c5 100644
--- a/clang/test/CXX/temp/temp.res/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/p4.cpp
@@ -185,3 +185,46 @@ template struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template  struct S1 {
+  friend void f1(S1, int = 0); // expected-error {{friend declaration 
specifying a default argument must be a definition}}
+  friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+template  using alias = int;
+template  struct S2 {
+  // FIXME: We miss diagnosing the default argument instantiation failure
+  // (forming reference to void)
+  friend void f3(S2, int a = alias(1)); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+struct S3 {
+  friend void f4(S3, int = 42) { }
+};
+
+template  using __enable_if_t = int;
+template  struct S4 {
+  static const int value = v;
+};
+struct S5 {
+  template <__enable_if_t::value, int> = 0>
+  S5(const char *);
+};
+struct S6 {
+  template 
+  friend void f5(int, S6, a, b, S5 = "") { }
+};
+
+void test() {
+  f1(S1<>{});
+  f2(S1<>{});
+  f3(S2());
+
+  S3 s3;
+  f4(s3);
+
+  S6 s6;
+  auto result = f5(0, s6, [] {}, [] {}); // expected-error {{variable has 
incomplete type 'void}}
+}
+} // namespace GH113324

>From 3ad3b6c5f35730be32f4f6ba2dc8d19f53be0442 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:53:39 +0200
Subject: [PATCH 2/3] update comments

---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 200519c71c57ab..0bbab95001ad8e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,13 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  // FIXME: We don't track member specialization info for non-defining
+  // friend declarations, so we will not be able to later find the function
+  // pattern. As a workaround, don't instantiate the default argument in this
+  // case. This is correct per wording and only an error recovery issue, as per
+  // [dcl.fct.default]p4:
+  //   if a friend declaration D specifies a default argument expression,
+  //   that declaration shall be a definition.
   if (FD->getFriendObjectKind() != Decl::FOK_None &&
   !FD->getTemplateInstantiationPattern())
 return true;

>From 09215dea0212368ef54956d8464788cc4b88cc02 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 21 Nov 2024 16:56:11 +0200
Subject: [PATCH 3/3] move cases that cause code generation failures to the
 appropriate folder

---
 clang/test/CXX/temp/temp.res/p4.cpp | 23

[clang] [AMDGPU] Do not allow the region address space to be converted to generic (PR #117171)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

Summary:
Previous changes relaxed the address space rules based on what the
target says about them. This accidentally included the AS(2) region as
convertible to generic. Simply check for AS(2) and reject it.


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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/AMDGPU.h (+2-1) 
- (modified) clang/test/Sema/amdgcn-address-spaces.c (+1-1) 


``diff
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index db7a095ba2a4fe..ea4189cdea47da 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -120,7 +120,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   toTargetAddressSpace(A) == llvm::AMDGPUAS::FLAT_ADDRESS)) &&
 isTargetAddressSpace(B) &&
 toTargetAddressSpace(B) >= llvm::AMDGPUAS::FLAT_ADDRESS &&
-toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS);
+toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS &&
+toTargetAddressSpace(B) != llvm::AMDGPUAS::REGION_ADDRESS);
   }
 
   uint64_t getMaxPointerWidth() const override {
diff --git a/clang/test/Sema/amdgcn-address-spaces.c 
b/clang/test/Sema/amdgcn-address-spaces.c
index 50c12993ac69b8..70545db920c807 100644
--- a/clang/test/Sema/amdgcn-address-spaces.c
+++ b/clang/test/Sema/amdgcn-address-spaces.c
@@ -9,7 +9,7 @@
 #define _AS999 __attribute__((address_space(999)))
 
 void *p1(void _AS1 *p) { return p; }
-void *p2(void _AS2 *p) { return p; }
+void *p2(void _AS2 *p) { return p; } // expected-error {{returning '_AS2 void 
*' from a function with result type 'void *' changes address space of pointer}}
 void *p3(void _AS3 *p) { return p; }
 void *p4(void _AS4 *p) { return p; }
 void *p5(void _AS5 *p) { return p; }

``




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


[clang] [AMDGPU] Do not allow the region address space to be converted to generic (PR #117171)

2024-11-21 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/117171

Summary:
Previous changes relaxed the address space rules based on what the
target says about them. This accidentally included the AS(2) region as
convertible to generic. Simply check for AS(2) and reject it.


>From d980715272ecdc028f0f9ccdc24417c270b01dd2 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 21 Nov 2024 08:55:38 -0600
Subject: [PATCH] [AMDGPU] Do not allow the region address space to be
 converted to generic

Summary:
Previous changes relaxed the address space rules based on what the
target says about them. This accidentally included the AS(2) region as
convertible to generic. Simply check for AS(2) and reject it.
---
 clang/lib/Basic/Targets/AMDGPU.h| 3 ++-
 clang/test/Sema/amdgcn-address-spaces.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index db7a095ba2a4fe..ea4189cdea47da 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -120,7 +120,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   toTargetAddressSpace(A) == llvm::AMDGPUAS::FLAT_ADDRESS)) &&
 isTargetAddressSpace(B) &&
 toTargetAddressSpace(B) >= llvm::AMDGPUAS::FLAT_ADDRESS &&
-toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS);
+toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS &&
+toTargetAddressSpace(B) != llvm::AMDGPUAS::REGION_ADDRESS);
   }
 
   uint64_t getMaxPointerWidth() const override {
diff --git a/clang/test/Sema/amdgcn-address-spaces.c 
b/clang/test/Sema/amdgcn-address-spaces.c
index 50c12993ac69b8..70545db920c807 100644
--- a/clang/test/Sema/amdgcn-address-spaces.c
+++ b/clang/test/Sema/amdgcn-address-spaces.c
@@ -9,7 +9,7 @@
 #define _AS999 __attribute__((address_space(999)))
 
 void *p1(void _AS1 *p) { return p; }
-void *p2(void _AS2 *p) { return p; }
+void *p2(void _AS2 *p) { return p; } // expected-error {{returning '_AS2 void 
*' from a function with result type 'void *' changes address space of pointer}}
 void *p3(void _AS3 *p) { return p; }
 void *p4(void _AS4 *p) { return p; }
 void *p5(void _AS5 *p) { return p; }

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


[clang] Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

2024-11-21 Thread Oleksandr T. via cfe-commits


@@ -185,3 +185,46 @@ template struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template  struct S1 {
+  friend void f1(S1, int = 0); // expected-error {{friend declaration 
specifying a default argument must be a definition}}
+  friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+template  using alias = int;
+template  struct S2 {
+  // FIXME: We miss diagnosing the default argument instantiation failure
+  // (forming reference to void)
+  friend void f3(S2, int a = alias(1)); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+struct S3 {
+  friend void f4(S3, int = 42) { }
+};

a-tarasyuk wrote:

@zyn0217 I've moved the tests that caused failures to 
`CodeGenCXX/default-arguments.cpp`

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


[clang] [clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above (PR #117149)

2024-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dipesh Sharma (dipeshs809)


Changes

Since `__STDC_NO_THREADS__` is a reserved identifier,
- If `MSVC version < 17.9`
- C version < C11(201112L)
- When `` is unavailable `!__has_include()` 
is `__has_include` is defined.

Closes #115529 

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


2 Files Affected:

- (modified) clang/include/clang/Basic/LangOptions.h (+1) 
- (modified) clang/lib/Basic/Targets/OSTargets.cpp (+13-2) 


``diff
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..114a5d34a008bd 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -144,6 +144,7 @@ class LangOptionsBase {
 MSVC2019_5 = 1925,
 MSVC2019_8 = 1928,
 MSVC2022_3 = 1933,
+MSVC2022_9 = 1939,
   };
 
   enum SYCLMajorVersion {
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..f8d974e9979e4d 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -248,8 +248,19 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 Builder.defineMacro("_KERNEL_MODE");
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
-  Builder.defineMacro("__STDC_NO_THREADS__");
-
+  // Define __STDC_NO_THREADS__ based on MSVC version, threads.h availability,
+  // and language standard.
+  if (!Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_9)) {
+Builder.defineMacro("__STDC_NO_THREADS__");
+  } else {
+#if defined(__has_include) && !__has_include()
+Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
+Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+  }
+  // Builder.defineMacro("__STDC_NO_THREADS__");
   // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
   // users of the execution character set defined at compile time.
   // The value given is the Windows Code Page Identifier:

``




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


[clang] [Clang] Prevent potential null pointer dereferences (PR #117176)

2024-11-21 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/117176

This commit addresses several null pointer issues identified by static analysis 
by replacing dyn_cast<> with cast<> and getAs<> with castAs<> in various parts 
of the Clang codebase. The cast and castAs method is used to ensure that the 
type is correctly cast, which helps prevent potential null pointer dereferences.

Changes:
1. ASTContext.cpp:
   Replaced dyn_cast with cast to ensure that the type is correctly cast to 
AttributedType.

2. SemaFunctionEffects.cpp:
 Replaced getAs with castAs to ensure that the type is correctly cast to 
FunctionProtoType.

3. SemaHLSL.cpp:
  Replaced getAs with castAs to ensure that the type is correctly cast to 
VectorType.

>From 1b6b411291b4d7cfd830d43609eaddc65b0f2c56 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Thu, 21 Nov 2024 07:25:11 -0800
Subject: [PATCH] [Clang] Prevent potential null pointer dereferences

---
 clang/lib/AST/ASTContext.cpp   | 2 +-
 clang/lib/Sema/SemaFunctionEffects.cpp | 2 +-
 clang/lib/Sema/SemaHLSL.cpp| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..23df7878a3bf29 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3558,7 +3558,7 @@ ASTContext::adjustType(QualType Orig,
llvm::function_ref Adjust) const {
   switch (Orig->getTypeClass()) {
   case Type::Attributed: {
-const auto *AT = dyn_cast(Orig);
+const auto *AT = cast(Orig);
 return getAttributedType(AT->getAttrKind(),
  adjustType(AT->getModifiedType(), Adjust),
  adjustType(AT->getEquivalentType(), Adjust),
diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp 
b/clang/lib/Sema/SemaFunctionEffects.cpp
index 6fe4d2353a2282..c5c1e3fb41a2ff 100644
--- a/clang/lib/Sema/SemaFunctionEffects.cpp
+++ b/clang/lib/Sema/SemaFunctionEffects.cpp
@@ -627,7 +627,7 @@ class Analyzer {
   IsNoexcept = isNoexcept(FD);
 } else if (auto *BD = dyn_cast(D)) {
   if (auto *TSI = BD->getSignatureAsWritten()) {
-auto *FPT = TSI->getType()->getAs();
+auto *FPT = TSI->getType()->castAs();
 IsNoexcept = FPT->isNothrow() || BD->hasAttr();
   }
 }
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index f4fc0f2ddc27a6..a1adc66ddb9ce9 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1908,9 +1908,9 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 // ensure both args have 3 elements
 int NumElementsArg1 =
-TheCall->getArg(0)->getType()->getAs()->getNumElements();
+TheCall->getArg(0)->getType()->casAs()->getNumElements();
 int NumElementsArg2 =
-TheCall->getArg(1)->getType()->getAs()->getNumElements();
+TheCall->getArg(1)->getType()->castAs()->getNumElements();
 
 if (NumElementsArg1 != 3) {
   int LessOrMore = NumElementsArg1 > 3 ? 1 : 0;

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-21 Thread Gábor Horváth via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr();
+}
+
+void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
+  if (!FD)
+return;
+  auto *MD = dyn_cast(FD);
+  if (!MD || !MD->getIdentifier() || !MD->getParent()->isInStdNamespace())
+return;
+  static const llvm::StringSet<> CapturingMethods{"insert", "push",
+  "push_front", "push_back"};
+  if (!CapturingMethods.contains(MD->getName()))
+return;
+  for (ParmVarDecl *PVD : MD->parameters()) {
+if (PVD->hasAttr())
+  return;

Xazax-hun wrote:

Is return intentional here? Do we want an explicit attr to turn off the 
inference for the rest of the params? If that is the case, I think we want to 
turn off the inference for the params before the explicit attr as well, not 
just after. 

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


[clang] [ARM] Fix undefined behaviour in bf16->float conversion (PR #116985)

2024-11-21 Thread Oliver Stannard via cfe-commits

https://github.com/ostannard closed 
https://github.com/llvm/llvm-project/pull/116985
___
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   >