[libcxx] [flang] [llvm] [lld] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 1/9] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::ope

[libcxx] [flang] [llvm] [lld] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/10] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::o

[clang] [clang-tools-extra] [llvm] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Thanks for your contribution! A couple of nit-picks, and I’d leave the approval 
to other folks.

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


[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread Younan Zhang via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread Younan Zhang via cfe-commits


@@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) {
   EXPECT_FALSE(isKeyword("override", LangOpts));
 }
 
+TEST(SourceCodeTests, isSpelledInSource) {
+  Annotations Test(R"cpp(
+int abc = 1;
+)cpp");
+
+  ParsedAST AST = TestTU::withCode(Test.code()).build();
+  llvm::errs() << Test.code();

zyn0217 wrote:

Debugging purpose?

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


[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread Younan Zhang via cfe-commits


@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   if (Loc.isFileID())
 return true;
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
-  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  bool InvalidSLocEntry = false;
+  const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
+  if (InvalidSLocEntry) {
+return false;
+  }

zyn0217 wrote:

```suggestion
  if (InvalidSLocEntry)
return false;
```
We don't usually add braces to one-line-if statements.

See 
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.

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


[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread Younan Zhang via cfe-commits


@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   if (Loc.isFileID())
 return true;
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
-  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  bool InvalidSLocEntry = false;
+  const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
+  if (InvalidSLocEntry) {
+return false;
+  }
+  const StringRef SpellingFile = SLocEntry.getFile().getName();

zyn0217 wrote:

The const qualifier looks unnecessary to me. Could you please leave it out?

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


[llvm] [libcxx] [flang] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,71 @@
+//===--===//
+//
+// 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 TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#if _LIBCPP_STD_VER >= 26
+
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+#  if defined(_LIBCPP_WIN32API)
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#  else
+#include 
+#  endif
+
+#  include "platform_support.h"
+
+#  if defined(_LIBCPP_WIN32API)
+using HandleT = void*; // HANDLE
+
+bool is_handle_valid([[HandleT handle) {
+  if (LPBY_HANDLE_FILE_INFORMATION & pFileInformation; 
!GetFileInformationByHandle(handle, &lpFileInformation))
+return false;
+  return true;
+};

Zingam wrote:

```suggestion
bool is_handle_valid(void* handle) {
if (BY_HANDLE_FILE_INFORMATION fileInformation; 
!GetFileInformationByHandle(handle, &fileInformation))
return false;
return true;
};
```

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


[llvm] [libcxx] [flang] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

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


[llvm] [libcxx] [flang] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/Zingam updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/11] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::openmo

[llvm] [clang] [lld] [libcxx] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits


@@ -245,6 +267,18 @@ public:
 #  endif
   _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode 
__mode);
   basic_filebuf* close();
+#  if _LIBCPP_STD_VER >= 26
+  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
+_LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");

H-G-Hristov wrote:

Can runtime assertions be validated? I couldn't figure it out.

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


[libcxx] [flang] [llvm] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/12] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::o

[clang] 0871c4b - [Driver][Solaris] Remove reachable llvm_unreachable (#76645)

2024-01-01 Thread via cfe-commits

Author: Brad Smith
Date: 2024-01-01T04:31:27-05:00
New Revision: 0871c4beb826feba2d2aaf2c3efbe1fdeba7624a

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

LOG: [Driver][Solaris] Remove reachable llvm_unreachable (#76645)

Remove the llvm_unreachable from getSolarisLibSuffix(). The code path is
reachable. In the case of an unsupported architecture we're not worrying
about trying to actually find the library paths, and I don't think it
makes sense for the Driver to crash.

Fixes #58334

Added: 


Modified: 
clang/lib/Driver/ToolChains/Solaris.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 9a9792d019d5ed..200ac46aa53409 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -295,13 +295,12 @@ static StringRef getSolarisLibSuffix(const llvm::Triple 
&Triple) {
   switch (Triple.getArch()) {
   case llvm::Triple::x86:
   case llvm::Triple::sparc:
+  default:
 break;
   case llvm::Triple::x86_64:
 return "/amd64";
   case llvm::Triple::sparcv9:
 return "/sparcv9";
-  default:
-llvm_unreachable("Unsupported architecture");
   }
   return "";
 }



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


[clang] [Driver][Solaris] Remove reachable llvm_unreachable (PR #76645)

2024-01-01 Thread Brad Smith via cfe-commits

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


[llvm] [clang] [mlir] Fix unsigned typos (PR #76670)

2024-01-01 Thread via cfe-commits

https://github.com/Rageking8 created 
https://github.com/llvm/llvm-project/pull/76670

None

>From 1412b138fb3ebe6b2bb71189e7cb4f8b4fd72234 Mon Sep 17 00:00:00 2001
From: Rageking8 <106309953+rageki...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 18:13:42 +0800
Subject: [PATCH] Fix unsigned typos

---
 clang/test/Analysis/additive-op-on-sym-int-expr.c | 4 ++--
 .../WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h | 2 +-
 llvm/test/MC/AArch64/neon-diagnostics.s   | 2 +-
 llvm/test/MC/AArch64/neon-scalar-shift-imm.s  | 2 +-
 llvm/test/MC/Disassembler/AArch64/neon-instructions.txt   | 2 +-
 mlir/docs/Dialects/Linalg/OpDSL.md| 2 +-
 mlir/python/mlir/dialects/linalg/opdsl/lang/comprehension.py  | 2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/test/Analysis/additive-op-on-sym-int-expr.c 
b/clang/test/Analysis/additive-op-on-sym-int-expr.c
index bd951c4443a1be..a268baf0a5f18c 100644
--- a/clang/test/Analysis/additive-op-on-sym-int-expr.c
+++ b/clang/test/Analysis/additive-op-on-sym-int-expr.c
@@ -59,7 +59,7 @@ void testMin(int i, long l) {
   clang_analyzer_dumpL(l - intMin); // expected-warning-re 
{{(reg_${{[0-9]+}}) + 2147483648 }} instead of - -2147483648
 }
 
-void changingToUnsinged(unsigned u, int i) {
+void changingToUnsigned(unsigned u, int i) {
   unsigned c = u + (unsigned)i;
   unsigned d = u - (unsigned)i;
   if (i == -1) {
@@ -89,7 +89,7 @@ void extendingToSigned(long l, int i) {
   }
 }
 
-void extendingToUnigned(unsigned long ul, int i) {
+void extendingToUnsigned(unsigned long ul, int i) {
   unsigned long c = ul + (unsigned long)i;
   unsigned long d = ul - (unsigned long)i;
   if (i == -1) {
diff --git 
a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h
index 18018dfc6d6fb9..486cf264d13e2f 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h
@@ -46,7 +46,7 @@ inline bool isRefType(wasm::ValType Type) {
 
 // Convert ValType or a list/signature of ValTypes to a string.
 
-// Convert an unsinged integer, which can be among wasm::ValType enum, to its
+// Convert an unsigned integer, which can be among wasm::ValType enum, to its
 // type name string. If the input is not within wasm::ValType, returns
 // "invalid_type".
 const char *anyTypeToString(unsigned Type);
diff --git a/llvm/test/MC/AArch64/neon-diagnostics.s 
b/llvm/test/MC/AArch64/neon-diagnostics.s
index 481a5ddd6a83f9..9a0445131ddf7c 100644
--- a/llvm/test/MC/AArch64/neon-diagnostics.s
+++ b/llvm/test/MC/AArch64/neon-diagnostics.s
@@ -4877,7 +4877,7 @@
 // CHECK-ERROR:^
 
 //--
-// Scalar Unigned Rounding Shift Right (Immediate)
+// Scalar Unsigned Rounding Shift Right (Immediate)
 //--
 
 urshr d20, d23, #99
diff --git a/llvm/test/MC/AArch64/neon-scalar-shift-imm.s 
b/llvm/test/MC/AArch64/neon-scalar-shift-imm.s
index 96cb815eafa816..db8e21a17a1d36 100644
--- a/llvm/test/MC/AArch64/neon-scalar-shift-imm.s
+++ b/llvm/test/MC/AArch64/neon-scalar-shift-imm.s
@@ -24,7 +24,7 @@
 // CHECK: srshr d19, d18, #7  // encoding: [0x53,0x26,0x79,0x5f]
 
 //--
-// Scalar Unigned Rounding Shift Right (Immediate)
+// Scalar Unsigned Rounding Shift Right (Immediate)
 //--
 urshr d20, d23, #31
 
diff --git a/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt 
b/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt
index ff7dedce444a4d..952ead99f92f76 100644
--- a/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt
+++ b/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt
@@ -1829,7 +1829,7 @@
 0x53,0x26,0x79,0x5f
 
 #--
-# Scalar Unigned Rounding Shift Right (Immediate)
+# Scalar Unsigned Rounding Shift Right (Immediate)
 #--
 # CHECK: urshr d20, d23, #31
 0xf4,0x26,0x61,0x7f
diff --git a/mlir/docs/Dialects/Linalg/OpDSL.md 
b/mlir/docs/Dialects/Linalg/OpDSL.md
index 5c4c8b4e1880ae..9d324d8c538ac7 100644
--- a/mlir/docs/Dialects/Linalg/OpDSL.md
+++ b/mlir/docs/Dialects/Linalg/OpDSL.md
@@ -291,7 +291,7 @@ The following examples illustrate the lowering of signed 
and unsigned functions:
 *   cast_unsigned(I32 -> I64) -> `arith.ExtUIOp`
 *   cast_unsigned(F32 -> I32) -> `arith.FPToUIOp`
 *   max_signed -> `arith.MaxSIOp`
-*   max_unsinged -> `arith.MaxUIOp`
+*   max_unsigned -> `arith.MaxUIOp`
 
 Not all functions are applicable for all numeric types, and on mismatch, op
 verification will f

[mlir] [clang] [llvm] Fix unsigned typos (PR #76670)

2024-01-01 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-webassembly

Author: None (Rageking8)


Changes



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


7 Files Affected:

- (modified) clang/test/Analysis/additive-op-on-sym-int-expr.c (+2-2) 
- (modified) 
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h (+1-1) 
- (modified) llvm/test/MC/AArch64/neon-diagnostics.s (+1-1) 
- (modified) llvm/test/MC/AArch64/neon-scalar-shift-imm.s (+1-1) 
- (modified) llvm/test/MC/Disassembler/AArch64/neon-instructions.txt (+1-1) 
- (modified) mlir/docs/Dialects/Linalg/OpDSL.md (+1-1) 
- (modified) mlir/python/mlir/dialects/linalg/opdsl/lang/comprehension.py 
(+1-1) 


``diff
diff --git a/clang/test/Analysis/additive-op-on-sym-int-expr.c 
b/clang/test/Analysis/additive-op-on-sym-int-expr.c
index bd951c4443a1be..a268baf0a5f18c 100644
--- a/clang/test/Analysis/additive-op-on-sym-int-expr.c
+++ b/clang/test/Analysis/additive-op-on-sym-int-expr.c
@@ -59,7 +59,7 @@ void testMin(int i, long l) {
   clang_analyzer_dumpL(l - intMin); // expected-warning-re 
{{(reg_${{[0-9]+}}) + 2147483648 }} instead of - -2147483648
 }
 
-void changingToUnsinged(unsigned u, int i) {
+void changingToUnsigned(unsigned u, int i) {
   unsigned c = u + (unsigned)i;
   unsigned d = u - (unsigned)i;
   if (i == -1) {
@@ -89,7 +89,7 @@ void extendingToSigned(long l, int i) {
   }
 }
 
-void extendingToUnigned(unsigned long ul, int i) {
+void extendingToUnsigned(unsigned long ul, int i) {
   unsigned long c = ul + (unsigned long)i;
   unsigned long d = ul - (unsigned long)i;
   if (i == -1) {
diff --git 
a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h
index 18018dfc6d6fb9..486cf264d13e2f 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h
@@ -46,7 +46,7 @@ inline bool isRefType(wasm::ValType Type) {
 
 // Convert ValType or a list/signature of ValTypes to a string.
 
-// Convert an unsinged integer, which can be among wasm::ValType enum, to its
+// Convert an unsigned integer, which can be among wasm::ValType enum, to its
 // type name string. If the input is not within wasm::ValType, returns
 // "invalid_type".
 const char *anyTypeToString(unsigned Type);
diff --git a/llvm/test/MC/AArch64/neon-diagnostics.s 
b/llvm/test/MC/AArch64/neon-diagnostics.s
index 481a5ddd6a83f9..9a0445131ddf7c 100644
--- a/llvm/test/MC/AArch64/neon-diagnostics.s
+++ b/llvm/test/MC/AArch64/neon-diagnostics.s
@@ -4877,7 +4877,7 @@
 // CHECK-ERROR:^
 
 //--
-// Scalar Unigned Rounding Shift Right (Immediate)
+// Scalar Unsigned Rounding Shift Right (Immediate)
 //--
 
 urshr d20, d23, #99
diff --git a/llvm/test/MC/AArch64/neon-scalar-shift-imm.s 
b/llvm/test/MC/AArch64/neon-scalar-shift-imm.s
index 96cb815eafa816..db8e21a17a1d36 100644
--- a/llvm/test/MC/AArch64/neon-scalar-shift-imm.s
+++ b/llvm/test/MC/AArch64/neon-scalar-shift-imm.s
@@ -24,7 +24,7 @@
 // CHECK: srshr d19, d18, #7  // encoding: [0x53,0x26,0x79,0x5f]
 
 //--
-// Scalar Unigned Rounding Shift Right (Immediate)
+// Scalar Unsigned Rounding Shift Right (Immediate)
 //--
 urshr d20, d23, #31
 
diff --git a/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt 
b/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt
index ff7dedce444a4d..952ead99f92f76 100644
--- a/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt
+++ b/llvm/test/MC/Disassembler/AArch64/neon-instructions.txt
@@ -1829,7 +1829,7 @@
 0x53,0x26,0x79,0x5f
 
 #--
-# Scalar Unigned Rounding Shift Right (Immediate)
+# Scalar Unsigned Rounding Shift Right (Immediate)
 #--
 # CHECK: urshr d20, d23, #31
 0xf4,0x26,0x61,0x7f
diff --git a/mlir/docs/Dialects/Linalg/OpDSL.md 
b/mlir/docs/Dialects/Linalg/OpDSL.md
index 5c4c8b4e1880ae..9d324d8c538ac7 100644
--- a/mlir/docs/Dialects/Linalg/OpDSL.md
+++ b/mlir/docs/Dialects/Linalg/OpDSL.md
@@ -291,7 +291,7 @@ The following examples illustrate the lowering of signed 
and unsigned functions:
 *   cast_unsigned(I32 -> I64) -> `arith.ExtUIOp`
 *   cast_unsigned(F32 -> I32) -> `arith.FPToUIOp`
 *   max_signed -> `arith.MaxSIOp`
-*   max_unsinged -> `arith.MaxUIOp`
+*   max_unsigned -> `arith.MaxUIOp`
 
 Not all functions are applicable for all numeric types, and on mismatch, op
 verification will fail.
diff --git a/mlir/python/mlir/dialects/linalg/opdsl/lang/comprehension.py 
b/mlir/python/mlir/dialects/linalg

[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)

2024-01-01 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/76671

None

>From e776bdf419556917463a1fdc978fac8fd8b89aaf Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 1 Jan 2024 18:48:27 +0800
Subject: [PATCH] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp'

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  6 ++--
 .../test/Analysis/errno-stdlibraryfunctions.c | 29 +++
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4ca49b9c0546d9..6f249b6b880283 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2511,10 +2511,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *mkdtemp(char *template);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
 // FIXME: Improve for errno modeling.
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index dafda764af9f38..fea81fd709a8bd 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -7,12 +7,9 @@
 // RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
 
 #include "Inputs/errno_var.h"
+#include "Inputs/std-c-library-functions-POSIX.h"
 
-typedef typeof(sizeof(int)) size_t;
-typedef __typeof(sizeof(int)) off_t;
-typedef size_t ssize_t;
-ssize_t send(int sockfd, const void *buf, size_t len, int flags);
-off_t lseek(int fildes, off_t offset, int whence);
+#define NULL ((void *) 0)
 
 void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
@@ -54,3 +51,25 @@ int errno_lseek(int fildes, off_t offset) {
   }
   return 0;
 }
+
+void errno_mkstemp(char *template) {
+  int FD = mkstemp(template);
+  if (FD >= 0) {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  close(FD);
+  } else {
+clang_analyzer_eval(FD == -1);   // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  }
+}
+
+void errno_mkdtemp(char *template) {
+  char *Dir = mkdtemp(template);
+  if (Dir == NULL) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

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


[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+4-2) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+24-5) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4ca49b9c0546d9..6f249b6b880283 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2511,10 +2511,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *mkdtemp(char *template);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
 // FIXME: Improve for errno modeling.
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index dafda764af9f38..fea81fd709a8bd 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -7,12 +7,9 @@
 // RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
 
 #include "Inputs/errno_var.h"
+#include "Inputs/std-c-library-functions-POSIX.h"
 
-typedef typeof(sizeof(int)) size_t;
-typedef __typeof(sizeof(int)) off_t;
-typedef size_t ssize_t;
-ssize_t send(int sockfd, const void *buf, size_t len, int flags);
-off_t lseek(int fildes, off_t offset, int whence);
+#define NULL ((void *) 0)
 
 void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
@@ -54,3 +51,25 @@ int errno_lseek(int fildes, off_t offset) {
   }
   return 0;
 }
+
+void errno_mkstemp(char *template) {
+  int FD = mkstemp(template);
+  if (FD >= 0) {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  close(FD);
+  } else {
+clang_analyzer_eval(FD == -1);   // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  }
+}
+
+void errno_mkdtemp(char *template) {
+  char *Dir = mkdtemp(template);
+  if (Dir == NULL) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

``




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


[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




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

Author: Ben Shi (benshi001)


Changes



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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+4-2) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+24-5) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4ca49b9c0546d9..6f249b6b880283 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2511,10 +2511,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *mkdtemp(char *template);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
 // FIXME: Improve for errno modeling.
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index dafda764af9f38..fea81fd709a8bd 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -7,12 +7,9 @@
 // RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
 
 #include "Inputs/errno_var.h"
+#include "Inputs/std-c-library-functions-POSIX.h"
 
-typedef typeof(sizeof(int)) size_t;
-typedef __typeof(sizeof(int)) off_t;
-typedef size_t ssize_t;
-ssize_t send(int sockfd, const void *buf, size_t len, int flags);
-off_t lseek(int fildes, off_t offset, int whence);
+#define NULL ((void *) 0)
 
 void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
@@ -54,3 +51,25 @@ int errno_lseek(int fildes, off_t offset) {
   }
   return 0;
 }
+
+void errno_mkstemp(char *template) {
+  int FD = mkstemp(template);
+  if (FD >= 0) {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  close(FD);
+  } else {
+clang_analyzer_eval(FD == -1);   // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  }
+}
+
+void errno_mkdtemp(char *template) {
+  char *Dir = mkdtemp(template);
+  if (Dir == NULL) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

``




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


[clang] [lld] [flang] [libcxx] [llvm] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/13] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::o

[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)

2024-01-01 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/76671

>From 0c586914ac977920140472d172ee357dea43f2c5 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 1 Jan 2024 18:48:27 +0800
Subject: [PATCH] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp'

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  6 ++--
 .../test/Analysis/errno-stdlibraryfunctions.c | 29 +++
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4ca49b9c0546d9..6f249b6b880283 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2511,10 +2511,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *mkdtemp(char *template);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
 // FIXME: Improve for errno modeling.
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index dafda764af9f38..de31de8cfea39b 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -7,12 +7,9 @@
 // RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
 
 #include "Inputs/errno_var.h"
+#include "Inputs/std-c-library-functions-POSIX.h"
 
-typedef typeof(sizeof(int)) size_t;
-typedef __typeof(sizeof(int)) off_t;
-typedef size_t ssize_t;
-ssize_t send(int sockfd, const void *buf, size_t len, int flags);
-off_t lseek(int fildes, off_t offset, int whence);
+#define NULL ((void *) 0)
 
 void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
@@ -54,3 +51,25 @@ int errno_lseek(int fildes, off_t offset) {
   }
   return 0;
 }
+
+void errno_mkstemp(char *template) {
+  int FD = mkstemp(template);
+  if (FD >= 0) {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+close(FD);
+  } else {
+clang_analyzer_eval(FD == -1);   // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  }
+}
+
+void errno_mkdtemp(char *template) {
+  char *Dir = mkdtemp(template);
+  if (Dir == NULL) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

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


[libcxx] [flang] [clang] [lld] [llvm] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/14] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::o

[mlir] [clang] [llvm] Fix unsigned typos (PR #76670)

2024-01-01 Thread Matthias Springer via cfe-commits

https://github.com/matthias-springer approved this pull request.


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


[clang] [clang][AVR] Restrict range of assembly constraint 'G' (PR #76561)

2024-01-01 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/76561

>From 66a786a0353d8ae88006e585861fcb2035797032 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 29 Dec 2023 17:58:21 +0800
Subject: [PATCH] [clang][AVR] Restrict range of assembly constraint 'G'

According to https://www.nongnu.org/avr-libc/user-manual/inline_asm.html,
"G" only represent float constant "0.0". And avr-gcc also rejects
other non-zero values.
---
 clang/lib/Basic/Targets/AVR.h | 4 +++-
 clang/test/CodeGen/avr/avr-inline-asm-constraints.c   | 4 ++--
 .../test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c | 1 +
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index 854a51d78c393b..9376c46cd98ca1 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -146,7 +146,9 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 case 'R': // Integer constant (Range: -6 to 5)
   Info.setRequiresImmediate(-6, 5);
   return true;
-case 'G': // Floating point constant
+case 'G': // Floating point constant 0.0
+  Info.setRequiresImmediate(0);
+  return true;
 case 'Q': // A memory address based on Y or Z pointer with displacement.
   return true;
 }
diff --git a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
index 96774861feb228..3a956de8db48f0 100644
--- a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -109,8 +109,8 @@ void R() {
 }
 
 void G() {
-  // CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "G"(i16 50)
-  asm("subi r30, %0" :: "G"(50));
+  // CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "G"(i16 0)
+  asm("subi r30, %0" :: "G"(0));
 }
 
 void Q() {
diff --git a/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
index ceea59229f736a..29f0b69285fa88 100644
--- a/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
@@ -5,4 +5,5 @@ const unsigned char val = 0;
 int foo(void) {
   __asm__ volatile("foo %0, 1" : : "fo" (val)); // expected-error {{invalid 
input constraint 'fo' in asm}}
   __asm__ volatile("foo %0, 1" : : "Nd" (val)); // expected-error {{invalid 
input constraint 'Nd' in asm}}
+  __asm__ volatile("subi r30, %0" : : "G" (1)); // expected-error {{value '1' 
out of range for constraint 'G'}}
 }

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


[clang] [clang][AVR] Restrict range of assembly constraint 'G' (PR #76561)

2024-01-01 Thread Ben Shi via cfe-commits

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


[flang] [lldb] [libcxx] [clang-tools-extra] [clang] [compiler-rt] [mlir] [libc] [openmp] [llvm] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/74994

>From 6e26ca239c49e1b7d9ab72217db7339e92df163f Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sun, 10 Dec 2023 14:16:02 +0200
Subject: [PATCH 01/17] [libc++][span] P2821R5: span.at()

---
 libcxx/include/span   |  30 +++
 .../views/views.span/span.elem/at.pass.cpp| 246 ++
 .../views.span/span.elem/op_idx.pass.cpp  |   1 -
 3 files changed, 276 insertions(+), 1 deletion(-)
 create mode 100644 
libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp

diff --git a/libcxx/include/span b/libcxx/include/span
index 69b0a2875e26cc..b015d7cf1c15b6 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -92,6 +92,7 @@ public:
 
 // [span.elem], span element access
 constexpr reference operator[](size_type idx) const;
+constexpr reference at(size_type idx) const; // since C++26
 constexpr reference front() const;
 constexpr reference back() const;
 constexpr pointer data() const noexcept;
@@ -146,6 +147,9 @@ template
 #include <__utility/forward.h>
 #include // for array
 #include   // for byte
+#if _LIBCPP_STD_VER >= 26
+#  include 
+#endif
 #include 
 
 // standard-mandated includes
@@ -343,6 +347,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -383,6 +396,10 @@ public:
 
 private:
 pointer__data_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 
@@ -510,6 +527,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -552,6 +578,10 @@ public:
 private:
 pointer   __data_;
 size_type __size_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 template 
diff --git a/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp 
b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
new file mode 100644
index 00..2a9ce2baeec1a5
--- /dev/null
+++ b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
@@ -0,0 +1,246 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+// template 
+// constexpr bool testConstexprSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// return r1 == r2;
+// }
+
+// template 
+// void testRuntimeSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// assert(r1 == r2);
+// }
+
+// struct A{};
+// constexpr int iArr1[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9};
+//   int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+
+// int main(int, char**)
+// {
+// static_assert(testConstexprSpan(std::span(iArr1, 1), 0), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 1), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 2), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 2), "");
+// static_assert(t

[flang] [lldb] [libcxx] [clang-tools-extra] [clang] [compiler-rt] [mlir] [libc] [openmp] [llvm] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

@philnik777  a gentle ping 
...and Happy New Year!

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


[clang] [clang-format] Fix erroneous BraceWrapping.BeforeLambdaBody column calcs (PR #76673)

2024-01-01 Thread James Grant via cfe-commits

https://github.com/jamesg-nz created 
https://github.com/llvm/llvm-project/pull/76673

Firstly, must check ColumnLimit > 0 before comparing calculated columns to the 
limit. Otherwise it always breaks before the brace if ColumnLimit = 0 (no 
limit). Fixes #50275

Secondly, the lambda body length alone is currently compared with the column 
limit. Should instead be comparing a column position, which includes everything 
before the lambda body, the body length itself, and any unbreakable tail. Fixes 
#59724

Thirdly, if must break before the lambda right brace, e.g. line comment in 
body, then must also break before the left brace. Can't use column calculation 
in this instance.

>From 04885844162b5390d8041a44a1895ad6ac160228 Mon Sep 17 00:00:00 2001
From: James Grant <42079499+jamesg...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 20:27:41 +1300
Subject: [PATCH] [clang-format] Fix erroneous BraceWrapping.BeforeLambdaBody
 column calcs

Firstly, must check ColumnLimit > 0 before comparing calculated columns
to the limit. Otherwise it always breaks before the brace if ColumnLimit
= 0 (no limit). Fixes #50275

Secondly, the lambda body length alone is currently compared with the
column limit. Should instead be comparing a column position, which
includes everything before the lambda body, the body length itself, and
any unbreakable tail. Fixes #59724

Thirdly, if must break before the lambda right brace, e.g. line comment
in body, then must also break before the left brace. Can't use column
calculation in this instance.
---
 clang/lib/Format/ContinuationIndenter.cpp | 10 ++-
 clang/unittests/Format/FormatTest.cpp | 78 +++
 2 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..f4f8b694f7ff51 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -366,8 +366,14 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   const auto &CurrentState = State.Stack.back();
   if (Style.BraceWrapping.BeforeLambdaBody && Current.CanBreakBefore &&
   Current.is(TT_LambdaLBrace) && Previous.isNot(TT_LineComment)) {
-auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
-return LambdaBodyLength > getColumnLimit(State);
+if (Current.MatchingParen->MustBreakBefore)
+  return true;
+
+auto LambdaEnd = getLengthToMatchingParen(Current, State.Stack) +
+ Current.MatchingParen->UnbreakableTailLength +
+ State.Column - 1;
+
+return Style.ColumnLimit > 0 && LambdaEnd > getColumnLimit(State);
   }
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..f5aadec3500ccb 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -22965,6 +22965,84 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
"};");
 }
 
+TEST_F(FormatTest, BreakBeforeLambdaBodyWrapping) {
+  verifyFormat("connect([]() {\n"
+   "  foo();\n"
+   "  bar();\n"
+   "});");
+
+  auto Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.BeforeLambdaBody = true;
+
+  verifyFormat("connect(\n"
+   "[]()\n"
+   "{\n"
+   "  foo();\n"
+   "  bar();\n"
+   "});",
+   Style);
+
+  for (unsigned l : {0, 41}) {
+Style.ColumnLimit = l;
+verifyFormat("auto lambda = []() { return foo + bar; };", Style);
+  }
+  for (unsigned l : {40, 22}) {
+Style.ColumnLimit = l;
+verifyFormat("auto lambda = []()\n"
+ "{ return foo + bar; };",
+ Style);
+  }
+  Style.ColumnLimit = 21;
+  verifyFormat("auto lambda = []()\n"
+   "{\n"
+   "  return foo + bar;\n"
+   "};",
+   Style);
+
+  for (unsigned l : {0, 67}) {
+Style.ColumnLimit = l;
+verifyFormat(
+"auto result = [](int foo, int bar) { return foo + bar; }(foo, bar);",
+Style);
+  }
+  Style.ColumnLimit = 66;
+  verifyFormat("auto result = [](int foo, int bar)\n"
+   "{ return foo + bar; }(foo, bar);",
+   Style);
+
+  Style.ColumnLimit = 36;
+  verifyFormat("myFunc([&]() { return foo + bar; });", Style);
+  Style.ColumnLimit = 35;
+  verifyFormat("myFunc([&]()\n"
+   "   { return foo + bar; });",
+   Style);
+
+  Style = getGoogleStyleWithColumns(100);
+  Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+  Style.IndentWidth = 4;
+  verifyFormat(
+  "void Func()\n"
+  "{\n"
+  "[]()\n"
+  "{\n"
+  "return TestVeryLongThingName::TestVeryLongFunctionName()\n"
+  ".TestAnotherVeryVeryLong

[libcxx] [lld] [llvm] [clang] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/15] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::o

[clang] [clang-format] Fix erroneous BraceWrapping.BeforeLambdaBody column calcs (PR #76673)

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


[clang] [clang-format] Fix erroneous BraceWrapping.BeforeLambdaBody column calcs (PR #76673)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: James Grant (jamesg-nz)


Changes

Firstly, must check ColumnLimit > 0 before comparing calculated columns to 
the limit. Otherwise it always breaks before the brace if ColumnLimit = 0 (no 
limit). Fixes #50275

Secondly, the lambda body length alone is currently compared with the column 
limit. Should instead be comparing a column position, which includes everything 
before the lambda body, the body length itself, and any unbreakable tail. Fixes 
#59724

Thirdly, if must break before the lambda right brace, e.g. line comment in 
body, then must also break before the left brace. Can't use column calculation 
in this instance.

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


2 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+8-2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+78) 


``diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..f4f8b694f7ff51 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -366,8 +366,14 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   const auto &CurrentState = State.Stack.back();
   if (Style.BraceWrapping.BeforeLambdaBody && Current.CanBreakBefore &&
   Current.is(TT_LambdaLBrace) && Previous.isNot(TT_LineComment)) {
-auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
-return LambdaBodyLength > getColumnLimit(State);
+if (Current.MatchingParen->MustBreakBefore)
+  return true;
+
+auto LambdaEnd = getLengthToMatchingParen(Current, State.Stack) +
+ Current.MatchingParen->UnbreakableTailLength +
+ State.Column - 1;
+
+return Style.ColumnLimit > 0 && LambdaEnd > getColumnLimit(State);
   }
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..f5aadec3500ccb 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -22965,6 +22965,84 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
"};");
 }
 
+TEST_F(FormatTest, BreakBeforeLambdaBodyWrapping) {
+  verifyFormat("connect([]() {\n"
+   "  foo();\n"
+   "  bar();\n"
+   "});");
+
+  auto Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.BeforeLambdaBody = true;
+
+  verifyFormat("connect(\n"
+   "[]()\n"
+   "{\n"
+   "  foo();\n"
+   "  bar();\n"
+   "});",
+   Style);
+
+  for (unsigned l : {0, 41}) {
+Style.ColumnLimit = l;
+verifyFormat("auto lambda = []() { return foo + bar; };", Style);
+  }
+  for (unsigned l : {40, 22}) {
+Style.ColumnLimit = l;
+verifyFormat("auto lambda = []()\n"
+ "{ return foo + bar; };",
+ Style);
+  }
+  Style.ColumnLimit = 21;
+  verifyFormat("auto lambda = []()\n"
+   "{\n"
+   "  return foo + bar;\n"
+   "};",
+   Style);
+
+  for (unsigned l : {0, 67}) {
+Style.ColumnLimit = l;
+verifyFormat(
+"auto result = [](int foo, int bar) { return foo + bar; }(foo, bar);",
+Style);
+  }
+  Style.ColumnLimit = 66;
+  verifyFormat("auto result = [](int foo, int bar)\n"
+   "{ return foo + bar; }(foo, bar);",
+   Style);
+
+  Style.ColumnLimit = 36;
+  verifyFormat("myFunc([&]() { return foo + bar; });", Style);
+  Style.ColumnLimit = 35;
+  verifyFormat("myFunc([&]()\n"
+   "   { return foo + bar; });",
+   Style);
+
+  Style = getGoogleStyleWithColumns(100);
+  Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+  Style.IndentWidth = 4;
+  verifyFormat(
+  "void Func()\n"
+  "{\n"
+  "[]()\n"
+  "{\n"
+  "return TestVeryLongThingName::TestVeryLongFunctionName()\n"
+  ".TestAnotherVeryVeryLongFunctionName();\n"
+  "}\n"
+  "}\n",
+  Style);
+  verifyFormat(
+  "void Func()\n"
+  "{\n"
+  "[]()\n"
+  "{\n"
+  "return TestVeryLongThingName::TestVeryLongFunctionName()\n"
+  ".TestAnotherVeryVeryVeryLongFunctionName();\n"
+  "}\n"
+  "}\n",
+  Style);
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;

``




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


[clang] [clang-format] Fix erroneous BraceWrapping.BeforeLambdaBody column calcs (PR #76673)

2024-01-01 Thread James Grant via cfe-commits

jamesg-nz wrote:

n.b. there's relevant test coverage provided by existing 
`LambdaWithLineComments` test.


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


[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

2024-01-01 Thread James Grant via cfe-commits

https://github.com/jamesg-nz created 
https://github.com/llvm/llvm-project/pull/76675

If there are possible column formats, but they weren't selected because they 
don't fit within remaining characters for the current path then applying severe 
penalty to induce column layout by selection of a different path seems fair.

But if due to style configuration or what the input code is, there are no 
possible column formats, different paths aren't going to have column layouts. 
Seems wrong to apply the severe penalty to induce column layouts if there are 
none available.

It just causes selection of sub-optimal paths, e.g. get bad formatting when 
brace initializers are used inside lambda bodies.

Fixes #56350

>From 68f7dee10e20b4ceeaba67f1ebe6b1153647e6ff Mon Sep 17 00:00:00 2001
From: James Grant <42079499+jamesg...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 21:35:11 +1300
Subject: [PATCH] [clang-format] Don't apply severe penalty if no possible
 column formats

If there are possible column formats, but they weren't selected because
they don't fit within remaining characters for the current path then
applying severe penalty to induce column layout by selection of a
different path seems fair.

But if due to style configuration or what the input code is, there are
no possible column formats, different paths aren't going to have column
layouts. Seems wrong to apply the severe penalty to induce column
layouts if there are none available.

It just causes selection of sub-optimal paths, e.g. get bad formatting
when brace initializers are used inside lambda bodies.

Fixes #56350
---
 clang/lib/Format/FormatToken.cpp  |  4 ++--
 clang/unittests/Format/FormatTest.cpp | 15 +++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 7a2df8c53952f9..b791c5a26bbe3a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -113,8 +113,8 @@ unsigned CommaSeparatedList::formatAfterToken(LineState 
&State,
   if (!State.NextToken || !State.NextToken->Previous)
 return 0;
 
-  if (Formats.size() == 1)
-return 0; // Handled by formatFromToken
+  if (Formats.size() <= 1)
+return 0; // Handled by formatFromToken (1) or avoid severe penalty (0).
 
   // Ensure that we start on the opening brace.
   const FormatToken *LBrace =
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..b7350b2fe66d9b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13875,6 +13875,21 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
getLLVMStyleWithColumns(35));
   verifyFormat("aa(aaa, {},\n"
"   aaa);");
+
+  // No possible column formats, don't want the optimal paths penalized.
+  verifyFormat(
+  "waarudo::unit desk = {\n"
+  ".s = \"desk\", .p = p, .b = [] { return w::r{3, 10} * w::m; }};");
+  verifyFormat("SomeType something1([](const Input &i) -> Output { return "
+   "Output{1, 2}; },\n"
+   "[](const Input &i) -> Output { return "
+   "Output{1, 2}; });");
+  FormatStyle NoBinPacking = getLLVMStyle();
+  NoBinPacking.BinPackParameters = false;
+  verifyFormat("waarudo::unit desk = {\n"
+   ".s = \"desk\", .p = p, .b = [] { return w::r{3, 10, 1, 1, "
+   "1, 1} * w::m; }};",
+   NoBinPacking);
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {

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


[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

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


[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: James Grant (jamesg-nz)


Changes

If there are possible column formats, but they weren't selected because they 
don't fit within remaining characters for the current path then applying severe 
penalty to induce column layout by selection of a different path seems fair.

But if due to style configuration or what the input code is, there are no 
possible column formats, different paths aren't going to have column layouts. 
Seems wrong to apply the severe penalty to induce column layouts if there are 
none available.

It just causes selection of sub-optimal paths, e.g. get bad formatting when 
brace initializers are used inside lambda bodies.

Fixes #56350

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


2 Files Affected:

- (modified) clang/lib/Format/FormatToken.cpp (+2-2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+15) 


``diff
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 7a2df8c53952f9..b791c5a26bbe3a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -113,8 +113,8 @@ unsigned CommaSeparatedList::formatAfterToken(LineState 
&State,
   if (!State.NextToken || !State.NextToken->Previous)
 return 0;
 
-  if (Formats.size() == 1)
-return 0; // Handled by formatFromToken
+  if (Formats.size() <= 1)
+return 0; // Handled by formatFromToken (1) or avoid severe penalty (0).
 
   // Ensure that we start on the opening brace.
   const FormatToken *LBrace =
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..b7350b2fe66d9b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13875,6 +13875,21 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
getLLVMStyleWithColumns(35));
   verifyFormat("aa(aaa, {},\n"
"   aaa);");
+
+  // No possible column formats, don't want the optimal paths penalized.
+  verifyFormat(
+  "waarudo::unit desk = {\n"
+  ".s = \"desk\", .p = p, .b = [] { return w::r{3, 10} * w::m; }};");
+  verifyFormat("SomeType something1([](const Input &i) -> Output { return "
+   "Output{1, 2}; },\n"
+   "[](const Input &i) -> Output { return "
+   "Output{1, 2}; });");
+  FormatStyle NoBinPacking = getLLVMStyle();
+  NoBinPacking.BinPackParameters = false;
+  verifyFormat("waarudo::unit desk = {\n"
+   ".s = \"desk\", .p = p, .b = [] { return w::r{3, 10, 1, 1, "
+   "1, 1} * w::m; }};",
+   NoBinPacking);
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {

``




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


[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

2024-01-01 Thread James Grant via cfe-commits

jamesg-nz wrote:

Running debug build clang-format with `-debug` parameter against code provided 
in #56350 (and its duplicate #58469) you see `Penalty for line: 1`. So 
pretty obvious the [severe 
penalty](https://github.com/llvm/llvm-project/blob/703e83611cd8bb7174ae76ba2e301f5a5e88b905/clang/lib/Format/FormatToken.cpp#L140)
 is responsible. 

Thoughts on this change? Is the removal of the severe penalty being applied too 
broadly? ... or is it correct/OK?

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


[clang] [clang-format] Fix handling of C-Style variable definition of a struct (PR #76344)

2024-01-01 Thread via cfe-commits

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -10895,6 +10899,138 @@ bool VectorExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+return false;
+
+  if (Result.isLValue()) {
+// Source of the data is an lvalue; Manually handle the lvalue as if
+// it was an rvalue to get the current APValue.
+LValue LValueFound;
+LValueFound.setFrom(Info.Ctx, Result);
+if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result)) {
+  return false;
+}
+  }
+
+  if (!Result.isVector()) {
+return false;
+  }
+  return true;
+}
+
+static bool handleVectorConversion(EvalInfo &Info, const FPOptions FPO,
+   const Expr *E, QualType SourceTy,
+   QualType DestTy, APValue const &Original,
+   APValue &Result) {
+  if (SourceTy->isIntegerType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = APValue(APFloat(0.0));
+  return HandleIntToFloatCast(Info, E, FPO, SourceTy, Original.getInt(),
+  DestTy, Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(
+  HandleIntToIntCast(Info, E, DestTy, SourceTy, Original.getInt()));
+  return true;
+}
+  } else if (SourceTy->isRealFloatingType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = Original;
+  return HandleFloatToFloatCast(Info, E, SourceTy, DestTy,
+Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(APSInt());
+  return HandleFloatToIntCast(Info, E, SourceTy, Original.getFloat(),
+  DestTy, Result.getInt());
+}
+  }
+  return false;
+}
+
+bool VectorExprEvaluator::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
+  APValue Source;
+  QualType SourceVecType = E->getSrcExpr()->getType();
+  if (!EvaluateVectorOrLValue(Source, Info, E->getSrcExpr(), SourceVecType))
+return false;
+
+  QualType DestTy = E->getType()->castAs()->getElementType();
+  QualType SourceTy = SourceVecType->castAs()->getElementType();
+
+  const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+
+  SmallVector ResultElements;
+  ResultElements.reserve(Source.getVectorLength());
+  for (unsigned EltNum = 0; EltNum < Source.getVectorLength(); ++EltNum) {
+APValue Elt;
+if (!handleVectorConversion(Info, FPO, E, SourceTy, DestTy,
+Source.getVectorElt(EltNum), Elt))
+  return false;
+ResultElements.push_back(std::move(Elt));
+  }
+
+  return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+}
+
+static bool handleVectorShuffle(EvalInfo &Info, const ShuffleVectorExpr *E,
+QualType ElemType, APValue const &VecVal1,
+APValue const &VecVal2, unsigned EltNum,
+APValue &Result) {
+  unsigned const TotalElementsInAVector = VecVal1.getVectorLength();
+
+  Expr const *IndexExpr = E->getExpr(2 + EltNum);
+  APSInt IndexVal;
+  if (!EvaluateInteger(IndexExpr, IndexVal, Info)) {
+return false;
+  }

RKSimon wrote:

(style) unnecessary braces

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -10895,6 +10899,138 @@ bool VectorExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+return false;
+
+  if (Result.isLValue()) {
+// Source of the data is an lvalue; Manually handle the lvalue as if
+// it was an rvalue to get the current APValue.
+LValue LValueFound;
+LValueFound.setFrom(Info.Ctx, Result);
+if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result)) {
+  return false;
+}
+  }
+
+  if (!Result.isVector()) {
+return false;
+  }
+  return true;

RKSimon wrote:

Just use `return Result.isVector()` ?

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -10895,6 +10899,138 @@ bool VectorExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+return false;
+
+  if (Result.isLValue()) {
+// Source of the data is an lvalue; Manually handle the lvalue as if
+// it was an rvalue to get the current APValue.
+LValue LValueFound;
+LValueFound.setFrom(Info.Ctx, Result);
+if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result)) {
+  return false;
+}
+  }
+
+  if (!Result.isVector()) {
+return false;
+  }
+  return true;
+}
+
+static bool handleVectorConversion(EvalInfo &Info, const FPOptions FPO,
+   const Expr *E, QualType SourceTy,
+   QualType DestTy, APValue const &Original,
+   APValue &Result) {
+  if (SourceTy->isIntegerType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = APValue(APFloat(0.0));
+  return HandleIntToFloatCast(Info, E, FPO, SourceTy, Original.getInt(),
+  DestTy, Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(
+  HandleIntToIntCast(Info, E, DestTy, SourceTy, Original.getInt()));
+  return true;
+}
+  } else if (SourceTy->isRealFloatingType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = Original;
+  return HandleFloatToFloatCast(Info, E, SourceTy, DestTy,
+Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(APSInt());
+  return HandleFloatToIntCast(Info, E, SourceTy, Original.getFloat(),
+  DestTy, Result.getInt());
+}
+  }
+  return false;
+}
+
+bool VectorExprEvaluator::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
+  APValue Source;
+  QualType SourceVecType = E->getSrcExpr()->getType();
+  if (!EvaluateVectorOrLValue(Source, Info, E->getSrcExpr(), SourceVecType))
+return false;
+
+  QualType DestTy = E->getType()->castAs()->getElementType();
+  QualType SourceTy = SourceVecType->castAs()->getElementType();
+
+  const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+
+  SmallVector ResultElements;
+  ResultElements.reserve(Source.getVectorLength());
+  for (unsigned EltNum = 0; EltNum < Source.getVectorLength(); ++EltNum) {
+APValue Elt;
+if (!handleVectorConversion(Info, FPO, E, SourceTy, DestTy,
+Source.getVectorElt(EltNum), Elt))
+  return false;
+ResultElements.push_back(std::move(Elt));
+  }
+
+  return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+}
+
+static bool handleVectorShuffle(EvalInfo &Info, const ShuffleVectorExpr *E,
+QualType ElemType, APValue const &VecVal1,
+APValue const &VecVal2, unsigned EltNum,
+APValue &Result) {
+  unsigned const TotalElementsInAVector = VecVal1.getVectorLength();
+
+  Expr const *IndexExpr = E->getExpr(2 + EltNum);
+  APSInt IndexVal;
+  if (!EvaluateInteger(IndexExpr, IndexVal, Info)) {
+return false;
+  }
+
+  uint32_t index = IndexVal.getZExtValue();
+  // The spec says that -1 should be treated as undef for optimizations,
+  // but in constexpr we need to choose a value. We'll choose 0.
+  if (index >= TotalElementsInAVector * 2) {
+index = 0;
+  }

RKSimon wrote:

Is there any chance we can retain the undef? Could we insert an undef element?

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -10895,6 +10899,138 @@ bool VectorExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+return false;
+
+  if (Result.isLValue()) {
+// Source of the data is an lvalue; Manually handle the lvalue as if
+// it was an rvalue to get the current APValue.
+LValue LValueFound;
+LValueFound.setFrom(Info.Ctx, Result);
+if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result)) {
+  return false;
+}
+  }
+
+  if (!Result.isVector()) {
+return false;
+  }
+  return true;
+}
+
+static bool handleVectorConversion(EvalInfo &Info, const FPOptions FPO,
+   const Expr *E, QualType SourceTy,
+   QualType DestTy, APValue const &Original,
+   APValue &Result) {
+  if (SourceTy->isIntegerType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = APValue(APFloat(0.0));
+  return HandleIntToFloatCast(Info, E, FPO, SourceTy, Original.getInt(),
+  DestTy, Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(
+  HandleIntToIntCast(Info, E, DestTy, SourceTy, Original.getInt()));
+  return true;
+}
+  } else if (SourceTy->isRealFloatingType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = Original;
+  return HandleFloatToFloatCast(Info, E, SourceTy, DestTy,
+Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(APSInt());
+  return HandleFloatToIntCast(Info, E, SourceTy, Original.getFloat(),
+  DestTy, Result.getInt());
+}
+  }
+  return false;
+}
+
+bool VectorExprEvaluator::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
+  APValue Source;
+  QualType SourceVecType = E->getSrcExpr()->getType();
+  if (!EvaluateVectorOrLValue(Source, Info, E->getSrcExpr(), SourceVecType))
+return false;
+
+  QualType DestTy = E->getType()->castAs()->getElementType();
+  QualType SourceTy = SourceVecType->castAs()->getElementType();
+
+  const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+
+  SmallVector ResultElements;
+  ResultElements.reserve(Source.getVectorLength());
+  for (unsigned EltNum = 0; EltNum < Source.getVectorLength(); ++EltNum) {
+APValue Elt;
+if (!handleVectorConversion(Info, FPO, E, SourceTy, DestTy,
+Source.getVectorElt(EltNum), Elt))
+  return false;
+ResultElements.push_back(std::move(Elt));
+  }
+
+  return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+}
+
+static bool handleVectorShuffle(EvalInfo &Info, const ShuffleVectorExpr *E,
+QualType ElemType, APValue const &VecVal1,
+APValue const &VecVal2, unsigned EltNum,
+APValue &Result) {
+  unsigned const TotalElementsInAVector = VecVal1.getVectorLength();
+
+  Expr const *IndexExpr = E->getExpr(2 + EltNum);
+  APSInt IndexVal;
+  if (!EvaluateInteger(IndexExpr, IndexVal, Info)) {
+return false;
+  }
+
+  uint32_t index = IndexVal.getZExtValue();
+  // The spec says that -1 should be treated as undef for optimizations,
+  // but in constexpr we need to choose a value. We'll choose 0.
+  if (index >= TotalElementsInAVector * 2) {
+index = 0;
+  }
+
+  if (index >= TotalElementsInAVector) {
+Result = VecVal2.getVectorElt(index - TotalElementsInAVector);
+  } else {
+Result = VecVal1.getVectorElt(index);
+  }
+  return true;
+}
+
+bool VectorExprEvaluator::VisitShuffleVectorExpr(const ShuffleVectorExpr *E) {
+  APValue VecVal1;
+  const Expr *Vec1 = E->getExpr(0);
+  if (!EvaluateVectorOrLValue(VecVal1, Info, Vec1, Vec1->getType()))
+return false;
+  APValue VecVal2;
+  const Expr *Vec2 = E->getExpr(1);
+  if (!EvaluateVectorOrLValue(VecVal2, Info, Vec2, Vec2->getType()))
+return false;
+
+  VectorType const *DestVecTy = E->getType()->castAs();
+  if (!DestVecTy) {
+return false;
+  }

RKSimon wrote:

(style) unnecessary braces

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon commented:

A few minors but a frontend specialist really needs to review this

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -302,3 +302,64 @@ extern __typeof__(__builtin_expect(0, 0)) bi0;
 // Strings
 int array1[__builtin_strlen("ab\0cd")];
 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
+
+typedef double vector4double __attribute__((__vector_size__(32)));
+typedef float vector4float __attribute__((__vector_size__(16)));
+typedef long long vector4long __attribute__((__vector_size__(32)));
+typedef int vector4int __attribute__((__vector_size__(16)));
+typedef short vector4short __attribute__((__vector_size__(8)));
+typedef char vector4char __attribute__((__vector_size__(4)));
+typedef double vector8double __attribute__((__vector_size__(64)));
+typedef float vector8float __attribute__((__vector_size__(32)));
+typedef long long vector8long __attribute__((__vector_size__(64)));
+typedef int vector8int __attribute__((__vector_size__(32)));
+typedef short vector8short __attribute__((__vector_size__(16)));
+typedef char vector8char __attribute__((__vector_size__(8)));
+
+// Convert vector
+#define CHECK_NUM(__size, __typeFrom, __typeTo, ...)   
 \
+  vector##__size##__typeTo 
 \
+  from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var 
= \
+  __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__},   
 \
+  vector##__size##__typeTo);
+#define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...)
\
+  CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__)   
\
+  CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) 
\
+  CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__)  
\
+  CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__)
+
+#define CHECK_ALL_COMBINATIONS(__size, ...)
\
+  CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__)  
\
+  CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__)
\
+  CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) 
\
+  CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__)
+
+CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3);
+CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7);
+#undef CHECK_ALL_COMBINATIONS
+#undef CHECK_TO_ALL_TYPES
+#undef CHECK_NUM
+
+// Shuffle vector
+vector4int const vector4intConst1 = {0, 1, 2, 3};
+vector4int const vector4intConst2 = {4, 5, 6, 7};
+vector8int const vector8intConst = {};
+
+vector4int vectorShuffle1 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 1, 2, 3);
+vector4int vectorShuffle2 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 4, 5, 6, 7);
+vector4int vectorShuffle3 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, -1, -1, -1, 
-1);
+vector4int vectorShuffle4 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6);
+vector8int vectorShuffle5 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14);
+vector4int vectorShuffle6 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6);
+vector8int vectorShuffle7 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6, 1, 
3, 5, 7);

RKSimon wrote:

What could we do to check the result values of the constant expression? Could 
we bitcast a char4 to a uint value and static assert the result for instance?

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -10895,6 +10899,138 @@ bool VectorExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+return false;
+
+  if (Result.isLValue()) {
+// Source of the data is an lvalue; Manually handle the lvalue as if
+// it was an rvalue to get the current APValue.
+LValue LValueFound;
+LValueFound.setFrom(Info.Ctx, Result);
+if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result)) {
+  return false;
+}
+  }
+
+  if (!Result.isVector()) {
+return false;
+  }
+  return true;
+}
+
+static bool handleVectorConversion(EvalInfo &Info, const FPOptions FPO,
+   const Expr *E, QualType SourceTy,
+   QualType DestTy, APValue const &Original,
+   APValue &Result) {
+  if (SourceTy->isIntegerType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = APValue(APFloat(0.0));
+  return HandleIntToFloatCast(Info, E, FPO, SourceTy, Original.getInt(),
+  DestTy, Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(
+  HandleIntToIntCast(Info, E, DestTy, SourceTy, Original.getInt()));
+  return true;
+}
+  } else if (SourceTy->isRealFloatingType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = Original;
+  return HandleFloatToFloatCast(Info, E, SourceTy, DestTy,
+Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(APSInt());
+  return HandleFloatToIntCast(Info, E, SourceTy, Original.getFloat(),
+  DestTy, Result.getInt());
+}
+  }
+  return false;
+}
+
+bool VectorExprEvaluator::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
+  APValue Source;
+  QualType SourceVecType = E->getSrcExpr()->getType();
+  if (!EvaluateVectorOrLValue(Source, Info, E->getSrcExpr(), SourceVecType))
+return false;
+
+  QualType DestTy = E->getType()->castAs()->getElementType();
+  QualType SourceTy = SourceVecType->castAs()->getElementType();
+
+  const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+
+  SmallVector ResultElements;
+  ResultElements.reserve(Source.getVectorLength());
+  for (unsigned EltNum = 0; EltNum < Source.getVectorLength(); ++EltNum) {

RKSimon wrote:

Pull out repeated Source.getVectorLength() calls?

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


[clang] [Clang][Sema] Diagnose unexpanded packs in the template argument lists of function template specializations (PR #76677)

2024-01-01 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/76677

This diagnoses unexpanded packs in the _unqualified-id_ of a function template 
specialization's _declarator-id_, e.g.:
```cpp
template
struct A
{
template
void f();

template<>
void f(); // error: explicit specialization contains unexpanded 
parameter pack 'Ts'
};
```

I moved the handling of template-id's so it happens right after we determine 
whether we are declaring a function template/function template specialization 
so diagnostics are issued in lexical order. 

>From 7c53e9cd31601f59367879384ad3b1c6b0ae3a98 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 1 Jan 2024 07:35:09 -0500
Subject: [PATCH] [Clang][Sema] Diagnose unexpanded packs in the template
 argument lists of function template specializations

---
 clang/lib/Sema/SemaDecl.cpp   | 89 +--
 .../CXX/temp/temp.decls/temp.variadic/p5.cpp  | 12 +++
 2 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ffbe317d559995..e94637b4f053e0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9900,15 +9900,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 // Match up the template parameter lists with the scope specifier, then
 // determine whether we have a template or a template specialization.
 bool Invalid = false;
+TemplateIdAnnotation *TemplateId =
+D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId
+? D.getName().TemplateId
+: nullptr;
 TemplateParameterList *TemplateParams =
 MatchTemplateParametersToScopeSpecifier(
 D.getDeclSpec().getBeginLoc(), D.getIdentifierLoc(),
-D.getCXXScopeSpec(),
-D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId
-? D.getName().TemplateId
-: nullptr,
-TemplateParamLists, isFriend, isMemberSpecialization,
-Invalid);
+D.getCXXScopeSpec(), TemplateId, TemplateParamLists, isFriend,
+isMemberSpecialization, Invalid);
 if (TemplateParams) {
   // Check that we can declare a template here.
   if (CheckTemplateDeclScope(S, TemplateParams))
@@ -9921,6 +9921,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 if (Name.getNameKind() == DeclarationName::CXXDestructorName) {
   Diag(NewFD->getLocation(), diag::err_destructor_template);
   NewFD->setInvalidDecl();
+  // Function template with explicit template arguments.
+} else if (TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_function_template_partial_spec)
+  << SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc);
+  NewFD->setInvalidDecl();
 }
 
 // If we're adding a template to a dependent context, we may need to
@@ -9973,6 +9978,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 << FixItHint::CreateRemoval(RemoveRange)
 << FixItHint::CreateInsertion(InsertLoc, "<>");
   Invalid = true;
+
+  // Recover by faking up an empty template argument list.
+  HasExplicitTemplateArgs = true;
+  TemplateArgs.setLAngleLoc(InsertLoc);
+  TemplateArgs.setRAngleLoc(InsertLoc);
 }
   }
 } else {
@@ -9986,6 +9996,33 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   if (TemplateParamLists.size() > 0)
 // For source fidelity, store all the template param lists.
 NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists);
+
+  // "friend void foo<>(int);" is an implicit specialization decl.
+  if (isFriend && TemplateId)
+isFunctionTemplateSpecialization = true;
+}
+
+// If this is a function template specialization and the unqualified-id of
+// the declarator-id is a template-id, convert the template argument list
+// into our AST format and check for unexpanded packs.
+if (isFunctionTemplateSpecialization && TemplateId) {
+  HasExplicitTemplateArgs = true;
+
+  TemplateArgs.setLAngleLoc(TemplateId->LAngleLoc);
+  TemplateArgs.setRAngleLoc(TemplateId->RAngleLoc);
+  ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
+ TemplateId->NumArgs);
+  translateTemplateArguments(TemplateArgsPtr, TemplateArgs);
+
+  // FIXME: Should we check for unexpanded packs if this was an (invalid)
+  // declaration of a function template partial specialization? Should we
+  // consider the unexpanded pack context to be a partial specialization?
+  for (const TemplateArgumentLoc &ArgLoc : TemplateArgs.arguments()) {
+if (DiagnoseUnexpandedParameterPack(
+ArgLoc, isFriend ? UPPC_FriendDeclaration
+   

[clang] [Clang][Sema] Diagnose unexpanded packs in the template argument lists of function template specializations (PR #76677)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

This diagnoses unexpanded packs in the _unqualified-id_ of a function template 
specialization's _declarator-id_, e.g.:
```cpp
template
struct A
{
template
void f();

template<>
void f(); // error: explicit specialization contains unexpanded 
parameter pack 'Ts'
};
```

I moved the handling of template-id's so it happens right after we determine 
whether we are declaring a function template/function template specialization 
so diagnostics are issued in lexical order. 

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+43-46) 
- (modified) clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp (+12) 


``diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ffbe317d559995..e94637b4f053e0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9900,15 +9900,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 // Match up the template parameter lists with the scope specifier, then
 // determine whether we have a template or a template specialization.
 bool Invalid = false;
+TemplateIdAnnotation *TemplateId =
+D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId
+? D.getName().TemplateId
+: nullptr;
 TemplateParameterList *TemplateParams =
 MatchTemplateParametersToScopeSpecifier(
 D.getDeclSpec().getBeginLoc(), D.getIdentifierLoc(),
-D.getCXXScopeSpec(),
-D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId
-? D.getName().TemplateId
-: nullptr,
-TemplateParamLists, isFriend, isMemberSpecialization,
-Invalid);
+D.getCXXScopeSpec(), TemplateId, TemplateParamLists, isFriend,
+isMemberSpecialization, Invalid);
 if (TemplateParams) {
   // Check that we can declare a template here.
   if (CheckTemplateDeclScope(S, TemplateParams))
@@ -9921,6 +9921,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 if (Name.getNameKind() == DeclarationName::CXXDestructorName) {
   Diag(NewFD->getLocation(), diag::err_destructor_template);
   NewFD->setInvalidDecl();
+  // Function template with explicit template arguments.
+} else if (TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_function_template_partial_spec)
+  << SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc);
+  NewFD->setInvalidDecl();
 }
 
 // If we're adding a template to a dependent context, we may need to
@@ -9973,6 +9978,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 << FixItHint::CreateRemoval(RemoveRange)
 << FixItHint::CreateInsertion(InsertLoc, "<>");
   Invalid = true;
+
+  // Recover by faking up an empty template argument list.
+  HasExplicitTemplateArgs = true;
+  TemplateArgs.setLAngleLoc(InsertLoc);
+  TemplateArgs.setRAngleLoc(InsertLoc);
 }
   }
 } else {
@@ -9986,6 +9996,33 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   if (TemplateParamLists.size() > 0)
 // For source fidelity, store all the template param lists.
 NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists);
+
+  // "friend void foo<>(int);" is an implicit specialization decl.
+  if (isFriend && TemplateId)
+isFunctionTemplateSpecialization = true;
+}
+
+// If this is a function template specialization and the unqualified-id of
+// the declarator-id is a template-id, convert the template argument list
+// into our AST format and check for unexpanded packs.
+if (isFunctionTemplateSpecialization && TemplateId) {
+  HasExplicitTemplateArgs = true;
+
+  TemplateArgs.setLAngleLoc(TemplateId->LAngleLoc);
+  TemplateArgs.setRAngleLoc(TemplateId->RAngleLoc);
+  ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
+ TemplateId->NumArgs);
+  translateTemplateArguments(TemplateArgsPtr, TemplateArgs);
+
+  // FIXME: Should we check for unexpanded packs if this was an (invalid)
+  // declaration of a function template partial specialization? Should we
+  // consider the unexpanded pack context to be a partial specialization?
+  for (const TemplateArgumentLoc &ArgLoc : TemplateArgs.arguments()) {
+if (DiagnoseUnexpandedParameterPack(
+ArgLoc, isFriend ? UPPC_FriendDeclaration
+ : UPPC_ExplicitSpecialization))
+  NewFD->setInvalidDecl();
+  }
 }
 
 if (Invalid) {
@@ -10438,46 +10475,6 @@ Sema::ActOnFunctionDecl

[clang] [Clang][Sema] Diagnose unexpanded packs in the template argument lists of function template specializations (PR #76677)

2024-01-01 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

Ping @erichkeane 

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


[clang] [Clang][Sema] Diagnose unexpanded packs in the template argument lists of function template specializations (PR #76677)

2024-01-01 Thread Krystian Stasiowski via cfe-commits

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


[lld] [clang] [clang-tools-extra] [libcxx] [compiler-rt] [flang] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-01 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,71 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::sentinel
+
+// template
+//   requires sentinel_for, 
iterator_t>>
+// friend constexpr bool operator==(const iterator& x, const 
sentinel& y);
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+template >
+constexpr void test() {
+  using View = MinimalView;
+
+  std::array array{0, 1, 2, 3, 84};
+
+  View v(Iterator(array.begin()), Sentinel(Iterator(array.end(;
+  std::ranges::enumerate_view view(std::move(v));
+
+  auto const it = view.begin();
+  auto const s  = view.end();
+
+  std::same_as decltype(auto) eqItSResult = (it == s);
+  assert(!eqItSResult);
+  std::same_as decltype(auto) eqSItResult = (s == it);
+  assert(!eqSItResult);
+
+  std::same_as decltype(auto) neqItSResult = (it != s);
+  assert(neqItSResult);
+  std::same_as decltype(auto) neqSItResult = (s != it);
+  assert(neqSItResult);
+}
+
+constexpr bool tests() {
+  test>();

H-G-Hristov wrote:

I'll keep this as is for now. If we do the suggested changes, I'll prefer to do 
them after everything else is ironed out.

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


[lld] [clang] [clang-tools-extra] [libcxx] [compiler-rt] [flang] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov edited 
https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Pol M via cfe-commits


@@ -10895,6 +10899,138 @@ bool VectorExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+return false;
+
+  if (Result.isLValue()) {
+// Source of the data is an lvalue; Manually handle the lvalue as if
+// it was an rvalue to get the current APValue.
+LValue LValueFound;
+LValueFound.setFrom(Info.Ctx, Result);
+if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result)) {
+  return false;
+}
+  }
+
+  if (!Result.isVector()) {
+return false;
+  }
+  return true;
+}
+
+static bool handleVectorConversion(EvalInfo &Info, const FPOptions FPO,
+   const Expr *E, QualType SourceTy,
+   QualType DestTy, APValue const &Original,
+   APValue &Result) {
+  if (SourceTy->isIntegerType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = APValue(APFloat(0.0));
+  return HandleIntToFloatCast(Info, E, FPO, SourceTy, Original.getInt(),
+  DestTy, Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(
+  HandleIntToIntCast(Info, E, DestTy, SourceTy, Original.getInt()));
+  return true;
+}
+  } else if (SourceTy->isRealFloatingType()) {
+if (DestTy->isRealFloatingType()) {
+  Result = Original;
+  return HandleFloatToFloatCast(Info, E, SourceTy, DestTy,
+Result.getFloat());
+}
+if (DestTy->isIntegerType()) {
+  Result = APValue(APSInt());
+  return HandleFloatToIntCast(Info, E, SourceTy, Original.getFloat(),
+  DestTy, Result.getInt());
+}
+  }
+  return false;
+}
+
+bool VectorExprEvaluator::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
+  APValue Source;
+  QualType SourceVecType = E->getSrcExpr()->getType();
+  if (!EvaluateVectorOrLValue(Source, Info, E->getSrcExpr(), SourceVecType))
+return false;
+
+  QualType DestTy = E->getType()->castAs()->getElementType();
+  QualType SourceTy = SourceVecType->castAs()->getElementType();
+
+  const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+
+  SmallVector ResultElements;
+  ResultElements.reserve(Source.getVectorLength());
+  for (unsigned EltNum = 0; EltNum < Source.getVectorLength(); ++EltNum) {
+APValue Elt;
+if (!handleVectorConversion(Info, FPO, E, SourceTy, DestTy,
+Source.getVectorElt(EltNum), Elt))
+  return false;
+ResultElements.push_back(std::move(Elt));
+  }
+
+  return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+}
+
+static bool handleVectorShuffle(EvalInfo &Info, const ShuffleVectorExpr *E,
+QualType ElemType, APValue const &VecVal1,
+APValue const &VecVal2, unsigned EltNum,
+APValue &Result) {
+  unsigned const TotalElementsInAVector = VecVal1.getVectorLength();
+
+  Expr const *IndexExpr = E->getExpr(2 + EltNum);
+  APSInt IndexVal;
+  if (!EvaluateInteger(IndexExpr, IndexVal, Info)) {
+return false;
+  }
+
+  uint32_t index = IndexVal.getZExtValue();
+  // The spec says that -1 should be treated as undef for optimizations,
+  // but in constexpr we need to choose a value. We'll choose 0.
+  if (index >= TotalElementsInAVector * 2) {
+index = 0;
+  }

Destroyerrrocket wrote:

If there is, I unfortunately don't know how...

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Pol M via cfe-commits


@@ -302,3 +302,64 @@ extern __typeof__(__builtin_expect(0, 0)) bi0;
 // Strings
 int array1[__builtin_strlen("ab\0cd")];
 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
+
+typedef double vector4double __attribute__((__vector_size__(32)));
+typedef float vector4float __attribute__((__vector_size__(16)));
+typedef long long vector4long __attribute__((__vector_size__(32)));
+typedef int vector4int __attribute__((__vector_size__(16)));
+typedef short vector4short __attribute__((__vector_size__(8)));
+typedef char vector4char __attribute__((__vector_size__(4)));
+typedef double vector8double __attribute__((__vector_size__(64)));
+typedef float vector8float __attribute__((__vector_size__(32)));
+typedef long long vector8long __attribute__((__vector_size__(64)));
+typedef int vector8int __attribute__((__vector_size__(32)));
+typedef short vector8short __attribute__((__vector_size__(16)));
+typedef char vector8char __attribute__((__vector_size__(8)));
+
+// Convert vector
+#define CHECK_NUM(__size, __typeFrom, __typeTo, ...)   
 \
+  vector##__size##__typeTo 
 \
+  from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var 
= \
+  __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__},   
 \
+  vector##__size##__typeTo);
+#define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...)
\
+  CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__)   
\
+  CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) 
\
+  CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__)  
\
+  CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__)
+
+#define CHECK_ALL_COMBINATIONS(__size, ...)
\
+  CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__)  
\
+  CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__)
\
+  CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) 
\
+  CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__)
+
+CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3);
+CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7);
+#undef CHECK_ALL_COMBINATIONS
+#undef CHECK_TO_ALL_TYPES
+#undef CHECK_NUM
+
+// Shuffle vector
+vector4int const vector4intConst1 = {0, 1, 2, 3};
+vector4int const vector4intConst2 = {4, 5, 6, 7};
+vector8int const vector8intConst = {};
+
+vector4int vectorShuffle1 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 1, 2, 3);
+vector4int vectorShuffle2 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 4, 5, 6, 7);
+vector4int vectorShuffle3 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, -1, -1, -1, 
-1);
+vector4int vectorShuffle4 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6);
+vector8int vectorShuffle5 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14);
+vector4int vectorShuffle6 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6);
+vector8int vectorShuffle7 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6, 1, 
3, 5, 7);

Destroyerrrocket wrote:

You're right! we can indeed make something like:
constexpr vector4char v = {1,2,3,4};
static_assert(std::bit_cast(v) == 0x4030201, "equal");
I had initially dismissed this as the operator[] is not implemented for 
vectors. This is endian dependent, is there a particular way I should handle 
this?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy created 
https://github.com/llvm/llvm-project/pull/76680

**Overview:**
This pull request fixes #47355 where in the Clang compiler's 
range-loop-analysis incorrectly checks for trivial copyability instead of 
trivial copy constructibility, leading to erroneous warnings.

**Changes Made:**
- The changes made in this commit address the issue by introducing a new member 
function `isTriviallyCopyConstructible` in the `CXXRecordDecl` class and 
implementing it in the associated files `(clang/include/clang/AST/DeclCXX.h, 
clang/lib/AST/DeclCXX.cpp)`. Additionally, modifications are made in 
`clang/include/clang/AST/Type.h` and `clang/lib/AST/Type.cpp` to support the 
new function. The implementation checks for trivial copy constructibility, 
distinguishing it from the existing `isTriviallyCopyable` check. The issue in 
`clang/lib/Sema/SemaStmt.cpp` is also addressed by updating the conditional 
check in the `DiagnoseForRangeConstVariableCopies` function to use the new 
`isTriviallyCopyConstructibleType` function. Overall, these changes aim to 
correct the range-loop-analysis by ensuring it checks for trivial copy 
constructibility rather than trivial copyability.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-01 
19-50-20](https://github.com/llvm/llvm-project/assets/76656712/c664f01a-522e-45e4-8363-39f13d8cc241)


**Dependencies:**
- No dependencies on other pull requests.

**References:**
- https://cplusplus.com/reference/type_traits/is_trivially_copy_constructible/
- https://en.cppreference.com/w/cpp/named_req/CopyConstructible
- https://cplusplus.com/reference/type_traits/is_trivially_copyable/

**CC:**
- @Endilll , @r4nt , @AaronBallman 


>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext &Context) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext &Context) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these ty

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bhuminjay Soni (11happy)


Changes

**Overview:**
This pull request fixes #47355 where in the Clang compiler's 
range-loop-analysis incorrectly checks for trivial copyability instead of 
trivial copy constructibility, leading to erroneous warnings.

**Changes Made:**
- The changes made in this commit address the issue by introducing a new member 
function `isTriviallyCopyConstructible` in the `CXXRecordDecl` class and 
implementing it in the associated files `(clang/include/clang/AST/DeclCXX.h, 
clang/lib/AST/DeclCXX.cpp)`. Additionally, modifications are made in 
`clang/include/clang/AST/Type.h` and `clang/lib/AST/Type.cpp` to support the 
new function. The implementation checks for trivial copy constructibility, 
distinguishing it from the existing `isTriviallyCopyable` check. The issue in 
`clang/lib/Sema/SemaStmt.cpp` is also addressed by updating the conditional 
check in the `DiagnoseForRangeConstVariableCopies` function to use the new 
`isTriviallyCopyConstructibleType` function. Overall, these changes aim to 
correct the range-loop-analysis by ensuring it checks for trivial copy 
constructibility rather than trivial copyability.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-01 
19-50-20](https://github.com/llvm/llvm-project/assets/76656712/c664f01a-522e-45e4-8363-39f13d8cc241)


**Dependencies:**
- No dependencies on other pull requests.

**References:**
- https://cplusplus.com/reference/type_traits/is_trivially_copy_constructible/
- https://en.cppreference.com/w/cpp/named_req/CopyConstructible
- https://cplusplus.com/reference/type_traits/is_trivially_copyable/

**CC:**
- @Endilll , @r4nt , @AaronBallman 


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


5 Files Affected:

- (modified) clang/include/clang/AST/DeclCXX.h (+3) 
- (modified) clang/include/clang/AST/Type.h (+3) 
- (modified) clang/lib/AST/DeclCXX.cpp (+13) 
- (modified) clang/lib/AST/Type.cpp (+43) 
- (modified) clang/lib/Sema/SemaStmt.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext &Context) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext &Context) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (

[clang-tools-extra] [llvm] [clang] [mlir] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread via cfe-commits

https://github.com/schenka0 updated 
https://github.com/llvm/llvm-project/pull/76668

>From c9e2b9ad57aa9bac52324c91fe6d4ec1aa39ff41 Mon Sep 17 00:00:00 2001
From: schenka0 <154034018+schen...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 01:31:05 -0500
Subject: [PATCH 1/2] Check for invalid SLocEntry before getting spelling

---
 clang-tools-extra/clangd/SourceCode.cpp|  7 ++-
 .../clangd/unittests/SourceCodeTests.cpp   | 14 ++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 835038423fdf37..64e0acb322350c 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   if (Loc.isFileID())
 return true;
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
-  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  bool InvalidSLocEntry = false;
+  const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
+  if(InvalidSLocEntry) {
+return false;
+  }
+  const StringRef SpellingFile = SLocEntry.getFile().getName();
   if (SpellingFile == "")
 return false;
   if (SpellingFile == "")
diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp 
b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
index 08abde87df6d4d..be052dd265e81f 100644
--- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -813,6 +813,20 @@ TEST(SourceCodeTests, isKeywords) {
   EXPECT_FALSE(isKeyword("override", LangOpts));
 }
 
+TEST(SourceCodeTests, isSpelledInSource) {
+Annotations Test(R"cpp(
+int abc = 1;
+)cpp");
+
+  ParsedAST AST = TestTU::withCode(Test.code()).build();
+  llvm::errs() << Test.code();
+  const SourceManager &SM = AST.getSourceManager();
+
+  EXPECT_TRUE(isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), 
SM));
+  EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
+  EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM));
+}
+
 struct IncrementalTestStep {
   llvm::StringRef Src;
   llvm::StringRef Contents;

>From 833e1dbb45a58e8c8b9d6a9087a92df19250e378 Mon Sep 17 00:00:00 2001
From: schenka0 <154034018+schen...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 01:37:29 -0500
Subject: [PATCH 2/2] clang format changes

---
 clang-tools-extra/clangd/SourceCode.cpp| 2 +-
 clang-tools-extra/clangd/unittests/SourceCodeTests.cpp | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 64e0acb322350c..8c573cc6fc064a 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -234,7 +234,7 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
   bool InvalidSLocEntry = false;
   const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
-  if(InvalidSLocEntry) {
+  if (InvalidSLocEntry) {
 return false;
   }
   const StringRef SpellingFile = SLocEntry.getFile().getName();
diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp 
b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
index be052dd265e81f..5dced4d317c605 100644
--- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -814,7 +814,7 @@ TEST(SourceCodeTests, isKeywords) {
 }
 
 TEST(SourceCodeTests, isSpelledInSource) {
-Annotations Test(R"cpp(
+  Annotations Test(R"cpp(
 int abc = 1;
 )cpp");
 
@@ -822,7 +822,8 @@ TEST(SourceCodeTests, isSpelledInSource) {
   llvm::errs() << Test.code();
   const SourceManager &SM = AST.getSourceManager();
 
-  EXPECT_TRUE(isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), 
SM));
+  EXPECT_TRUE(
+  isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM));
   EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
   EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM));
 }

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Simon Pilgrim via cfe-commits


@@ -302,3 +302,64 @@ extern __typeof__(__builtin_expect(0, 0)) bi0;
 // Strings
 int array1[__builtin_strlen("ab\0cd")];
 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
+
+typedef double vector4double __attribute__((__vector_size__(32)));
+typedef float vector4float __attribute__((__vector_size__(16)));
+typedef long long vector4long __attribute__((__vector_size__(32)));
+typedef int vector4int __attribute__((__vector_size__(16)));
+typedef short vector4short __attribute__((__vector_size__(8)));
+typedef char vector4char __attribute__((__vector_size__(4)));
+typedef double vector8double __attribute__((__vector_size__(64)));
+typedef float vector8float __attribute__((__vector_size__(32)));
+typedef long long vector8long __attribute__((__vector_size__(64)));
+typedef int vector8int __attribute__((__vector_size__(32)));
+typedef short vector8short __attribute__((__vector_size__(16)));
+typedef char vector8char __attribute__((__vector_size__(8)));
+
+// Convert vector
+#define CHECK_NUM(__size, __typeFrom, __typeTo, ...)   
 \
+  vector##__size##__typeTo 
 \
+  from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var 
= \
+  __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__},   
 \
+  vector##__size##__typeTo);
+#define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...)
\
+  CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__)   
\
+  CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) 
\
+  CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__)  
\
+  CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__)
+
+#define CHECK_ALL_COMBINATIONS(__size, ...)
\
+  CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__)  
\
+  CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__)
\
+  CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) 
\
+  CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__)
+
+CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3);
+CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7);
+#undef CHECK_ALL_COMBINATIONS
+#undef CHECK_TO_ALL_TYPES
+#undef CHECK_NUM
+
+// Shuffle vector
+vector4int const vector4intConst1 = {0, 1, 2, 3};
+vector4int const vector4intConst2 = {4, 5, 6, 7};
+vector8int const vector8intConst = {};
+
+vector4int vectorShuffle1 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 1, 2, 3);
+vector4int vectorShuffle2 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 4, 5, 6, 7);
+vector4int vectorShuffle3 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, -1, -1, -1, 
-1);
+vector4int vectorShuffle4 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6);
+vector8int vectorShuffle5 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14);
+vector4int vectorShuffle6 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6);
+vector8int vectorShuffle7 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6, 1, 
3, 5, 7);

RKSimon wrote:

Maybe use the same 'LITTLE_END' define approach used in 
clang\test\SemaCXX\constexpr-builtin-bit-cast.cpp?

How much work will it to be to eventually implement the vector operator[] as a 
constexpr as well do you think?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Can you add some tests?

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Pol M via cfe-commits


@@ -302,3 +302,64 @@ extern __typeof__(__builtin_expect(0, 0)) bi0;
 // Strings
 int array1[__builtin_strlen("ab\0cd")];
 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
+
+typedef double vector4double __attribute__((__vector_size__(32)));
+typedef float vector4float __attribute__((__vector_size__(16)));
+typedef long long vector4long __attribute__((__vector_size__(32)));
+typedef int vector4int __attribute__((__vector_size__(16)));
+typedef short vector4short __attribute__((__vector_size__(8)));
+typedef char vector4char __attribute__((__vector_size__(4)));
+typedef double vector8double __attribute__((__vector_size__(64)));
+typedef float vector8float __attribute__((__vector_size__(32)));
+typedef long long vector8long __attribute__((__vector_size__(64)));
+typedef int vector8int __attribute__((__vector_size__(32)));
+typedef short vector8short __attribute__((__vector_size__(16)));
+typedef char vector8char __attribute__((__vector_size__(8)));
+
+// Convert vector
+#define CHECK_NUM(__size, __typeFrom, __typeTo, ...)   
 \
+  vector##__size##__typeTo 
 \
+  from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var 
= \
+  __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__},   
 \
+  vector##__size##__typeTo);
+#define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...)
\
+  CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__)   
\
+  CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) 
\
+  CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__)  
\
+  CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__)
+
+#define CHECK_ALL_COMBINATIONS(__size, ...)
\
+  CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__)  
\
+  CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__)
\
+  CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) 
\
+  CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__)
+
+CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3);
+CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7);
+#undef CHECK_ALL_COMBINATIONS
+#undef CHECK_TO_ALL_TYPES
+#undef CHECK_NUM
+
+// Shuffle vector
+vector4int const vector4intConst1 = {0, 1, 2, 3};
+vector4int const vector4intConst2 = {4, 5, 6, 7};
+vector8int const vector8intConst = {};
+
+vector4int vectorShuffle1 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 1, 2, 3);
+vector4int vectorShuffle2 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 4, 5, 6, 7);
+vector4int vectorShuffle3 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, -1, -1, -1, 
-1);
+vector4int vectorShuffle4 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6);
+vector8int vectorShuffle5 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14);
+vector4int vectorShuffle6 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6);
+vector8int vectorShuffle7 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6, 1, 
3, 5, 7);

Destroyerrrocket wrote:

Yep, I'll copy that over.

Well, in that case I would have to care about lvalues (in my code I just needed 
the values to return a new copy, so I could ignore all that machinery for now). 
I'd have to learn how these work more in depth. I don't think they'd be 
necessarily super complicated, and that would make for an ideal follow-up for 
me! (looks like this would be part of: 
https://github.com/llvm/llvm-project/issues/41806, and also this also looks 
interesting: https://github.com/llvm/llvm-project/issues/30794)

I think this is a pretty interesting set of tasks to work on!

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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-01-01 Thread Pol M via cfe-commits


@@ -302,3 +302,64 @@ extern __typeof__(__builtin_expect(0, 0)) bi0;
 // Strings
 int array1[__builtin_strlen("ab\0cd")];
 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
+
+typedef double vector4double __attribute__((__vector_size__(32)));
+typedef float vector4float __attribute__((__vector_size__(16)));
+typedef long long vector4long __attribute__((__vector_size__(32)));
+typedef int vector4int __attribute__((__vector_size__(16)));
+typedef short vector4short __attribute__((__vector_size__(8)));
+typedef char vector4char __attribute__((__vector_size__(4)));
+typedef double vector8double __attribute__((__vector_size__(64)));
+typedef float vector8float __attribute__((__vector_size__(32)));
+typedef long long vector8long __attribute__((__vector_size__(64)));
+typedef int vector8int __attribute__((__vector_size__(32)));
+typedef short vector8short __attribute__((__vector_size__(16)));
+typedef char vector8char __attribute__((__vector_size__(8)));
+
+// Convert vector
+#define CHECK_NUM(__size, __typeFrom, __typeTo, ...)   
 \
+  vector##__size##__typeTo 
 \
+  from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var 
= \
+  __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__},   
 \
+  vector##__size##__typeTo);
+#define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...)
\
+  CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__)   
\
+  CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) 
\
+  CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__)  
\
+  CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__)
\
+  CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__)
+
+#define CHECK_ALL_COMBINATIONS(__size, ...)
\
+  CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__)  
\
+  CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__)
\
+  CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) 
\
+  CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__)   
\
+  CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__)
+
+CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3);
+CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7);
+#undef CHECK_ALL_COMBINATIONS
+#undef CHECK_TO_ALL_TYPES
+#undef CHECK_NUM
+
+// Shuffle vector
+vector4int const vector4intConst1 = {0, 1, 2, 3};
+vector4int const vector4intConst2 = {4, 5, 6, 7};
+vector8int const vector8intConst = {};
+
+vector4int vectorShuffle1 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 1, 2, 3);
+vector4int vectorShuffle2 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 4, 5, 6, 7);
+vector4int vectorShuffle3 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, -1, -1, -1, 
-1);
+vector4int vectorShuffle4 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6);
+vector8int vectorShuffle5 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14);
+vector4int vectorShuffle6 = __builtin_shufflevector(
+vector8intConst, vector8intConst, 0, 2, 4, 6);
+vector8int vectorShuffle7 =
+__builtin_shufflevector(vector4intConst1, vector4intConst2, 0, 2, 4, 6, 1, 
3, 5, 7);

Destroyerrrocket wrote:

But just for this validation, I'd definitiely take the bitcast approach

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Sure I can , I have also tested the code that was giving erroneous warnings, so 
should I add that example as well?? 

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Sure I can , I have also tested the code that was giving erroneous warnings, 
> so should I add that example as well??

Yes. Clang has a special mode which check which diagnostics are emitted: 
https://clang.llvm.org/docs/InternalsManual.html#verifying-diagnostics

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


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-01 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/75440

>From ce9db667e6567532fe119ff8d793281215f223dc Mon Sep 17 00:00:00 2001
From: hstk30-hw 
Date: Thu, 14 Dec 2023 15:40:03 +0800
Subject: [PATCH] feat: arm_acle.h add Coprocessor Instrinsics

---
 clang/lib/Basic/Targets/ARM.cpp   |  65 
 clang/lib/Basic/Targets/ARM.h |  13 +
 clang/lib/Headers/arm_acle.h  |  52 +++
 clang/test/CodeGen/arm-acle-coproc.c  | 346 ++
 .../Preprocessor/aarch64-target-features.c|   1 +
 5 files changed, 477 insertions(+)
 create mode 100644 clang/test/CodeGen/arm-acle-coproc.c

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index ce7e4d4639ceac..d68ae21b219535 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/ARMTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -836,6 +837,70 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARM5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  }
+  Builder.defineMacro("__ARM_FEATURE_COPROC",
+  "0x" + Twine::utohexstr(FeatureCoprocBF));
+
   if (ArchKind == llvm::ARM::ArchKind::XSCALE)
 Builder.defineMacro("__XSCALE__");
 
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index b1aa2794c7e4c3..9802eb01abf3c4 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -100,6 +100,19 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
   };
   uint32_t HW_FP;
 
+  enum {
+/// __arm_cdp __arm_ldc, __arm_ldcl, __arm_stc,
+/// __arm_stcl, __arm_mcr and __arm_mrc
+FEATURE_COPROC_B1 = (1 << 0),
+/// __arm_cdp2, __arm_ldc2, __arm_stc2, __arm_ldc2l,
+/// __arm_stc2l, __arm_mcr2 and __arm_mrc2
+FEATURE_COPROC_B2 = (1 << 1),
+/// __arm_mcrr, __arm_mrrc
+FEATURE_COPROC_B3 = (1 << 2),
+/// __arm_mcrr2,  __arm_mrrc2
+FEATURE_COPROC_B4 = (1 << 3),
+  };
+
   void setABIAAPCS();
   void setABIAPCS(bool IsAAPCS16);
 
diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 61d80258d166a1..8a7e9a7930920b 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -756,6 +756,58 @@ __arm_st64bv0(void *__addr, data512_t __value) {
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif
 
+/* Coprocessor Intrinsics */
+#if defined(__ARM_FEATURE_COPROC)
+
+#if (__ARM

[llvm] [libcxx] [flang] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov ready_for_review 
https://github.com/llvm/llvm-project/pull/76632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [flang] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

This test is failing but I have no idea how to fix it:  
@github-actions
Build and Test libc++ / stage3 (generic-no-localization, libcxx-runners-8-set, 
OFF) (pull_request) Failing after 1m

https://github.com/llvm/llvm-project/actions/runs/7377144646/job/20072043476?pr=76632#step:3:1467

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


[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread via cfe-commits

https://github.com/schenka0 updated 
https://github.com/llvm/llvm-project/pull/76668

>From fd5e586d807fa4532f26188822ac5790202673bc Mon Sep 17 00:00:00 2001
From: schenka0 <154034018+schen...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 01:31:05 -0500
Subject: [PATCH] Check for invalid SLocEntry before getting spelling

---
 clang-tools-extra/clangd/SourceCode.cpp   |  7 ++-
 .../clangd/unittests/SourceCodeTests.cpp  | 15 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 835038423fdf37..8c573cc6fc064a 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   if (Loc.isFileID())
 return true;
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
-  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  bool InvalidSLocEntry = false;
+  const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
+  if (InvalidSLocEntry) {
+return false;
+  }
+  const StringRef SpellingFile = SLocEntry.getFile().getName();
   if (SpellingFile == "")
 return false;
   if (SpellingFile == "")
diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp 
b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
index 08abde87df6d4d..5dced4d317c605 100644
--- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) {
   EXPECT_FALSE(isKeyword("override", LangOpts));
 }
 
+TEST(SourceCodeTests, isSpelledInSource) {
+  Annotations Test(R"cpp(
+int abc = 1;
+)cpp");
+
+  ParsedAST AST = TestTU::withCode(Test.code()).build();
+  llvm::errs() << Test.code();
+  const SourceManager &SM = AST.getSourceManager();
+
+  EXPECT_TRUE(
+  isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM));
+  EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
+  EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM));
+}
+
 struct IncrementalTestStep {
   llvm::StringRef Src;
   llvm::StringRef Contents;

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


[llvm] [libcxx] [flang] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/76632

>From 1165b11477ab59122a4db35221fcefe3c9505387 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 30 Dec 2023 17:34:56 +0200
Subject: [PATCH 01/16] [libc++][streams] P1759R6: Native handles and file
 streams

Implements: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1759r6.html

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 59 +++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 33 +++
 .../fstream.version.compile.pass.cpp  | 16 ++---
 .../version.version.compile.pass.cpp  | 16 ++---
 .../generate_feature_test_macro_components.py |  1 -
 10 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index ad12b109023154..0427615a9636fd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fa60a581652d6a..e6f1adf4d5529b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -58,6 +58,7 @@ Implemented Papers
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..1d7807a4291a99 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R2 `__","LWG","More ``constexpr`` for 
 and ","Varna June 2023","","",""
 "`P2734R0 `__","LWG","Adding the new SI 
prefixes","Varna June 2023","|Complete|","17.0",""
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 7a4e15b55d56fe..9609ff420220fa 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -73,6 +73,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ifstream();
 explicit basic_ifstream(const char* s, ios_base::openmode mode = 
ios_base::in);
@@ -85,6 +86,7 @@ public:
 void swap(basic_ifstream& rhs);
 
 basic_filebuf* rdbuf() const;
+native_handle_type native_handle() const noexcept; // Since C++26
 bool is_open() const;
 void open(const char* s, ios_base::openmode mode = ios_base::in);
 void open(const string& s, ios_base::openmode mode = ios_base::in);
@@ -110,6 +112,7 @@ public:
 typedef typename traits_type::int_type int_type;
 typedef typename traits_type::pos_type pos_type;
 typedef typename traits_type::off_type off_type;
+using native_handle_type = typename basic_filebuf::native_handle_type; // Since C++26
 
 basic_ofstream();
 explicit basic_ofstream(const char* s, ios_base::o

[clang] [clang-format] Fix erroneous BraceWrapping.BeforeLambdaBody column calcs (PR #76673)

2024-01-01 Thread Björn Schäpers via cfe-commits


@@ -22965,6 +22965,84 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
"};");
 }
 
+TEST_F(FormatTest, BreakBeforeLambdaBodyWrapping) {
+  verifyFormat("connect([]() {\n"
+   "  foo();\n"
+   "  bar();\n"
+   "});");
+
+  auto Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.BeforeLambdaBody = true;
+
+  verifyFormat("connect(\n"
+   "[]()\n"
+   "{\n"
+   "  foo();\n"
+   "  bar();\n"
+   "});",
+   Style);
+
+  for (unsigned l : {0, 41}) {

HazardyKnusperkeks wrote:

Don't loop. Pick some values.

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


[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

2024-01-01 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

I think that's not the right way to fix the issue.

Why are the 2 lines formatted differently? It seems to me that this fixes the 
symptom, not the cause.

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 1/2] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext &Context) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext &Context) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
&SemaRef,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext &Ctx = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87 M

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-01 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

I have added the tests as well.


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


[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)

2024-01-01 Thread via cfe-commits

https://github.com/schenka0 updated 
https://github.com/llvm/llvm-project/pull/76668

>From fd5e586d807fa4532f26188822ac5790202673bc Mon Sep 17 00:00:00 2001
From: schenka0 <154034018+schen...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 01:31:05 -0500
Subject: [PATCH 1/2] Check for invalid SLocEntry before getting spelling

---
 clang-tools-extra/clangd/SourceCode.cpp   |  7 ++-
 .../clangd/unittests/SourceCodeTests.cpp  | 15 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 835038423fdf37..8c573cc6fc064a 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   if (Loc.isFileID())
 return true;
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
-  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  bool InvalidSLocEntry = false;
+  const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
+  if (InvalidSLocEntry) {
+return false;
+  }
+  const StringRef SpellingFile = SLocEntry.getFile().getName();
   if (SpellingFile == "")
 return false;
   if (SpellingFile == "")
diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp 
b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
index 08abde87df6d4d..5dced4d317c605 100644
--- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) {
   EXPECT_FALSE(isKeyword("override", LangOpts));
 }
 
+TEST(SourceCodeTests, isSpelledInSource) {
+  Annotations Test(R"cpp(
+int abc = 1;
+)cpp");
+
+  ParsedAST AST = TestTU::withCode(Test.code()).build();
+  llvm::errs() << Test.code();
+  const SourceManager &SM = AST.getSourceManager();
+
+  EXPECT_TRUE(
+  isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM));
+  EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
+  EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM));
+}
+
 struct IncrementalTestStep {
   llvm::StringRef Src;
   llvm::StringRef Contents;

>From 612c1fea8de7dfea67d5b4fdd23d6f13b9851607 Mon Sep 17 00:00:00 2001
From: schenka0 <154034018+schen...@users.noreply.github.com>
Date: Mon, 1 Jan 2024 11:49:24 -0500
Subject: [PATCH 2/2] Update clang-tools-extra/clangd/SourceCode.cpp

Co-authored-by: Younan Zhang 
---
 clang-tools-extra/clangd/SourceCode.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 8c573cc6fc064a..58a0d142777d00 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -234,9 +234,8 @@ bool isSpelledInSource(SourceLocation Loc, const 
SourceManager &SM) {
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
   bool InvalidSLocEntry = false;
   const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
-  if (InvalidSLocEntry) {
+  if (InvalidSLocEntry)
 return false;
-  }
   const StringRef SpellingFile = SLocEntry.getFile().getName();
   if (SpellingFile == "")
 return false;

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


[compiler-rt] [clang] [libcxx] [lldb] [mlir] [llvm] [libc] [openmp] [flang] [clang-tools-extra] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Nikolas Klauser via cfe-commits

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

Other than the test this LGTM.

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


[clang] [lldb] [flang] [libcxx] [openmp] [llvm] [compiler-rt] [clang-tools-extra] [mlir] [libc] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Nikolas Klauser via cfe-commits

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


[llvm] [compiler-rt] [libcxx] [libc] [openmp] [lldb] [mlir] [clang] [flang] [clang-tools-extra] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,136 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr void testSpanAt(auto span, int idx, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = 
span.at(idx);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(span).at(idx);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {

philnik777 wrote:

I don't think you've addressed this?

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


[clang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits


@@ -31,14 +31,14 @@ class InvalidatedIteratorChecker
check::PreStmt,
check::PreStmt> {
 
-  std::unique_ptr InvalidatedBugType;
+  const BugType InvalidatedBugType{this, "Iterator invalidated",
+   "Misuse of STL APIs"};
 
   void verifyAccess(CheckerContext &C, const SVal &Val) const;
-  void reportBug(const StringRef &Message, const SVal &Val,
- CheckerContext &C, ExplodedNode *ErrNode) const;
-public:
-  InvalidatedIteratorChecker();
+  void reportBug(const StringRef &Message, const SVal &Val, CheckerContext &C,

steakhal wrote:

Same for the `SVal`. Done.

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


[clang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits


@@ -17,19 +17,18 @@
 
 #include "MPITypes.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace clang {
 namespace ento {
 namespace mpi {
 
 class MPIBugReporter {
 public:
-  MPIBugReporter(const CheckerBase &CB) {
-UnmatchedWaitBugType.reset(new BugType(&CB, "Unmatched wait", MPIError));
-DoubleNonblockingBugType.reset(
-new BugType(&CB, "Double nonblocking", MPIError));
-MissingWaitBugType.reset(new BugType(&CB, "Missing wait", MPIError));
-  }
+  MPIBugReporter(const CheckerBase &CB)
+  : UnmatchedWaitBugType(&CB, "Unmatched wait", MPIError),

steakhal wrote:

I considered that, but couldn't as `CB` is a ctor param. I don't have that in a 
field init context.

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


[flang] [lld] [mlir] [llvm] [libcxx] [clang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits


@@ -52,10 +52,13 @@ class SimpleStreamChecker : public Checker {
-  CallDescription OpenFn, CloseFn;
+  const CallDescription OpenFn{{"fopen"}, 2};
+  const CallDescription CloseFn{{"fclose"}, 1};

steakhal wrote:

Well, it seems like `StringRef` is not constexpr for some reason - and I'm 
using that inside.
Consequently, that's a blocker.

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


[flang] [lld] [mlir] [llvm] [libcxx] [clang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits

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


[flang] [lld] [mlir] [llvm] [libcxx] [clang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits


@@ -52,10 +52,13 @@ class SimpleStreamChecker : public Checker {
-  CallDescription OpenFn, CloseFn;
+  const CallDescription OpenFn{{"fopen"}, 2};
+  const CallDescription CloseFn{{"fclose"}, 1};

steakhal wrote:

Here is why we can't have CallDescriptions constexpr:
It's an owning type, holding a `std::vector`, and they are 
themselves non-constexpr, until IDK cpp20+?
So, this is resolved.

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


[flang] [lld] [mlir] [llvm] [libcxx] [clang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer][NFC] Take small objects by value (PR #76688)

2024-01-01 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/76688

None

>From 70c03932cad401f477674881050a8f0c4b573cdb Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Mon, 1 Jan 2024 18:59:46 +0100
Subject: [PATCH 1/2] [analyzer][NFC] Take StringRef by value

---
 .../Checkers/IteratorRangeChecker.cpp |  4 ++--
 .../Checkers/MismatchedIteratorChecker.cpp| 20 ---
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
index f966ea63da2181..f9263f439b1e3d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -43,7 +43,7 @@ class IteratorRangeChecker
   void verifyAdvance(CheckerContext &C, SVal LHS, SVal RHS) const;
   void verifyPrev(CheckerContext &C, SVal LHS, SVal RHS) const;
   void verifyNext(CheckerContext &C, SVal LHS, SVal RHS) const;
-  void reportBug(const StringRef &Message, SVal Val, CheckerContext &C,
+  void reportBug(StringRef Message, SVal Val, CheckerContext &C,
  ExplodedNode *ErrNode) const;
 
 public:
@@ -269,7 +269,7 @@ void IteratorRangeChecker::verifyNext(CheckerContext &C, 
SVal LHS,
   verifyRandomIncrOrDecr(C, OO_Plus, LHS, RHS);
 }
 
-void IteratorRangeChecker::reportBug(const StringRef &Message, SVal Val,
+void IteratorRangeChecker::reportBug(StringRef Message, SVal Val,
  CheckerContext &C,
  ExplodedNode *ErrNode) const {
   auto R = std::make_unique(OutOfRangeBugType, Message,
diff --git a/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
index 38f80ba5e1ff39..8116105a50eb08 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
@@ -38,12 +38,10 @@ class MismatchedIteratorChecker
const MemRegion *Cont) const;
   void verifyMatch(CheckerContext &C, const SVal &Iter1,
const SVal &Iter2) const;
-  void reportBug(const StringRef &Message, const SVal &Val1,
- const SVal &Val2, CheckerContext &C,
- ExplodedNode *ErrNode) const;
-  void reportBug(const StringRef &Message, const SVal &Val,
- const MemRegion *Reg, CheckerContext &C,
- ExplodedNode *ErrNode) const;
+  void reportBug(StringRef Message, const SVal &Val1, const SVal &Val2,
+ CheckerContext &C, ExplodedNode *ErrNode) const;
+  void reportBug(StringRef Message, const SVal &Val, const MemRegion *Reg,
+ CheckerContext &C, ExplodedNode *ErrNode) const;
 
 public:
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
@@ -271,10 +269,8 @@ void MismatchedIteratorChecker::verifyMatch(CheckerContext 
&C,
   }
 }
 
-void MismatchedIteratorChecker::reportBug(const StringRef &Message,
-  const SVal &Val1,
-  const SVal &Val2,
-  CheckerContext &C,
+void MismatchedIteratorChecker::reportBug(StringRef Message, const SVal &Val1,
+  const SVal &Val2, CheckerContext &C,
   ExplodedNode *ErrNode) const {
   auto R = std::make_unique(MismatchedBugType, Message,
 ErrNode);
@@ -283,8 +279,8 @@ void MismatchedIteratorChecker::reportBug(const StringRef 
&Message,
   C.emitReport(std::move(R));
 }
 
-void MismatchedIteratorChecker::reportBug(const StringRef &Message,
-  const SVal &Val, const MemRegion 
*Reg,
+void MismatchedIteratorChecker::reportBug(StringRef Message, const SVal &Val,
+  const MemRegion *Reg,
   CheckerContext &C,
   ExplodedNode *ErrNode) const {
   auto R = std::make_unique(MismatchedBugType, Message,

>From c0a3df172d1b1ba1d6330e336e7c38ba32370204 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Mon, 1 Jan 2024 19:00:13 +0100
Subject: [PATCH 2/2] [analyzer][NFC] Take SVal and NonLoc by value

---
 .../clang/StaticAnalyzer/Core/Checker.h   | 14 ++
 .../StaticAnalyzer/Core/CheckerManager.h  | 11 ++---
 .../Checkers/CallAndMessageChecker.cpp|  9 ++--
 .../Checkers/InvalidatedIteratorChecker.cpp   |  5 +-
 .../lib/StaticAnalyzer/Checkers/Iterator.cpp  | 14 +++---
 clang/lib/StaticAnalyzer/Checkers/Iterator.h  | 15 +++---
 .../Checkers/IteratorModeling.cpp | 49 +--
 .../Checkers/IteratorRangeChecker.cpp |  4 +-
 .../Checkers/MismatchedIteratorChecker.cpp| 25 +-
 .../Checkers/TaggedUnionM

[clang] [analyzer][NFC] Take small objects by value (PR #76688)

2024-01-01 Thread via cfe-commits

llvmbot wrote:




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

Author: Balazs Benics (steakhal)


Changes



---

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


14 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/Checker.h (+5-9) 
- (modified) clang/include/clang/StaticAnalyzer/Core/CheckerManager.h (+4-7) 
- (modified) clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp (+4-5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp 
(+3-2) 
- (modified) clang/lib/StaticAnalyzer/Checkers/Iterator.cpp (+6-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/Iterator.h (+6-9) 
- (modified) clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp (+23-26) 
- (modified) clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp (+4-4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp 
(+12-19) 
- (modified) clang/lib/StaticAnalyzer/Checkers/TaggedUnionModeling.h (+1-1) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
(+1-1) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/Environment.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index 8a46282a595eae..2ec54a837c42c9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -193,9 +193,8 @@ class PostCall {
 
 class Location {
   template 
-  static void _checkLocation(void *checker,
- const SVal &location, bool isLoad, const Stmt *S,
- CheckerContext &C) {
+  static void _checkLocation(void *checker, SVal location, bool isLoad,
+ const Stmt *S, CheckerContext &C) {
 ((const CHECKER *)checker)->checkLocation(location, isLoad, S, C);
   }
 
@@ -209,8 +208,7 @@ class Location {
 
 class Bind {
   template 
-  static void _checkBind(void *checker,
- const SVal &location, const SVal &val, const Stmt *S,
+  static void _checkBind(void *checker, SVal location, SVal val, const Stmt *S,
  CheckerContext &C) {
 ((const CHECKER *)checker)->checkBind(location, val, S, C);
   }
@@ -456,10 +454,8 @@ namespace eval {
 
 class Assume {
   template 
-  static ProgramStateRef _evalAssume(void *checker,
- ProgramStateRef state,
- const SVal &cond,
- bool assumption) {
+  static ProgramStateRef _evalAssume(void *checker, ProgramStateRef state,
+ SVal cond, bool assumption) {
 return ((const CHECKER *)checker)->evalAssume(state, cond, assumption);
   }
 
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 39583c443eda54..a45ba1bc573e1e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -488,13 +488,11 @@ class CheckerManager {
   using CheckCallFunc =
   CheckerFn;
 
-  using CheckLocationFunc =
-  CheckerFn;
+  using CheckLocationFunc = CheckerFn;
 
   using CheckBindFunc =
-  CheckerFn;
+  CheckerFn;
 
   using CheckEndAnalysisFunc =
   CheckerFn;
@@ -530,8 +528,7 @@ class CheckerManager {
  RegionAndSymbolInvalidationTraits *ITraits)>;
 
   using EvalAssumeFunc =
-  CheckerFn;
+  CheckerFn;
 
   using EvalCallFunc = CheckerFn;
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index ea74256935ca87..f2e1f69c32cfdc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -125,9 +125,8 @@ class CallAndMessageChecker
 if (!BT)
   BT.reset(new BugType(OriginalName, desc));
   }
-  bool uninitRefOrPointer(CheckerContext &C, const SVal &V,
-  SourceRange ArgRange, const Expr *ArgEx,
-  std::unique_ptr &BT,
+  bool uninitRefOrPointer(CheckerContext &C, SVal V, SourceRange ArgRange,
+  const Expr *ArgEx, std::unique_ptr &BT,
   const ParmVarDecl *ParamDecl, const char *BD,
   int ArgumentNumber) const;
 };
@@ -185,7 +184,7 @@ static void describeUninitializedArgumentInCall(const 
CallEvent &Call,
 }
 
 bool CallAndMessageChecker::uninitRefOrPointer(
-CheckerContext &C, const SVal &V, SourceRange ArgRange, const Expr *ArgEx,
+CheckerContext &C, SVal 

[lld] [llvm] [clang] [mlir] [libcxx] [flang] [analyzer][NFC] Cleanup BugType lazy-init patterns (PR #76655)

2024-01-01 Thread Balazs Benics via cfe-commits


@@ -31,14 +31,14 @@ class InvalidatedIteratorChecker
check::PreStmt,
check::PreStmt> {
 
-  std::unique_ptr InvalidatedBugType;
+  const BugType InvalidatedBugType{this, "Iterator invalidated",
+   "Misuse of STL APIs"};
 
   void verifyAccess(CheckerContext &C, const SVal &Val) const;
-  void reportBug(const StringRef &Message, const SVal &Val,
- CheckerContext &C, ExplodedNode *ErrNode) const;
-public:
-  InvalidatedIteratorChecker();
+  void reportBug(const StringRef &Message, const SVal &Val, CheckerContext &C,

steakhal wrote:

Followup PR for the analyzer-wide refactor: #76688

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


[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)

2024-01-01 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/76671

>From 0c586914ac977920140472d172ee357dea43f2c5 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 1 Jan 2024 18:48:27 +0800
Subject: [PATCH 1/2] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp'

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  6 ++--
 .../test/Analysis/errno-stdlibraryfunctions.c | 29 +++
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4ca49b9c0546d9..6f249b6b880283 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2511,10 +2511,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *mkdtemp(char *template);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
 // FIXME: Improve for errno modeling.
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index dafda764af9f38..de31de8cfea39b 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -7,12 +7,9 @@
 // RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
 
 #include "Inputs/errno_var.h"
+#include "Inputs/std-c-library-functions-POSIX.h"
 
-typedef typeof(sizeof(int)) size_t;
-typedef __typeof(sizeof(int)) off_t;
-typedef size_t ssize_t;
-ssize_t send(int sockfd, const void *buf, size_t len, int flags);
-off_t lseek(int fildes, off_t offset, int whence);
+#define NULL ((void *) 0)
 
 void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
@@ -54,3 +51,25 @@ int errno_lseek(int fildes, off_t offset) {
   }
   return 0;
 }
+
+void errno_mkstemp(char *template) {
+  int FD = mkstemp(template);
+  if (FD >= 0) {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+close(FD);
+  } else {
+clang_analyzer_eval(FD == -1);   // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  }
+}
+
+void errno_mkdtemp(char *template) {
+  char *Dir = mkdtemp(template);
+  if (Dir == NULL) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

>From c24e09d2108ebe4da92e100aa7f8d3a53ef8f326 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Mon, 1 Jan 2024 19:12:57 +0100
Subject: [PATCH 2/2] Add to the release notes

---
 clang/docs/ReleaseNotes.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..ffe482f16e2fbe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1127,11 +1127,12 @@ Improvements
 
 
 - Improved the ``unix.StdCLibraryFunctions`` checker by modeling more
-  functions like ``send``, ``recv``, ``readlink``, ``fflush`` and
-  ``errno`` behavior.
+  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp``
+  and ``errno`` behavior.
   (`52ac71f92d38 
`_,
   `#71373 `_,
   `#76557 `_,
+  `#76671 `_,
   `#71392 `_)
 
 - Fixed a false negative for when accessing a nonnull property (ObjC).

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


[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)

2024-01-01 Thread Balazs Benics via cfe-commits

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

LGTM

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


[clang] [analyzer][NFC] Take small objects by value (PR #76688)

2024-01-01 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM! Thanks!

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2024-01-01 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@cor3ntin 
Could you help me in closing this?

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


[lldb] [llvm] [openmp] [libc] [libcxx] [clang-tools-extra] [mlir] [flang] [clang] [compiler-rt] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/74994

>From 6e26ca239c49e1b7d9ab72217db7339e92df163f Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sun, 10 Dec 2023 14:16:02 +0200
Subject: [PATCH 01/18] [libc++][span] P2821R5: span.at()

---
 libcxx/include/span   |  30 +++
 .../views/views.span/span.elem/at.pass.cpp| 246 ++
 .../views.span/span.elem/op_idx.pass.cpp  |   1 -
 3 files changed, 276 insertions(+), 1 deletion(-)
 create mode 100644 
libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp

diff --git a/libcxx/include/span b/libcxx/include/span
index 69b0a2875e26cc..b015d7cf1c15b6 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -92,6 +92,7 @@ public:
 
 // [span.elem], span element access
 constexpr reference operator[](size_type idx) const;
+constexpr reference at(size_type idx) const; // since C++26
 constexpr reference front() const;
 constexpr reference back() const;
 constexpr pointer data() const noexcept;
@@ -146,6 +147,9 @@ template
 #include <__utility/forward.h>
 #include // for array
 #include   // for byte
+#if _LIBCPP_STD_VER >= 26
+#  include 
+#endif
 #include 
 
 // standard-mandated includes
@@ -343,6 +347,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -383,6 +396,10 @@ public:
 
 private:
 pointer__data_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 
@@ -510,6 +527,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -552,6 +578,10 @@ public:
 private:
 pointer   __data_;
 size_type __size_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 template 
diff --git a/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp 
b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
new file mode 100644
index 00..2a9ce2baeec1a5
--- /dev/null
+++ b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
@@ -0,0 +1,246 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+// template 
+// constexpr bool testConstexprSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// return r1 == r2;
+// }
+
+// template 
+// void testRuntimeSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// assert(r1 == r2);
+// }
+
+// struct A{};
+// constexpr int iArr1[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9};
+//   int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+
+// int main(int, char**)
+// {
+// static_assert(testConstexprSpan(std::span(iArr1, 1), 0), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 1), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 2), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 2), "");
+// static_assert(t

[lldb] [llvm] [openmp] [libc] [libcxx] [clang-tools-extra] [mlir] [flang] [clang] [compiler-rt] [libc++][span] P2821R5: `span.at()` (PR #74994)

2024-01-01 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,136 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr void testSpanAt(auto span, int idx, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = 
span.at(idx);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(span).at(idx);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {

H-G-Hristov wrote:

Sorry, I missed your comment!

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


[clang] 7619050 - [analyzer][NFC] Take StringRef by value

2024-01-01 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2024-01-01T22:00:32+01:00
New Revision: 7619050cd7c3715f34c1d13ea048c092299037bb

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

LOG: [analyzer][NFC] Take StringRef by value

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
index f966ea63da2181..f9263f439b1e3d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -43,7 +43,7 @@ class IteratorRangeChecker
   void verifyAdvance(CheckerContext &C, SVal LHS, SVal RHS) const;
   void verifyPrev(CheckerContext &C, SVal LHS, SVal RHS) const;
   void verifyNext(CheckerContext &C, SVal LHS, SVal RHS) const;
-  void reportBug(const StringRef &Message, SVal Val, CheckerContext &C,
+  void reportBug(StringRef Message, SVal Val, CheckerContext &C,
  ExplodedNode *ErrNode) const;
 
 public:
@@ -269,7 +269,7 @@ void IteratorRangeChecker::verifyNext(CheckerContext &C, 
SVal LHS,
   verifyRandomIncrOrDecr(C, OO_Plus, LHS, RHS);
 }
 
-void IteratorRangeChecker::reportBug(const StringRef &Message, SVal Val,
+void IteratorRangeChecker::reportBug(StringRef Message, SVal Val,
  CheckerContext &C,
  ExplodedNode *ErrNode) const {
   auto R = std::make_unique(OutOfRangeBugType, Message,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
index 38f80ba5e1ff39..8116105a50eb08 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
@@ -38,12 +38,10 @@ class MismatchedIteratorChecker
const MemRegion *Cont) const;
   void verifyMatch(CheckerContext &C, const SVal &Iter1,
const SVal &Iter2) const;
-  void reportBug(const StringRef &Message, const SVal &Val1,
- const SVal &Val2, CheckerContext &C,
- ExplodedNode *ErrNode) const;
-  void reportBug(const StringRef &Message, const SVal &Val,
- const MemRegion *Reg, CheckerContext &C,
- ExplodedNode *ErrNode) const;
+  void reportBug(StringRef Message, const SVal &Val1, const SVal &Val2,
+ CheckerContext &C, ExplodedNode *ErrNode) const;
+  void reportBug(StringRef Message, const SVal &Val, const MemRegion *Reg,
+ CheckerContext &C, ExplodedNode *ErrNode) const;
 
 public:
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
@@ -271,10 +269,8 @@ void MismatchedIteratorChecker::verifyMatch(CheckerContext 
&C,
   }
 }
 
-void MismatchedIteratorChecker::reportBug(const StringRef &Message,
-  const SVal &Val1,
-  const SVal &Val2,
-  CheckerContext &C,
+void MismatchedIteratorChecker::reportBug(StringRef Message, const SVal &Val1,
+  const SVal &Val2, CheckerContext &C,
   ExplodedNode *ErrNode) const {
   auto R = std::make_unique(MismatchedBugType, Message,
 ErrNode);
@@ -283,8 +279,8 @@ void MismatchedIteratorChecker::reportBug(const StringRef 
&Message,
   C.emitReport(std::move(R));
 }
 
-void MismatchedIteratorChecker::reportBug(const StringRef &Message,
-  const SVal &Val, const MemRegion 
*Reg,
+void MismatchedIteratorChecker::reportBug(StringRef Message, const SVal &Val,
+  const MemRegion *Reg,
   CheckerContext &C,
   ExplodedNode *ErrNode) const {
   auto R = std::make_unique(MismatchedBugType, Message,



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


[clang] 8ee3dfd - [analyzer][NFC] Take SVal and NonLoc by value

2024-01-01 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2024-01-01T22:00:32+01:00
New Revision: 8ee3dfd74653e30f48dd9f49ba24f43547e6a549

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

LOG: [analyzer][NFC] Take SVal and NonLoc by value

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/Checker.h
clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
clang/lib/StaticAnalyzer/Checkers/Iterator.h
clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/TaggedUnionModeling.h
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h

clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
clang/lib/StaticAnalyzer/Core/Environment.cpp
clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index 8a46282a595eae..2ec54a837c42c9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -193,9 +193,8 @@ class PostCall {
 
 class Location {
   template 
-  static void _checkLocation(void *checker,
- const SVal &location, bool isLoad, const Stmt *S,
- CheckerContext &C) {
+  static void _checkLocation(void *checker, SVal location, bool isLoad,
+ const Stmt *S, CheckerContext &C) {
 ((const CHECKER *)checker)->checkLocation(location, isLoad, S, C);
   }
 
@@ -209,8 +208,7 @@ class Location {
 
 class Bind {
   template 
-  static void _checkBind(void *checker,
- const SVal &location, const SVal &val, const Stmt *S,
+  static void _checkBind(void *checker, SVal location, SVal val, const Stmt *S,
  CheckerContext &C) {
 ((const CHECKER *)checker)->checkBind(location, val, S, C);
   }
@@ -456,10 +454,8 @@ namespace eval {
 
 class Assume {
   template 
-  static ProgramStateRef _evalAssume(void *checker,
- ProgramStateRef state,
- const SVal &cond,
- bool assumption) {
+  static ProgramStateRef _evalAssume(void *checker, ProgramStateRef state,
+ SVal cond, bool assumption) {
 return ((const CHECKER *)checker)->evalAssume(state, cond, assumption);
   }
 

diff  --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 39583c443eda54..a45ba1bc573e1e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -488,13 +488,11 @@ class CheckerManager {
   using CheckCallFunc =
   CheckerFn;
 
-  using CheckLocationFunc =
-  CheckerFn;
+  using CheckLocationFunc = CheckerFn;
 
   using CheckBindFunc =
-  CheckerFn;
+  CheckerFn;
 
   using CheckEndAnalysisFunc =
   CheckerFn;
@@ -530,8 +528,7 @@ class CheckerManager {
  RegionAndSymbolInvalidationTraits *ITraits)>;
 
   using EvalAssumeFunc =
-  CheckerFn;
+  CheckerFn;
 
   using EvalCallFunc = CheckerFn;
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index ea74256935ca87..f2e1f69c32cfdc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -125,9 +125,8 @@ class CallAndMessageChecker
 if (!BT)
   BT.reset(new BugType(OriginalName, desc));
   }
-  bool uninitRefOrPointer(CheckerContext &C, const SVal &V,
-  SourceRange ArgRange, const Expr *ArgEx,
-  std::unique_ptr &BT,
+  bool uninitRefOrPointer(CheckerContext &C, SVal V, SourceRange ArgRange,
+  const Expr *ArgEx, std::unique_ptr &BT,
   const ParmVarDecl *ParamDecl, const char *BD,
   int ArgumentNumber) const;
 };
@@ -185,7 +184,7 @@ static void describeUninitializedArgumentInCall(const 
CallEvent &Call,
 }
 
 bool CallAndMessageChecker::uninitRefOrPointer(
-CheckerContext &C, const SVal &V, SourceRange ArgRange, const Expr *ArgEx,
+CheckerContext &C, SVal V, SourceRange ArgRange, const Expr *Arg

[clang] [analyzer][NFC] Take small objects by value (PR #76688)

2024-01-01 Thread Balazs Benics via cfe-commits

steakhal wrote:

Pushed as 7619050cd7c3715f34c1d13ea048c092299037bb and 
8ee3dfd74653e30f48dd9f49ba24f43547e6a549 respectively.

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


[clang] [analyzer][NFC] Take small objects by value (PR #76688)

2024-01-01 Thread Balazs Benics via cfe-commits

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


[clang] [llvm] [lld] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2024-01-01 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

Can you please fix or revert 
https://lab.llvm.org/buildbot/#/builders/74/builds/24592 ?

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


[llvm] [clang] [lld] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2024-01-01 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

```
This patch deduces noundef attributes for return values.
IIUC, a function returns noundef values iff all of its return values are 
guaranteed not to be undef or poison.
```

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


[llvm] [clang] [lld] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2024-01-01 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

Another problem is that there was assumption that definition and declaration 
will be consistent, for msan is a part of ABI.
Clang will generate them consistently for all modules, with declaration and 
definition of the function.

Is possible that after this patch some definitions will get noundef, but 
declarations in other modules will still have none? If that is so, it breaks 
msan.

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


[llvm] [clang] [lld] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2024-01-01 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> Can you please fix or revert 
> https://lab.llvm.org/buildbot/#/builders/74/builds/24592 ?

Thank you for reporting this! I will check the error log.


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


[llvm] [clang] [lld] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2024-01-01 Thread Nikita Popov via cfe-commits

nikic wrote:

Yeah, we should skip this inference for functions with the sanitize_memory 
attribute.

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


  1   2   >