[compiler-rt] [llvm] [libc] [clang] [clang-tools-extra] [flang] [libcxx] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2023-12-31 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

> Thanks for working on this.

Thank you for reviewing!

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


[clang] [clang] Add `clang::behaves_like_std(...)` attribute (PR #76596)

2023-12-31 Thread via cfe-commits

cor3ntin wrote:

I struggle to understand the motivation here: If you are not using a standard 
library implementation at all and instead act as your own standard library 
vendor, just providing a declaration of move / forward should be enough.

The concern about ABI tags only come up if the STL is indeed included, and you 
seem to say it never is. Can you explain a bit more why you are concerned about 
how things are defined in libc++?

@philnik777 Do `std::move`/ `std::forward` etc actually need an abi tag? Maybe 
we should simply not set a tag given that clang / gcc replace call to these 
functions.

I prefer this approach over `msvc::intrinsic` because at least it gives control 
over how the call is replaced.
Ie, I think the semantics you'd want is really a `substitute_with_builtin` 
(presumably just after lookup).  `intrinsic`s a very generic name with a very 
narrow set of use cases (some casts).

More general observations on the "using c++ without the STL thing":
I don't think this is a major consideration of the language/standard committee 
going forward.
As you noted, there exist a lot of type traits/functions which are or should be 
backed by compiler magic.
And we are actually extending the set of freestanding function dramatically. 
Reflection will also have a dependency on the STL

That being said, I understand the pain. 
Modules should ease that pain - I don't have a good visibility on that but my 
understanding is that some progress is being made. In the meantime, I wonder if 
there is room for a lighter utility header, one without pair/rel_ops, maybe 
that would help.

I think we could also extend the set of std functions replaced in the front end 
if we can show it would have measurable compile times improvements (ie 
to_integer, as_const, to_underlying, etc).


PS: I appreciate that this patch comes with complete documentation :)


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


[flang] [libcxx] [lldb] [clang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Hristo Hristov via cfe-commits


@@ -26,7 +26,7 @@ template 
 void test_call_operator_forwarding() {
   using Fn = ForwardingCallObject;
   Fn obj{};
-  const Fn &cobj = obj;

H-G-Hristov wrote:

Restored original file and name. But now the tests are not sorted.

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


[flang] [libcxx] [lldb] [clang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Hristo Hristov via cfe-commits


@@ -17,27 +17,28 @@
 #include "test_macros.h"
 
 struct Incomplete;
-template struct Holder { T t; };

H-G-Hristov wrote:

Same as above.

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


[flang] [libcxx] [lldb] [clang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Hristo Hristov via cfe-commits

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


[flang] [libcxx] [lldb] [clang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,268 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class variant;
+
+// template
+//   constexpr decltype(auto) visit(this Self&&, Visitor&&); // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "variant_test_helpers.h"
+
+void test_call_operator_forwarding() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const Fn& cobj = obj;
+
+  { // test call operator forwarding - no variant
+// non-member
+{
+  std::visit(obj);
+  assert(Fn::check_call<>(CT_NonConst | CT_LValue));
+  std::visit(cobj);
+  assert(Fn::check_call<>(CT_Const | CT_LValue));
+  std::visit(std::move(obj));
+  assert(Fn::check_call<>(CT_NonConst | CT_RValue));
+  std::visit(std::move(cobj));
+  assert(Fn::check_call<>(CT_Const | CT_RValue));
+}
+  }
+  { // test call operator forwarding - single variant, single arg
+using V = std::variant;
+V v(42);
+
+v.visit(obj);
+assert(Fn::check_call(CT_NonConst | CT_LValue));
+v.visit(cobj);
+assert(Fn::check_call(CT_Const | CT_LValue));
+v.visit(std::move(obj));
+assert(Fn::check_call(CT_NonConst | CT_RValue));
+v.visit(std::move(cobj));
+assert(Fn::check_call(CT_Const | CT_RValue));
+  }
+  { // test call operator forwarding - single variant, multi arg
+using V = std::variant;
+V v(42L);
+
+v.visit(obj);
+assert(Fn::check_call(CT_NonConst | CT_LValue));
+v.visit(cobj);
+assert(Fn::check_call(CT_Const | CT_LValue));
+v.visit(std::move(obj));
+assert(Fn::check_call(CT_NonConst | CT_RValue));
+v.visit(std::move(cobj));
+assert(Fn::check_call(CT_Const | CT_RValue));
+  }
+}
+
+// Applies to non-member `std::visit` only.
+void test_argument_forwarding() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const auto val = CT_LValue | CT_NonConst;
+
+  { // single argument - value type
+using V = std::variant;
+V v(42);
+const V& cv = v;
+
+v.visit(obj);
+assert(Fn::check_call(val));
+cv.visit(obj);
+assert(Fn::check_call(val));
+std::move(v).visit(obj);
+assert(Fn::check_call(val));
+std::move(cv).visit(obj);
+assert(Fn::check_call(val));
+  }
+#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
+  { // single argument - lvalue reference
+using V = std::variant;
+int x   = 42;
+V v(x);
+const V& cv = v;
+
+v.visit(obj);
+assert(Fn::check_call(val));
+cv.visit(obj);
+assert(Fn::check_call(val));
+std::move(v).visit(obj);
+assert(Fn::check_call(val));
+std::move(cv).visit(obj);
+assert(Fn::check_call(val));
+assert(false);
+  }
+  { // single argument - rvalue reference
+using V = std::variant;
+int x   = 42;
+V v(std::move(x));
+const V& cv = v;
+
+v.visit(obj);
+assert(Fn::check_call(val));
+cvstd::visit(obj);
+assert(Fn::check_call(val));
+std::move(v).visit(obj);
+assert(Fn::check_call(val));
+std::move(cv).visit(obj);
+assert(Fn::check_call(val));
+  }
+#endif
+}
+
+void test_return_type() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const Fn& cobj = obj;
+
+  { // test call operator forwarding - single variant, single arg
+using V = std::variant;
+V v(42);
+
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+  }
+  { // test call operator forwarding - single variant, multi arg
+using V = std::variant;
+V v(42L);
+
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+  }
+}
+
+void test_constexpr() {
+  constexpr ReturnFirst obj{};
+
+  {
+using V = std::variant;
+constexpr V v(42);
+
+static_assert(v.visit(obj) == 42);
+  }
+  {
+using V = std::variant;
+constexpr V v(42L);
+
+static_assert(v.visit(obj) == 42);
+  }
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  ReturnArity obj{};
+
+  auto test = [&](auto&& v) {
+try {
+  v.visit(obj);
+} catch (const std::bad_variant_access&) {
+  return true;
+} catch (...) {
+}
+return false;
+  };
+
+  {
+using V = std::variant;
+V v;
+makeEmpty(v);
+
+assert(test(v));
+  }
+#endif
+}
+
+// See https://llvm.org/PR31916
+void test_caller_accepts_nonconst() {
+  struct A {};
+  struct Visitor {
+void operator()(A&) {}
+  };
+  std::variant v;
+
+  v.visit(Visitor{});
+}
+
+struct MyVariant : std::variant {};
+
+n

[clang-tools-extra] [clang] In compilation databases, add support for relative directories (PR #69856)

2023-12-31 Thread via cfe-commits

https://github.com/Overhatted updated 
https://github.com/llvm/llvm-project/pull/69856

>From 071f8df3f82798255bcc0e2787fd7167b607d59f Mon Sep 17 00:00:00 2001
From: Overhatted <15021741+overhat...@users.noreply.github.com>
Date: Fri, 15 Dec 2023 15:53:56 +
Subject: [PATCH] In compilation databases, add support for relative
 directories

---
 .../clangd/GlobalCompilationDatabase.cpp  |  2 +-
 clang/docs/JSONCompilationDatabase.rst|  4 +++-
 .../clang/Tooling/JSONCompilationDatabase.h   | 10 
 clang/lib/Tooling/JSONCompilationDatabase.cpp | 24 ++-
 .../Tooling/CompilationDatabaseTest.cpp   | 10 
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 5bec7966a9c3a9..de017b78241ad3 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -245,7 +245,7 @@ 
DirectoryBasedGlobalCompilationDatabase::DirectoryCache::CachedFile::load(
 static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string &Error) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
-  Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
+  Path, Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
 // FS used for expanding response files.
 // FIXME: ExpandResponseFilesDatabase appears not to provide the usual
 // thread-safety guarantees, as the access to FS is not locked!
diff --git a/clang/docs/JSONCompilationDatabase.rst 
b/clang/docs/JSONCompilationDatabase.rst
index f5432278bd4d4e..41219a554dfdea 100644
--- a/clang/docs/JSONCompilationDatabase.rst
+++ b/clang/docs/JSONCompilationDatabase.rst
@@ -81,7 +81,9 @@ The contracts for each field in the command object are:
 
 -  **directory:** The working directory of the compilation. All paths
specified in the **command** or **file** fields must be either
-   absolute or relative to this directory.
+   absolute or relative to this directory. This field itself can be a
+   relative path in which case it is evaluated relative to the folder
+   containing the compilation database file.
 -  **file:** The main translation unit source processed by this
compilation step. This is used by tools as the key into the
compilation database. There can be multiple command objects for the
diff --git a/clang/include/clang/Tooling/JSONCompilationDatabase.h 
b/clang/include/clang/Tooling/JSONCompilationDatabase.h
index 96582457c63d58..3ec0e36c196d2e 100644
--- a/clang/include/clang/Tooling/JSONCompilationDatabase.h
+++ b/clang/include/clang/Tooling/JSONCompilationDatabase.h
@@ -72,8 +72,8 @@ class JSONCompilationDatabase : public CompilationDatabase {
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage,
- JSONCommandLineSyntax Syntax);
+  loadFromBuffer(StringRef FilePath, StringRef DatabaseString,
+ std::string &ErrorMessage, JSONCommandLineSyntax Syntax);
 
   /// Returns all compile commands in which the specified file was
   /// compiled.
@@ -94,9 +94,10 @@ class JSONCompilationDatabase : public CompilationDatabase {
 
 private:
   /// Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCompilationDatabase(SmallString<128> FolderPath,
+  std::unique_ptr Database,
   JSONCommandLineSyntax Syntax)
-  : Database(std::move(Database)), Syntax(Syntax),
+  : FolderPath(FolderPath), Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// Parses the database file and creates the index.
@@ -130,6 +131,7 @@ class JSONCompilationDatabase : public CompilationDatabase {
 
   FileMatchTrie MatchTrie;
 
+  SmallString<128> FolderPath;
   std::unique_ptr Database;
   JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index a77686996879f1..c8c7f46e1fb3e6 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -202,21 +202,26 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
 ErrorMessage = "Error while opening JSON database: " + Result.message();
 return nullptr;
   }
-  std::unique_ptr Database(
-  new JSONCompilationDatabase(std::move(*DatabaseBuffer), Syntax));
+  SmallString<128> FolderPath = FilePath;
+  llvm::sys::path::remove_filename(FolderPath);
+  std::unique_ptr Database(new 
JSONCompilationDatabase(
+  FolderPath, std::move(*DatabaseBuffer), Syntax));
   if (!Database->parse(ErrorMessage))
 return nullptr;
   return Database;
 }
 
 std::unique

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-12-31 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang][Sema] Warn on self move for inlined static cast (PR #76646)

2023-12-31 Thread Timm Baeder via cfe-commits


@@ -18843,17 +18843,26 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, 
const Expr *RHSExpr,
   LHSExpr = LHSExpr->IgnoreParenImpCasts();
   RHSExpr = RHSExpr->IgnoreParenImpCasts();
 
-  // Check for a call expression
+  // Check for a call expression or static_cast expression
   const CallExpr *CE = dyn_cast(RHSExpr);
-  if (!CE || CE->getNumArgs() != 1)
+  const CXXStaticCastExpr *CXXSCE = dyn_cast(RHSExpr);

tbaederr wrote:

```suggestion
  const auto *CXXSCE = dyn_cast(RHSExpr);
```

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


[compiler-rt] [llvm] [lldb] [clang-tools-extra] [clang] [libc] [flang] [libcxx] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Hristo Hristov via cfe-commits

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


[compiler-rt] [llvm] [lldb] [clang-tools-extra] [clang] [libc] [flang] [libcxx] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

> Thanks for working on this!

Thank you for reviewing!

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


[clang] [clang] Add `clang::behaves_like_std(...)` attribute (PR #76596)

2023-12-31 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> @philnik777 Do `std::move`/ `std::forward` etc actually need an abi tag? 
> Maybe we should simply not set a tag given that clang / gcc replace call to 
> these functions.

If that were always the case we could simply provide a declaration without ever 
defining the function, but clang and gcc don't always replace it. e.g. if you 
take the address (which both compilers unfortunately still allow). While it's 
unlikely for `std::move` specifically, it's always possible that the 
implementation changes and we have ABI breaks in the end, and having an ABI 
break vs. not allowing forward declarations of standard library functions seems 
like a no-brainer to me.

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)

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

ldionne wrote:

I think this can be merged. I would have liked to have @jlebar 's input on 
interactions with Cuda, but I think this is probably good enough.

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)

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

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


[clang] 61999b1 - [clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)

2023-12-31 Thread via cfe-commits

Author: Louis Dionne
Date: 2023-12-31T05:15:49-05:00
New Revision: 61999b18c407b9f5c07577e63057d41c65240e61

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

LOG: [clang][Darwin] Remove legacy framework search path logic in the frontend 
(#75841)

This removes a long standing piece of technical debt. Most other
platforms have moved all their header search path logic to the driver,
but Darwin still had some logic for setting framework search paths
present in the frontend. This patch moves that logic to the driver
alongside existing logic that already handles part of these search
paths.

This is intended to be a pure refactor without any functional change
visible to users, since the search paths before and after should be the
same, and in the same order. The change in the tests is necessary
because we would previously add the DriverKit framework search path in
the frontend regardless of whether we actually need to, which we now
handle correctly because the driver checks for ld64-605.1+.

Fixes #75638

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Lex/InitHeaderSearch.cpp
clang/test/Driver/driverkit-path.c

Removed: 
clang/test/Preprocessor/cuda-macos-includes.cu



diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 65846cace461e3..f76a42d2d8e7e3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -758,9 +758,14 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
   }
 
-  // Add non-standard, platform-specific search paths, e.g., for DriverKit:
-  //  -L/System/DriverKit/usr/lib
-  //  -F/System/DriverKit/System/Library/Framework
+  // Add framework include paths and library search paths.
+  // There are two flavors:
+  // 1. The "non-standard" paths, e.g. for DriverKit:
+  //  -L/System/DriverKit/usr/lib
+  //  -F/System/DriverKit/System/Library/Frameworks
+  // 2. The "standard" paths, e.g. for macOS and iOS:
+  //  -F/System/Library/Frameworks
+  //  -F/Library/Frameworks
   {
 bool NonStandardSearchPath = false;
 const auto &Triple = getToolChain().getTriple();
@@ -771,18 +776,22 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   (Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1);
 }
 
-if (NonStandardSearchPath) {
-  if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
-auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
-  SmallString<128> P(Sysroot->getValue());
-  AppendPlatformPrefix(P, Triple);
-  llvm::sys::path::append(P, SearchPath);
-  if (getToolChain().getVFS().exists(P)) {
-CmdArgs.push_back(Args.MakeArgString(Flag + P));
-  }
-};
+if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
+  auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
+SmallString<128> P(Sysroot->getValue());
+AppendPlatformPrefix(P, Triple);
+llvm::sys::path::append(P, SearchPath);
+if (getToolChain().getVFS().exists(P)) {
+  CmdArgs.push_back(Args.MakeArgString(Flag + P));
+}
+  };
+
+  if (NonStandardSearchPath) {
 AddSearchPath("-L", "/usr/lib");
 AddSearchPath("-F", "/System/Library/Frameworks");
+  } else if (!Triple.isDriverKit()) {
+AddSearchPath("-F", "/System/Library/Frameworks");
+AddSearchPath("-F", "/Library/Frameworks");
   }
 }
   }

diff  --git a/clang/lib/Lex/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
index 2218db15013d92..1350fa5f01a578 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -324,6 +324,9 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
 break;
   }
 
+  if (triple.isOSDarwin())
+return false;
+
   return true; // Everything else uses AddDefaultIncludePaths().
 }
 
@@ -338,21 +341,6 @@ void InitHeaderSearch::AddDefaultIncludePaths(
   if (!ShouldAddDefaultIncludePaths(triple))
 return;
 
-  // NOTE: some additional header search logic is handled in the driver for
-  // Darwin.
-  if (triple.isOSDarwin()) {
-if (HSOpts.UseStandardSystemIncludes) {
-  // Add the default framework include paths on Darwin.
-  if (triple.isDriverKit()) {
-AddPath("/System/DriverKit/System/Library/Frameworks", System, true);
-  } else {
-AddPath("/System/Library/Frameworks", System, true);
-AddPath("/Library/Frameworks", System, true);
-  }
-}
-return;
-  }
-
   if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
   HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
 if (HSOpts.UseLi

[clang] [Cygwin] Cygwin driver (PR #74933)

2023-12-31 Thread Brad Smith via cfe-commits
=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,
=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,
=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng
Message-ID:
In-Reply-To: 


brad0 wrote:

You probably need to rebase this.

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)

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

brad0 wrote:

Thank you for the effort.

https://github.com/llvm/llvm-project/pull/75841
___
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)

2023-12-31 Thread Balazs Benics via cfe-commits

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

Cleanup most of the lazy-init `BugType` legacy.
Some will be preserved, as those are slightly more complicated to refactor.

Notice, that the default category for `BugType` is `LogicError`. I omitted 
setting this explicitly where I could.

Please, actually have a look at the diff. I did this manually, and we rarely 
check the bug type descriptions and stuff in tests, so the testing might be 
shallow on this one.

>From 0362ae2c888edc749711209174f592c5c311db76 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sun, 31 Dec 2023 11:33:15 +0100
Subject: [PATCH] [analyzer][NFC] Cleanup BugType lazy-init patterns

Cleanup most of the lazy-init `BugType` legacy.
Some will be preserved, as those are slightly more complicated to refactor.

Notice, that the default category for `BugType` is `LogicError`.
I omitted setting this explicitly where I could.
---
 .../Core/BugReporter/CommonBugCategories.h|  1 +
 .../Checkers/ArrayBoundChecker.cpp|  7 +-
 .../Checkers/BasicObjCFoundationChecks.cpp|  2 +-
 .../Checkers/BoolAssignmentChecker.cpp|  7 +-
 .../Checkers/CXXDeleteChecker.cpp | 24 ++---
 .../Checkers/CastSizeChecker.cpp  |  6 +-
 .../StaticAnalyzer/Checkers/ChrootChecker.cpp |  6 +-
 .../Checkers/ConversionChecker.cpp|  7 +-
 .../Checkers/DivZeroChecker.cpp   | 16 ++--
 .../Checkers/DynamicTypeChecker.cpp   | 10 +--
 .../Checkers/EnumCastOutOfRangeChecker.cpp|  8 +-
 .../Checkers/ExprInspectionChecker.cpp|  8 +-
 .../Checkers/FixedAddressChecker.cpp  |  6 +-
 .../Checkers/LocalizationChecker.cpp  | 12 +--
 .../Checkers/MacOSKeychainAPIChecker.cpp  | 22 ++---
 .../Checkers/MacOSXAPIChecker.cpp | 10 +--
 .../Checkers/MmapWriteExecChecker.cpp | 16 ++--
 .../Checkers/NSAutoreleasePoolChecker.cpp |  9 +-
 .../Checkers/NonNullParamChecker.cpp  | 21 ++---
 .../Checkers/ObjCAtSyncChecker.cpp| 17 ++--
 .../Checkers/ObjCContainersChecker.cpp| 11 +--
 .../Checkers/ObjCSelfInitChecker.cpp  |  9 +-
 .../Checkers/PaddingChecker.cpp   |  9 +-
 .../Checkers/PointerArithChecker.cpp  | 12 +--
 .../Checkers/PointerSubChecker.cpp|  6 +-
 .../Checkers/ReturnPointerRangeChecker.cpp| 10 +--
 .../Checkers/ReturnUndefChecker.cpp   | 15 ++--
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  8 +-
 .../Checkers/TestAfterDivZeroChecker.cpp  | 10 +--
 .../Checkers/UndefBranchChecker.cpp   | 89 +--
 .../Checkers/UndefCapturedBlockVarChecker.cpp |  8 +-
 .../Checkers/UndefResultChecker.cpp   |  8 +-
 .../UndefinedArraySubscriptChecker.cpp|  7 +-
 .../Checkers/UndefinedAssignmentChecker.cpp   | 11 +--
 .../Checkers/UnixAPIChecker.cpp   | 32 +++
 .../Checkers/VLASizeChecker.cpp   | 20 ++---
 .../StaticAnalyzer/Checkers/VforkChecker.cpp  |  7 +-
 .../Core/CommonBugCategories.cpp  |  1 +
 .../NoStateChangeFuncVisitorTest.cpp  |  7 +-
 39 files changed, 171 insertions(+), 324 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
index 5d2c96e5bc9de3..45187433c069fd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
@@ -13,6 +13,7 @@
 namespace clang {
 namespace ento {
 namespace categories {
+extern const char *const AppleAPIMisuse;
 extern const char *const CoreFoundationObjectiveC;
 extern const char *const LogicError;
 extern const char *const MemoryRefCount;
diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
index ce126541265551..c990ad138f8905 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
@@ -25,7 +25,7 @@ using namespace ento;
 namespace {
 class ArrayBoundChecker :
 public Checker {
-  mutable std::unique_ptr BT;
+  const BugType BT{this, "Out-of-bound array access"};
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt* S,
@@ -65,16 +65,13 @@ void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, 
const Stmt* LoadS,
 if (!N)
   return;
 
-if (!BT)
-  BT.reset(new BugType(this, "Out-of-bound array access"));
-
 // FIXME: It would be nice to eventually make this diagnostic more clear,
 // e.g., by referencing the original declaration or by saying *why* this
 // reference is outside the range.
 
 // Generate a report for this bug.
 auto report = std::make_unique(
-*BT, "Access out-of-bound array element (buffer overflow)", N);
+BT, "Access out-of-bound array element (buffer overflow)",

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

2023-12-31 Thread via cfe-commits

llvmbot wrote:




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

Author: Balazs Benics (steakhal)


Changes

Cleanup most of the lazy-init `BugType` legacy.
Some will be preserved, as those are slightly more complicated to refactor.

Notice, that the default category for `BugType` is `LogicError`. I omitted 
setting this explicitly where I could.

Please, actually have a look at the diff. I did this manually, and we rarely 
check the bug type descriptions and stuff in tests, so the testing might be 
shallow on this one.

---

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


39 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h (+1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp (+2-5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
(+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp (+2-5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp (+7-17) 
- (modified) clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp (+2-4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp (+2-4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp (+2-5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp (+5-11) 
- (modified) clang/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp (+2-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp 
(+2-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp (+2-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp (+2-4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (+3-9) 
- (modified) clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp 
(+6-16) 
- (modified) clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp (+4-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp (+9-7) 
- (modified) clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp 
(+3-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp (+6-15) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp (+6-11) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp (+3-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp (+3-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp (+2-7) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp (+4-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp (+2-4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp 
(+4-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp (+5-10) 
- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+2-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp 
(+4-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp (+42-47) 
- (modified) clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp 
(+2-6) 
- (modified) clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp (+2-6) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp (+2-5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp 
(+3-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp (+11-21) 
- (modified) clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp (+6-14) 
- (modified) clang/lib/StaticAnalyzer/Checkers/VforkChecker.cpp (+2-5) 
- (modified) clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp (+1) 
- (modified) clang/unittests/StaticAnalyzer/NoStateChangeFuncVisitorTest.cpp 
(+2-5) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
index 5d2c96e5bc9de3..45187433c069fd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
@@ -13,6 +13,7 @@
 namespace clang {
 namespace ento {
 namespace categories {
+extern const char *const AppleAPIMisuse;
 extern const char *const CoreFoundationObjectiveC;
 extern const char *const LogicError;
 extern const char *const MemoryRefCount;
diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
index ce126541265551..c990ad138f8905 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
@@ -25,7 +25,7 @@ using namespace ento;
 namespace {
 class ArrayBoundChecker :
 public Checker {
-  mutable std::unique_ptr BT;
+  const BugType BT{this, "Out-of-bound array access"};
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt* S

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

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

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/76553

>From 30dcc33c4ea3ab50397a7adbe85fe977d4a400bd Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 29 Dec 2023 14:27:22 +0800
Subject: [PATCH 1/2] [FuncAttrs] Add pre-commit tests. NFC.

---
 llvm/test/Transforms/FunctionAttrs/noundef.ll | 145 ++
 1 file changed, 145 insertions(+)
 create mode 100644 llvm/test/Transforms/FunctionAttrs/noundef.ll

diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll 
b/llvm/test/Transforms/FunctionAttrs/noundef.ll
new file mode 100644
index 00..9eca495e111e8f
--- /dev/null
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt < %s -passes='function-attrs' -S | FileCheck %s
+
+define i32 @test_ret_constant() {
+; CHECK-LABEL: define i32 @test_ret_constant(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:ret i32 0
+;
+  ret i32 0
+}
+
+define i32 @test_ret_poison() {
+; CHECK-LABEL: define i32 @test_ret_poison(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 poison
+;
+  ret i32 poison
+}
+
+define i32 @test_ret_undef() {
+; CHECK-LABEL: define i32 @test_ret_undef(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 undef
+;
+  ret i32 undef
+}
+
+define i32 @test_ret_param(i32 %x) {
+; CHECK-LABEL: define i32 @test_ret_param(
+; CHECK-SAME: i32 returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 [[X]]
+;
+  ret i32 %x
+}
+
+define i32 @test_ret_noundef_param(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_noundef_param(
+; CHECK-SAME: i32 noundef returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 [[X]]
+;
+  ret i32 %x
+}
+
+define i32 @test_ret_noundef_expr(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_noundef_expr(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[Y]]
+;
+  %y = add i32 %x, 1
+  ret i32 %y
+}
+
+define i32 @test_ret_create_poison_expr(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_create_poison_expr(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[Y]]
+;
+  %y = add nsw i32 %x, 1
+  ret i32 %y
+}
+
+define i32 @test_ret_freezed(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_freezed(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:[[Z:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:ret i32 [[Z]]
+;
+  %y = add nsw i32 %x, 1
+  %z = freeze i32 %y
+  ret i32 %z
+}
+
+define i32 @test_ret_control_flow(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 0
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add i32 %x, 1
+  ret i32 %ret
+}
+
+define i32 @test_ret_control_flow_may_poison(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow_may_poison(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 0
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add nsw i32 %x, 1
+  ret i32 %ret
+}
+
+; TODO: use context-sensitive analysis
+define i32 @test_ret_control_flow_never_poison(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow_never_poison(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 2147483647
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 2147483647
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add nsw i32 %x, 1
+  ret i32 %ret
+}
+
+define i32 @test_noundef_prop() {
+; CHECK-LABEL: define i32 @test_noundef_prop(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:[[RET:%.*]] = call i32 @test_ret_constant()
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %ret = call i32 @test_ret_constant()
+  ret i32 %ret
+}

>From 46188dfe1a8069c94fc4628660889e070e6a82cb Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Da

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

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

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/76553

>From 30dcc33c4ea3ab50397a7adbe85fe977d4a400bd Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 29 Dec 2023 14:27:22 +0800
Subject: [PATCH 1/2] [FuncAttrs] Add pre-commit tests. NFC.

---
 llvm/test/Transforms/FunctionAttrs/noundef.ll | 145 ++
 1 file changed, 145 insertions(+)
 create mode 100644 llvm/test/Transforms/FunctionAttrs/noundef.ll

diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll 
b/llvm/test/Transforms/FunctionAttrs/noundef.ll
new file mode 100644
index 00..9eca495e111e8f
--- /dev/null
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt < %s -passes='function-attrs' -S | FileCheck %s
+
+define i32 @test_ret_constant() {
+; CHECK-LABEL: define i32 @test_ret_constant(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:ret i32 0
+;
+  ret i32 0
+}
+
+define i32 @test_ret_poison() {
+; CHECK-LABEL: define i32 @test_ret_poison(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 poison
+;
+  ret i32 poison
+}
+
+define i32 @test_ret_undef() {
+; CHECK-LABEL: define i32 @test_ret_undef(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 undef
+;
+  ret i32 undef
+}
+
+define i32 @test_ret_param(i32 %x) {
+; CHECK-LABEL: define i32 @test_ret_param(
+; CHECK-SAME: i32 returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 [[X]]
+;
+  ret i32 %x
+}
+
+define i32 @test_ret_noundef_param(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_noundef_param(
+; CHECK-SAME: i32 noundef returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 [[X]]
+;
+  ret i32 %x
+}
+
+define i32 @test_ret_noundef_expr(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_noundef_expr(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[Y]]
+;
+  %y = add i32 %x, 1
+  ret i32 %y
+}
+
+define i32 @test_ret_create_poison_expr(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_create_poison_expr(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[Y]]
+;
+  %y = add nsw i32 %x, 1
+  ret i32 %y
+}
+
+define i32 @test_ret_freezed(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_freezed(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:[[Z:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:ret i32 [[Z]]
+;
+  %y = add nsw i32 %x, 1
+  %z = freeze i32 %y
+  ret i32 %z
+}
+
+define i32 @test_ret_control_flow(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 0
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add i32 %x, 1
+  ret i32 %ret
+}
+
+define i32 @test_ret_control_flow_may_poison(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow_may_poison(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 0
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add nsw i32 %x, 1
+  ret i32 %ret
+}
+
+; TODO: use context-sensitive analysis
+define i32 @test_ret_control_flow_never_poison(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow_never_poison(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 2147483647
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 2147483647
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add nsw i32 %x, 1
+  ret i32 %ret
+}
+
+define i32 @test_noundef_prop() {
+; CHECK-LABEL: define i32 @test_noundef_prop(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:[[RET:%.*]] = call i32 @test_ret_constant()
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %ret = call i32 @test_ret_constant()
+  ret i32 %ret
+}

>From fe11127cd7e9ed4669243502eda5991504b9809a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Da

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

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

dtcxzyw wrote:

> There are lld test failures.

Done.

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)

2023-12-31 Thread Nikita Popov via cfe-commits

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

LGTM, assuming Linux CI passes now.

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


[compiler-rt] [clang-tools-extra] [flang] [libc] [lldb] [clang] [llvm] [libcxx] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Mark de Wever via cfe-commits


@@ -26,7 +26,7 @@ template 
 void test_call_operator_forwarding() {
   using Fn = ForwardingCallObject;
   Fn obj{};
-  const Fn &cobj = obj;

mordante wrote:

Thanks! We still need to reformat all our tests like we did with the headers. 
The main problem with mixing formatting and real changes that it often is hard 
for the reviewer to find the real changes in a file.

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


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

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

dtcxzyw wrote:

> Failed Tests (3):
  LLVM :: CodeGen/BPF/loop-exit-cond.ll
  LLVM :: CodeGen/NVPTX/nvvm-reflect-opaque.ll
  LLVM :: CodeGen/NVPTX/nvvm-reflect.ll

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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-31 Thread Timm Baeder via cfe-commits

tbaederr wrote:

The documentation build still fails fwiw.

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


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

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

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/76553

>From 30dcc33c4ea3ab50397a7adbe85fe977d4a400bd Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 29 Dec 2023 14:27:22 +0800
Subject: [PATCH 1/2] [FuncAttrs] Add pre-commit tests. NFC.

---
 llvm/test/Transforms/FunctionAttrs/noundef.ll | 145 ++
 1 file changed, 145 insertions(+)
 create mode 100644 llvm/test/Transforms/FunctionAttrs/noundef.ll

diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll 
b/llvm/test/Transforms/FunctionAttrs/noundef.ll
new file mode 100644
index 00..9eca495e111e8f
--- /dev/null
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt < %s -passes='function-attrs' -S | FileCheck %s
+
+define i32 @test_ret_constant() {
+; CHECK-LABEL: define i32 @test_ret_constant(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:ret i32 0
+;
+  ret i32 0
+}
+
+define i32 @test_ret_poison() {
+; CHECK-LABEL: define i32 @test_ret_poison(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 poison
+;
+  ret i32 poison
+}
+
+define i32 @test_ret_undef() {
+; CHECK-LABEL: define i32 @test_ret_undef(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 undef
+;
+  ret i32 undef
+}
+
+define i32 @test_ret_param(i32 %x) {
+; CHECK-LABEL: define i32 @test_ret_param(
+; CHECK-SAME: i32 returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 [[X]]
+;
+  ret i32 %x
+}
+
+define i32 @test_ret_noundef_param(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_noundef_param(
+; CHECK-SAME: i32 noundef returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:ret i32 [[X]]
+;
+  ret i32 %x
+}
+
+define i32 @test_ret_noundef_expr(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_noundef_expr(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[Y]]
+;
+  %y = add i32 %x, 1
+  ret i32 %y
+}
+
+define i32 @test_ret_create_poison_expr(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_create_poison_expr(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[Y]]
+;
+  %y = add nsw i32 %x, 1
+  ret i32 %y
+}
+
+define i32 @test_ret_freezed(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_freezed(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[Y:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:[[Z:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:ret i32 [[Z]]
+;
+  %y = add nsw i32 %x, 1
+  %z = freeze i32 %y
+  ret i32 %z
+}
+
+define i32 @test_ret_control_flow(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 0
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add i32 %x, 1
+  ret i32 %ret
+}
+
+define i32 @test_ret_control_flow_may_poison(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow_may_poison(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 0
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add nsw i32 %x, 1
+  ret i32 %ret
+}
+
+; TODO: use context-sensitive analysis
+define i32 @test_ret_control_flow_never_poison(i32 noundef %x) {
+; CHECK-LABEL: define i32 @test_ret_control_flow_never_poison(
+; CHECK-SAME: i32 noundef [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[X]], 2147483647
+; CHECK-NEXT:br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:ret i32 2
+; CHECK:   if.else:
+; CHECK-NEXT:[[RET:%.*]] = add nsw i32 [[X]], 1
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %cond = icmp eq i32 %x, 2147483647
+  br i1 %cond, label %if.then, label %if.else
+if.then:
+  ret i32 2
+if.else:
+  %ret = add nsw i32 %x, 1
+  ret i32 %ret
+}
+
+define i32 @test_noundef_prop() {
+; CHECK-LABEL: define i32 @test_noundef_prop(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT:[[RET:%.*]] = call i32 @test_ret_constant()
+; CHECK-NEXT:ret i32 [[RET]]
+;
+  %ret = call i32 @test_ret_constant()
+  ret i32 %ret
+}

>From c5e8738d4bfbf1e97e3f455fded90b791f223d74 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Da

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

2023-12-31 Thread Balazs Benics via cfe-commits

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

>From 0362ae2c888edc749711209174f592c5c311db76 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sun, 31 Dec 2023 11:33:15 +0100
Subject: [PATCH 1/2] [analyzer][NFC] Cleanup BugType lazy-init patterns

Cleanup most of the lazy-init `BugType` legacy.
Some will be preserved, as those are slightly more complicated to refactor.

Notice, that the default category for `BugType` is `LogicError`.
I omitted setting this explicitly where I could.
---
 .../Core/BugReporter/CommonBugCategories.h|  1 +
 .../Checkers/ArrayBoundChecker.cpp|  7 +-
 .../Checkers/BasicObjCFoundationChecks.cpp|  2 +-
 .../Checkers/BoolAssignmentChecker.cpp|  7 +-
 .../Checkers/CXXDeleteChecker.cpp | 24 ++---
 .../Checkers/CastSizeChecker.cpp  |  6 +-
 .../StaticAnalyzer/Checkers/ChrootChecker.cpp |  6 +-
 .../Checkers/ConversionChecker.cpp|  7 +-
 .../Checkers/DivZeroChecker.cpp   | 16 ++--
 .../Checkers/DynamicTypeChecker.cpp   | 10 +--
 .../Checkers/EnumCastOutOfRangeChecker.cpp|  8 +-
 .../Checkers/ExprInspectionChecker.cpp|  8 +-
 .../Checkers/FixedAddressChecker.cpp  |  6 +-
 .../Checkers/LocalizationChecker.cpp  | 12 +--
 .../Checkers/MacOSKeychainAPIChecker.cpp  | 22 ++---
 .../Checkers/MacOSXAPIChecker.cpp | 10 +--
 .../Checkers/MmapWriteExecChecker.cpp | 16 ++--
 .../Checkers/NSAutoreleasePoolChecker.cpp |  9 +-
 .../Checkers/NonNullParamChecker.cpp  | 21 ++---
 .../Checkers/ObjCAtSyncChecker.cpp| 17 ++--
 .../Checkers/ObjCContainersChecker.cpp| 11 +--
 .../Checkers/ObjCSelfInitChecker.cpp  |  9 +-
 .../Checkers/PaddingChecker.cpp   |  9 +-
 .../Checkers/PointerArithChecker.cpp  | 12 +--
 .../Checkers/PointerSubChecker.cpp|  6 +-
 .../Checkers/ReturnPointerRangeChecker.cpp| 10 +--
 .../Checkers/ReturnUndefChecker.cpp   | 15 ++--
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  8 +-
 .../Checkers/TestAfterDivZeroChecker.cpp  | 10 +--
 .../Checkers/UndefBranchChecker.cpp   | 89 +--
 .../Checkers/UndefCapturedBlockVarChecker.cpp |  8 +-
 .../Checkers/UndefResultChecker.cpp   |  8 +-
 .../UndefinedArraySubscriptChecker.cpp|  7 +-
 .../Checkers/UndefinedAssignmentChecker.cpp   | 11 +--
 .../Checkers/UnixAPIChecker.cpp   | 32 +++
 .../Checkers/VLASizeChecker.cpp   | 20 ++---
 .../StaticAnalyzer/Checkers/VforkChecker.cpp  |  7 +-
 .../Core/CommonBugCategories.cpp  |  1 +
 .../NoStateChangeFuncVisitorTest.cpp  |  7 +-
 39 files changed, 171 insertions(+), 324 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
index 5d2c96e5bc9de3..45187433c069fd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
@@ -13,6 +13,7 @@
 namespace clang {
 namespace ento {
 namespace categories {
+extern const char *const AppleAPIMisuse;
 extern const char *const CoreFoundationObjectiveC;
 extern const char *const LogicError;
 extern const char *const MemoryRefCount;
diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
index ce126541265551..c990ad138f8905 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
@@ -25,7 +25,7 @@ using namespace ento;
 namespace {
 class ArrayBoundChecker :
 public Checker {
-  mutable std::unique_ptr BT;
+  const BugType BT{this, "Out-of-bound array access"};
 
 public:
   void checkLocation(SVal l, bool isLoad, const Stmt* S,
@@ -65,16 +65,13 @@ void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, 
const Stmt* LoadS,
 if (!N)
   return;
 
-if (!BT)
-  BT.reset(new BugType(this, "Out-of-bound array access"));
-
 // FIXME: It would be nice to eventually make this diagnostic more clear,
 // e.g., by referencing the original declaration or by saying *why* this
 // reference is outside the range.
 
 // Generate a report for this bug.
 auto report = std::make_unique(
-*BT, "Access out-of-bound array element (buffer overflow)", N);
+BT, "Access out-of-bound array element (buffer overflow)", N);
 
 report->addRange(LoadS->getSourceRange());
 C.emitReport(std::move(report));
diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 5e25153a148fea..c72a97cc01e914 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChec

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

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

https://github.com/dtcxzyw edited 
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


[clang] 1228bec - [FuncAttrs] Deduce `noundef` attributes for return values (#76553)

2023-12-31 Thread via cfe-commits

Author: Yingwei Zheng
Date: 2023-12-31T20:44:48+08:00
New Revision: 1228becf7df28c68579f2b9b390b74aa41149a0a

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

LOG: [FuncAttrs] Deduce `noundef` attributes for return values (#76553)

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`.
Definition of `noundef` from LangRef:
```
noundef
This attribute applies to parameters and return values. If the value 
representation contains any 
undefined or poison bits, the behavior is undefined. Note that this does not 
refer to padding 
introduced by the type’s storage representation.
```
Alive2: https://alive2.llvm.org/ce/z/g8Eis6

Compile-time impact: 
http://llvm-compile-time-tracker.com/compare.php?from=30dcc33c4ea3ab50397a7adbe85fe977d4a400bd&to=c5e8738d4bfbf1e97e3f455fded90b791f223d74&stat=instructions:u
|stage1-O3|stage1-ReleaseThinLTO|stage1-ReleaseLTO-g|stage1-O0-g|stage2-O3|stage2-O0-g|stage2-clang|
|--|--|--|--|--|--|--|
|+0.01%|+0.01%|-0.01%|+0.01%|+0.03%|-0.04%|+0.01%|

The motivation of this patch is to reduce the number of `freeze` insts
and enable more optimizations.

Added: 
llvm/test/Transforms/FunctionAttrs/noundef.ll

Modified: 
clang/test/CodeGen/X86/ms-x86-intrinsics.c
clang/test/CodeGen/arm-bf16-params-returns.c
clang/test/CodeGen/arm-vector_type-params-returns.c
clang/test/CodeGen/ifunc.c
clang/test/CodeGen/isfpclass.c
clang/test/CodeGen/ms-mixed-ptr-sizes.c
clang/test/CodeGenCUDA/link-builtin-bitcode-denormal-fp-mode.cu
clang/test/CodeGenOpenCL/as_type.cl
lld/test/COFF/savetemps.ll
lld/test/ELF/lto/devirt_validate_vtable_typeinfos.ll
lld/test/ELF/lto/devirt_validate_vtable_typeinfos_mixed_lto.ll
lld/test/ELF/lto/devirt_validate_vtable_typeinfos_no_rtti.ll
lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
lld/test/ELF/lto/devirt_vcall_vis_public.ll
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/CodeGen/BPF/loop-exit-cond.ll
llvm/test/CodeGen/NVPTX/nvvm-reflect-opaque.ll
llvm/test/CodeGen/NVPTX/nvvm-reflect.ll
llvm/test/DebugInfo/X86/array2.ll
llvm/test/ThinLTO/X86/devirt.ll
llvm/test/ThinLTO/X86/devirt2.ll
llvm/test/ThinLTO/X86/devirt_check.ll
llvm/test/ThinLTO/X86/devirt_promote.ll
llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
llvm/test/ThinLTO/X86/devirt_pure_virtual_base.ll
llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
llvm/test/ThinLTO/X86/funcimport.ll
llvm/test/ThinLTO/X86/globals-import-const-fold.ll
llvm/test/ThinLTO/X86/import-constant.ll
llvm/test/ThinLTO/X86/index-const-prop-alias.ll
llvm/test/ThinLTO/X86/index-const-prop.ll
llvm/test/Transforms/FunctionAttrs/nocapture.ll
llvm/test/Transforms/FunctionAttrs/nonnull.ll
llvm/test/Transforms/FunctionAttrs/out-of-bounds-iterator-bug.ll
llvm/test/Transforms/Inline/devirtualize-3.ll
llvm/test/Transforms/Inline/devirtualize-5.ll
llvm/test/Transforms/Inline/launder.invariant.group.ll

llvm/test/Transforms/PhaseOrdering/AArch64/constraint-elimination-placement.ll
llvm/test/Transforms/PhaseOrdering/X86/merge-functions.ll
llvm/test/Transforms/PhaseOrdering/bitcast-store-branch.ll
llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion-loads.ll
llvm/test/Transforms/PhaseOrdering/early-arg-attrs-inference.ll
llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
llvm/test/Transforms/SampleProfile/ctxsplit.ll

Removed: 




diff  --git a/clang/test/CodeGen/X86/ms-x86-intrinsics.c 
b/clang/test/CodeGen/X86/ms-x86-intrinsics.c
index b4b8f5dc0b8c55..a1c90d71c8ebf5 100644
--- a/clang/test/CodeGen/X86/ms-x86-intrinsics.c
+++ b/clang/test/CodeGen/X86/ms-x86-intrinsics.c
@@ -145,7 +145,7 @@ unsigned __int64 test__shiftleft128(unsigned __int64 l, 
unsigned __int64 h,
 unsigned char d) {
   return __shiftleft128(l, h, d);
 }
-// CHECK-X64-LABEL: define dso_local i64 @test__shiftleft128(i64 noundef %l, 
i64 noundef %h, i8 noundef %d)
+// CHECK-X64-LABEL: define dso_local noundef i64 @test__shiftleft128(i64 
noundef %l, i64 noundef %h, i8 noundef %d)
 // CHECK-X64: = zext i8 %{{.*}} to i64
 // CHECK-X64: = tail call i64 @llvm.fshl.i64(i64 %h, i64 %l, i64 %{{.*}})
 // CHECK-X64:  ret i64 %
@@ -154,7 +154,7 @@ unsigned __int64 test__shiftright128(unsigned __int64 l, 
unsigned __int64 h,
  unsigned char d) {
   return __shiftright128(l, h, d);
 }
-// CHECK-X64-LABEL: define dso_local i64 @test__shiftright128(i64 noundef %l, 
i64 noundef %h, i8 nou

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

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

https://github.com/dtcxzyw closed 
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


[clang] [Cygwin] Cygwin driver (PR #74933)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74933

From 40ec69c72a4951953ce96c1ab30ec17a07f430cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sat, 9 Dec 2023 21:51:29 +0800
Subject: [PATCH 1/7] 1

---
 clang/lib/Driver/CMakeLists.txt|   1 +
 clang/lib/Driver/Driver.cpp|   4 +
 clang/lib/Driver/ToolChains/Cygwin.cpp | 731 +
 clang/lib/Driver/ToolChains/Cygwin.h   | 125 +
 clang/lib/Lex/InitHeaderSearch.cpp |  30 +-
 5 files changed, 865 insertions(+), 26 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp
 create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h

diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 58427e3f83c420..7ab5a1ee963515 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -51,6 +51,7 @@ add_clang_library(clangDriver
   ToolChains/CrossWindows.cpp
   ToolChains/CSKYToolChain.cpp
   ToolChains/Cuda.cpp
+  ToolChains/Cygwin.cpp
   ToolChains/Darwin.cpp
   ToolChains/DragonFly.cpp
   ToolChains/Flang.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9b2f2a37480983..4d08c9a14c9bcf 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -17,6 +17,7 @@
 #include "ToolChains/Clang.h"
 #include "ToolChains/CrossWindows.h"
 #include "ToolChains/Cuda.h"
+#include "ToolChains/Cygwin.h"
 #include "ToolChains/Darwin.h"
 #include "ToolChains/DragonFly.h"
 #include "ToolChains/FreeBSD.h"
@@ -6269,6 +6270,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
 else
   TC = std::make_unique(*this, Target, Args);
 break;
+  case llvm::Triple::Cygnus:
+TC = std::make_unique(*this, Target, Args);
+break;
   case llvm::Triple::GNU:
 TC = std::make_unique(*this, Target, Args);
 break;
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp 
b/clang/lib/Driver/ToolChains/Cygwin.cpp
new file mode 100644
index 00..8aa9cf5c8ec034
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -0,0 +1,731 @@
+//===--- Cygwin.cpp - CygwinToolChain Implementation 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Cygwin.h"
+#include "CommonArgs.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 
+
+using namespace clang::diag;
+using namespace clang::driver;
+using namespace clang;
+using namespace llvm::opt;
+
+/// Cygwin Tools
+void tools::Cygwin::Assembler::ConstructJob(Compilation &C, const JobAction 
&JA,
+   const InputInfo &Output,
+   const InputInfoList &Inputs,
+   const ArgList &Args,
+   const char *LinkingOutput) const {
+  claimNoWarnArgs(Args);
+  ArgStringList CmdArgs;
+
+  if (getToolChain().getArch() == llvm::Triple::x86) {
+CmdArgs.push_back("--32");
+  } else if (getToolChain().getArch() == llvm::Triple::x86_64) {
+CmdArgs.push_back("--64");
+  }
+
+  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, 
options::OPT_Xassembler);
+
+  CmdArgs.push_back("-o");
+  CmdArgs.push_back(Output.getFilename());
+
+  for (const auto &II : Inputs)
+CmdArgs.push_back(II.getFilename());
+
+  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ Exec, CmdArgs, Inputs, Output));
+
+  if (Args.hasArg(options::OPT_gsplit_dwarf))
+SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
+   SplitDebugName(JA, Args, Inputs[0], Output));
+}
+
+void tools::Cygwin::Linker::AddLibGCC(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+  // Make use of compiler-rt if --rtlib option is used
+  ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
+  if (RLT == ToolChain::RLT_Libgcc) {
+bool Static = Args.hasArg(options::OPT_static_libgcc) ||
+  Args.hasArg(options::OPT_static);
+bool Shared = Args.hasArg(options::OPT_shared);
+bool CXX = getToolChain().getDriver().CCCIsCXX();
+
+if (Static || (!CXX && !S

[clang] [Cygwin] Cygwin basic support (PR #74868)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74868

From 35cb22083fc0f842e873c99518a58d673bbcb1ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sat, 9 Dec 2023 00:59:00 +0800
Subject: [PATCH 1/3] [Cygwin] Cygwin basic support

---
 clang/lib/Basic/Targets/X86.h | 5 -
 clang/lib/Driver/ToolChains/Clang.cpp | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 0ab1c10833db26..e77e1e690cfc0c 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -905,7 +905,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : 
public X86_64TargetInfo {
   CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : X86_64TargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
-TLSSupported = false;
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -919,6 +918,10 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : 
public X86_64TargetInfo {
 if (Opts.CPlusPlus)
   Builder.defineMacro("_GNU_SOURCE");
   }
+
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
 };
 
 class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index acfa119805068d..38b9b84cf37c5b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6729,7 +6729,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // -fuse-cxa-atexit is default.
   if (!Args.hasFlag(
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
-  !RawTriple.isOSAIX() && !RawTriple.isOSWindows() &&
+  !RawTriple.isOSAIX()
+  && !RawTriple.isWindowsGNUEnvironment()
+  && !RawTriple.isWindowsMSVCEnvironment() &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||
   KernelOrKext)

From 99199c9364be0d8cd83a65ea5425715a82e2a40f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sat, 9 Dec 2023 01:08:20 +0800
Subject: [PATCH 2/3] 1

---
 clang/lib/Driver/ToolChains/Clang.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 38b9b84cf37c5b..58b042266c6091 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6729,9 +6729,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // -fuse-cxa-atexit is default.
   if (!Args.hasFlag(
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
-  !RawTriple.isOSAIX()
-  && !RawTriple.isWindowsGNUEnvironment()
-  && !RawTriple.isWindowsMSVCEnvironment() &&
+  !RawTriple.isOSAIX() && !RawTriple.isWindowsGNUEnvironment() &&
+  !RawTriple.isWindowsMSVCEnvironment() &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||
   KernelOrKext)

From 856ecf178a2487f7449bd291f6ce78b13f07fd24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sat, 9 Dec 2023 12:37:05 +0800
Subject: [PATCH 3/3] 1

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

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 58b042266c6091..acfa119805068d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6729,8 +6729,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // -fuse-cxa-atexit is default.
   if (!Args.hasFlag(
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
-  !RawTriple.isOSAIX() && !RawTriple.isWindowsGNUEnvironment() &&
-  !RawTriple.isWindowsMSVCEnvironment() &&
+  !RawTriple.isOSAIX() && !RawTriple.isOSWindows() &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||
   KernelOrKext)

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


[clang] [Cygwin] Cygwin general (PR #74936)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74936

From c9cffe8c188d32a9edd1b6316db065bbcc479c97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 00:34:27 +0800
Subject: [PATCH] 1

---
 clang/lib/Headers/mm_malloc.h |  6 +++---
 clang/tools/libclang/CIndexer.cpp | 10 ++
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index d32fe594162774..6f46f10ee50f31 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -12,7 +12,7 @@
 
 #include 
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include 
 #else
 #ifndef __cplusplus
@@ -41,7 +41,7 @@ _mm_malloc(size_t __size, size_t __align) {
   void *__mallocedMemory;
 #if defined(__MINGW32__)
   __mallocedMemory = __mingw_aligned_malloc(__size, __align);
-#elif defined(_WIN32)
+#elif defined(_WIN32) && !defined(__CYGWIN__)
   __mallocedMemory = _aligned_malloc(__size, __align);
 #else
   if (posix_memalign(&__mallocedMemory, __align, __size))
@@ -56,7 +56,7 @@ _mm_free(void *__p)
 {
 #if defined(__MINGW32__)
   __mingw_aligned_free(__p);
-#elif defined(_WIN32)
+#elif defined(_WIN32) && !defined(__CYGWIN__)
   _aligned_free(__p);
 #else
   free(__p);
diff --git a/clang/tools/libclang/CIndexer.cpp 
b/clang/tools/libclang/CIndexer.cpp
index 12d9d418dea51d..e7c1bed8b740fd 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -27,12 +27,10 @@
 #include 
 
 #ifdef __CYGWIN__
-#include 
 #include 
-#define _WIN32 1
 #endif
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
 #include 
 #elif defined(_AIX)
 #include 
@@ -105,7 +103,7 @@ const std::string &CIndexer::getClangResourcesPath() {
   SmallString<128> LibClangPath;
 
   // Find the location where this library lives (libclang.dylib).
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
   MEMORY_BASIC_INFORMATION mbi;
   char path[MAX_PATH];
   VirtualQuery((void *)(uintptr_t)clang_createTranslationUnit, &mbi,
@@ -115,11 +113,7 @@ const std::string &CIndexer::getClangResourcesPath() {
 #ifdef __CYGWIN__
   char w32path[MAX_PATH];
   strcpy(w32path, path);
-#if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 181
   cygwin_conv_path(CCP_WIN_A_TO_POSIX, w32path, path, MAX_PATH);
-#else
-  cygwin_conv_to_full_posix_path(w32path, path);
-#endif
 #endif
 
   LibClangPath += path;

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


[clang] [Cygwin] Cygwin macro (PR #74973)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74973

From 29f213f8921c38ca8192aa32087e99771a0cfbfb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 14:04:36 +0800
Subject: [PATCH 1/2] 1

---
 clang/lib/Basic/Targets/ARM.cpp | 2 --
 clang/lib/Basic/Targets/X86.cpp | 9 +++--
 clang/lib/Basic/Targets/X86.h   | 4 
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 01f9e844da12a0..800f61c0c67864 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -1402,8 +1402,6 @@ void CygwinARMTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   Builder.defineMacro("__CYGWIN__");
   Builder.defineMacro("__CYGWIN32__");
   DefineStd(Builder, "unix", Opts);
-  if (Opts.CPlusPlus)
-Builder.defineMacro("_GNU_SOURCE");
 }
 
 DarwinARMTargetInfo::DarwinARMTargetInfo(const llvm::Triple &Triple,
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 3deaa19f8d4fc4..2e281439ae13a7 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -508,8 +508,13 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
 
   std::string CodeModel = getTargetOpts().CodeModel;
-  if (CodeModel == "default")
-CodeModel = "small";
+  if (CodeModel == "default") {
+if (getTriple().isWindowsCygwinEnvironment() && getTriple().getArch() == 
llvm::Triple::x86_64) {
+  CodeModel = "medium";
+} else {
+  CodeModel = "small";
+}
+  }
   Builder.defineMacro("__code_model_" + CodeModel + "__");
 
   // Target identification.
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 0ab1c10833db26..1664fcc417b148 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -643,8 +643,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : 
public X86_32TargetInfo {
 Builder.defineMacro("__CYGWIN32__");
 addCygMingDefines(Opts, Builder);
 DefineStd(Builder, "unix", Opts);
-if (Opts.CPlusPlus)
-  Builder.defineMacro("_GNU_SOURCE");
   }
 };
 
@@ -916,8 +914,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : 
public X86_64TargetInfo {
 Builder.defineMacro("__CYGWIN64__");
 addCygMingDefines(Opts, Builder);
 DefineStd(Builder, "unix", Opts);
-if (Opts.CPlusPlus)
-  Builder.defineMacro("_GNU_SOURCE");
   }
 };
 

From fa807942d6be7b0f486ed7f64c0113a288fa8264 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 14:13:02 +0800
Subject: [PATCH 2/2] 1

---
 clang/lib/Basic/Targets/X86.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 2e281439ae13a7..e6b2d1160de9ad 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -509,7 +509,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default") {
-if (getTriple().isWindowsCygwinEnvironment() && getTriple().getArch() == 
llvm::Triple::x86_64) {
+if (getTriple().isWindowsCygwinEnvironment() &&
+getTriple().getArch() == llvm::Triple::x86_64) {
   CodeModel = "medium";
 } else {
   CodeModel = "small";

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


[clang] [MinGW] MinGW Value.h (PR #74982)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74982

From 79391542d94910efe25f09374ef241456609dbde Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 15:16:38 +0800
Subject: [PATCH] 1

---
 clang/include/clang/Interpreter/Value.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
index c380cd91550def..46e827f3ec283d 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -52,7 +52,8 @@ class ASTContext;
 class Interpreter;
 class QualType;
 
-#if defined(_WIN32)
+#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
+#if defined(_WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
 // REPL_EXTERNAL_VISIBILITY are symbols that we need to be able to locate
 // at runtime. On Windows, this requires them to be exported from any of the
 // modules loaded at runtime. Marking them as dllexport achieves this; both
@@ -63,7 +64,6 @@ class QualType;
 // statically linked into an EXE, it makes sure that they're exported.
 #define REPL_EXTERNAL_VISIBILITY __declspec(dllexport)
 #elif __has_attribute(visibility)
-#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
 #define REPL_EXTERNAL_VISIBILITY __attribute__((visibility("default")))
 #else
 #define REPL_EXTERNAL_VISIBILITY

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


[clang] [MinGW] MinGW pthread (PR #74981)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74981

From 0a90989e77603a49b17eaf44cbbffa9c003afb54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 15:12:11 +0800
Subject: [PATCH] 1

---
 clang/lib/Driver/ToolChains/MinGW.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 65512f16357d04..3a0bc2abf03935 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -307,7 +307,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pg))
 CmdArgs.push_back("-lgmon");
 
-  if (Args.hasArg(options::OPT_pthread))
+  if (!Args.hasArg(options::OPT_no_pthread))
 CmdArgs.push_back("-lpthread");
 
   if (Sanitize.needsAsanRt()) {

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


[clang-tools-extra] [pseudo] gen Main.cpp (PR #74983)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74983

From 164ce88e00c341b2507618f67a8971d55f9aee9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 15:27:25 +0800
Subject: [PATCH 1/2] 1

---
 clang-tools-extra/pseudo/gen/Main.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/pseudo/gen/Main.cpp 
b/clang-tools-extra/pseudo/gen/Main.cpp
index 25cb26563837a6..c9367ca16ed85e 100644
--- a/clang-tools-extra/pseudo/gen/Main.cpp
+++ b/clang-tools-extra/pseudo/gen/Main.cpp
@@ -70,13 +70,13 @@ namespace {
 //   keyword: `INT` becomes `INT`;
 //   terminal: `IDENTIFIER` becomes `IDENTIFIER`;
 std::string mangleSymbol(SymbolID SID, const Grammar &G) {
-  static auto &TokNames = *new std::vector{
-#define TOK(X) llvm::StringRef(#X).upper(),
-#define KEYWORD(Keyword, Condition) llvm::StringRef(#Keyword).upper(),
+  static char const * TokNames[] = {
+#define TOK(X) #X ,
+#define KEYWORD(Keyword, Condition) #Keyword ,
 #include "clang/Basic/TokenKinds.def"
   };
   if (isToken(SID))
-return TokNames[symbolToToken(SID)];
+return llvm::StringRef(TokNames[symbolToToken(SID)]).upper();
   std::string Name = G.symbolName(SID).str();
   // translation-unit -> translation_unit
   std::replace(Name.begin(), Name.end(), '-', '_');

From 94362c452d9743c6ee78f084e9e90baafeb45beb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 15:38:56 +0800
Subject: [PATCH 2/2] 1

---
 clang-tools-extra/pseudo/gen/Main.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/pseudo/gen/Main.cpp 
b/clang-tools-extra/pseudo/gen/Main.cpp
index c9367ca16ed85e..2c0bf662ef405d 100644
--- a/clang-tools-extra/pseudo/gen/Main.cpp
+++ b/clang-tools-extra/pseudo/gen/Main.cpp
@@ -70,11 +70,11 @@ namespace {
 //   keyword: `INT` becomes `INT`;
 //   terminal: `IDENTIFIER` becomes `IDENTIFIER`;
 std::string mangleSymbol(SymbolID SID, const Grammar &G) {
-  static char const * TokNames[] = {
-#define TOK(X) #X ,
-#define KEYWORD(Keyword, Condition) #Keyword ,
+  static char const *TokNames[] = {
+#define TOK(X) #X,
+#define KEYWORD(Keyword, Condition) #Keyword,
 #include "clang/Basic/TokenKinds.def"
-  };
+  };
   if (isToken(SID))
 return llvm::StringRef(TokNames[symbolToToken(SID)]).upper();
   std::string Name = G.symbolName(SID).str();

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


[clang-tools-extra] [pseudo] lib Grammar.cpp (PR #74984)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74984

From bba8cd890cb7edcff3852ac6bf225e358d2aaac2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 15:31:36 +0800
Subject: [PATCH] 1

---
 clang-tools-extra/pseudo/lib/grammar/Grammar.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp 
b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
index 3e9c5c3c7a6c42..ec6e8915a2c7d7 100644
--- a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
@@ -172,9 +172,10 @@ std::vector> followSets(const 
Grammar &G) {
   return FollowSets;
 }
 
+static auto TerminalNames = new std::string[NumTerminals];
+
 static llvm::ArrayRef getTerminalNames() {
-  static const auto &TerminalNames = []() {
-auto TerminalNames = new std::string[NumTerminals];
+  static const auto &TerminalNames1 = []() {
 #define PUNCTUATOR(Tok, Spelling) TerminalNames[tok::Tok] = Spelling;
 #define KEYWORD(Keyword, Condition)
\
   TerminalNames[tok::kw_##Keyword] = llvm::StringRef(#Keyword).upper();
@@ -182,7 +183,7 @@ static llvm::ArrayRef getTerminalNames() {
 #include "clang/Basic/TokenKinds.def"
 return llvm::ArrayRef(TerminalNames, NumTerminals);
   }();
-  return TerminalNames;
+  return TerminalNames1;
 }
 GrammarTable::GrammarTable() : Terminals(getTerminalNames()) {}
 

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


[clang] [Cygwin] Reduced number of inline elements of CallArgList. (PR #74977)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

https://github.com/xu-chiheng updated 
https://github.com/llvm/llvm-project/pull/74977

From 36031b0f4940d31edf026882ec47cd4bee90e324 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 
Date: Sun, 10 Dec 2023 14:52:29 +0800
Subject: [PATCH] 1

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

diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 1c0d15dc932ad8..e96a7edd2a511c 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -255,7 +255,7 @@ struct CallArg {
 
 /// CallArgList - Type for representing both the value and type of
 /// arguments in a call.
-class CallArgList : public SmallVector {
+class CallArgList : public SmallVector {
 public:
   CallArgList() = default;
 

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


[clang] [Cygwin] Reduced number of inline elements of CallArgList. (PR #74977)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

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


[clang] [Cygwin] Cygwin CGCall.h (PR #74977)

2023-12-31 Thread 徐持恒 Xu Chiheng via cfe-commits

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


[clang] [clang][Sema] Warn on self move for inlined static cast (PR #76646)

2023-12-31 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/76646

>From a081f8266f24405523e6d283318bd898fd2d376a Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sat, 30 Dec 2023 22:00:38 -0500
Subject: [PATCH 1/2] Warn on self move for inlined static cast

---
 clang/lib/Sema/SemaChecking.cpp   | 19 ++-
 clang/test/SemaCXX/warn-self-move.cpp | 13 +
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2a69325f029514..a21410434d8099 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -18843,17 +18843,26 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, 
const Expr *RHSExpr,
   LHSExpr = LHSExpr->IgnoreParenImpCasts();
   RHSExpr = RHSExpr->IgnoreParenImpCasts();
 
-  // Check for a call expression
+  // Check for a call expression or static_cast expression
   const CallExpr *CE = dyn_cast(RHSExpr);
-  if (!CE || CE->getNumArgs() != 1)
+  const CXXStaticCastExpr *CXXSCE = dyn_cast(RHSExpr);
+  if (!CE && !CXXSCE)
 return;
 
   // Check for a call to std::move
-  if (!CE->isCallToStdMove())
+  if (CE && (CE->getNumArgs() != 1 || !CE->isCallToStdMove()))
 return;
 
-  // Get argument from std::move
-  RHSExpr = CE->getArg(0);
+  // Check for a static_cast(..) to an xvalue which we can treat as an
+  // inlined std::move
+  if (CXXSCE && !CXXSCE->isXValue())
+return;
+
+  // Get argument from std::move or static_cast
+  if (CE)
+RHSExpr = CE->getArg(0);
+  else
+RHSExpr = CXXSCE->getSubExpr();
 
   const DeclRefExpr *LHSDeclRef = dyn_cast(LHSExpr);
   const DeclRefExpr *RHSDeclRef = dyn_cast(RHSExpr);
diff --git a/clang/test/SemaCXX/warn-self-move.cpp 
b/clang/test/SemaCXX/warn-self-move.cpp
index 0987e9b6bf6017..d0158626424142 100644
--- a/clang/test/SemaCXX/warn-self-move.cpp
+++ b/clang/test/SemaCXX/warn-self-move.cpp
@@ -16,6 +16,9 @@ void int_test() {
   x = std::move(x);  // expected-warning{{explicitly moving}}
   (x) = std::move(x);  // expected-warning{{explicitly moving}}
 
+  x = static_cast(x);  // expected-warning{{explicitly moving}}
+  (x) = static_cast(x);  // expected-warning{{explicitly moving}}
+
   using std::move;
   x = move(x); // expected-warning{{explicitly moving}} \
expected-warning {{unqualified call to 'std::move}}
@@ -26,6 +29,9 @@ void global_int_test() {
   global = std::move(global);  // expected-warning{{explicitly moving}}
   (global) = std::move(global);  // expected-warning{{explicitly moving}}
 
+  global = static_cast(global);  // expected-warning{{explicitly 
moving}}
+  (global) = static_cast(global);  // expected-warning{{explicitly 
moving}}
+
   using std::move;
   global = move(global); // expected-warning{{explicitly moving}} \
  expected-warning {{unqualified call to 
'std::move}}
@@ -35,11 +41,14 @@ class field_test {
   int x;
   field_test(field_test&& other) {
 x = std::move(x);  // expected-warning{{explicitly moving}}
+x = static_cast(x);  // expected-warning{{explicitly moving}}
 x = std::move(other.x);
 other.x = std::move(x);
 other.x = std::move(other.x);  // expected-warning{{explicitly moving}}
+other.x = static_cast(other.x);  // expected-warning{{explicitly 
moving}}
   }
   void withSuggest(int x) {
+x = static_cast(x); // expected-warning{{explicitly moving variable 
of type 'int' to itself; did you mean to move to member 'x'?}}
 x = std::move(x); // expected-warning{{explicitly moving variable of type 
'int' to itself; did you mean to move to member 'x'?}}
   }
 };
@@ -50,11 +59,15 @@ struct C { C() {}; ~C() {} };
 void struct_test() {
   A a;
   a = std::move(a);  // expected-warning{{explicitly moving}}
+  a = static_cast(a);  // expected-warning{{explicitly moving}}
 
   B b;
   b = std::move(b);  // expected-warning{{explicitly moving}}
+  b = static_cast(b);  // expected-warning{{explicitly moving}}
   b.a = std::move(b.a);  // expected-warning{{explicitly moving}}
+  b.a = static_cast(b.a);  // expected-warning{{explicitly moving}}
 
   C c;
   c = std::move(c);  // expected-warning{{explicitly moving}}
+  c = static_cast(c);  // expected-warning{{explicitly moving}}
 }

>From ecd9d5bf0d3fa0bc3e64266c6e7586da25438652 Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sun, 31 Dec 2023 17:47:03 -0500
Subject: [PATCH 2/2] use auto

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

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a21410434d8099..ecb3269d0d30c7 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -18845,7 +18845,7 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, const 
Expr *RHSExpr,
 
   // Check for a call expression or static_cast expression
   const CallExpr *CE = dy

[clang-tools-extra] [pseudo] gen Main.cpp (PR #74983)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

asl wrote:

Will you please provide meaningful description in the PRs from now on? Since 
this is not the first time you've been asked to do this and you are ignoring 
these requests I'm closing this PR. Please do not use PRs to debug your own 
issues, this is wasting both time of reviewers as well as CI time.

Feel free to reopen when / if you will be able to fix these issues.

For more information about proper way to contribute to LLVM consider 
familiarizing yourself with:
  * https://llvm.org/docs/Contributing.html#how-to-submit-a-patch
  * https://llvm.org/docs/CodeReview.html

Thanks.

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


[clang-tools-extra] [pseudo] gen Main.cpp (PR #74983)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

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


[clang-tools-extra] [pseudo] lib Grammar.cpp (PR #74984)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

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


[clang-tools-extra] [pseudo] lib Grammar.cpp (PR #74984)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

asl wrote:

Will you please provide meaningful description in the PRs from now on? Since 
this is not the first time you've been asked to do this and you are ignoring 
these requests I'm closing this PR. Please do not use PRs to debug your own 
issues, this is wasting both time of reviewers as well as CI time.

Feel free to reopen when / if you will be able to fix these issues.

For more information about proper way to contribute to LLVM consider 
familiarizing yourself with:

 * https://llvm.org/docs/Contributing.html#how-to-submit-a-patch
 * https://llvm.org/docs/CodeReview.html
Thanks.

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


[clang] [MinGW] MinGW pthread (PR #74981)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

asl wrote:

@xu-chiheng  Will you please provide meaningful description in the PRs from now 
on? Since this is not the first time you've been asked to do this and you are 
ignoring these requests I'm closing this PR. Please do not use PRs to debug 
your own issues, this is wasting both time of reviewers as well as CI time.

Feel free to reopen when / if you will be able to fix these issues.

For more information about proper way to contribute to LLVM consider 
familiarizing yourself with:

 * https://llvm.org/docs/Contributing.html#how-to-submit-a-patch
 * https://llvm.org/docs/CodeReview.html
Thanks.

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


[clang] [MinGW] MinGW pthread (PR #74981)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

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


[clang] [MinGW] MinGW Value.h (PR #74982)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

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


[clang] [MinGW] MinGW Value.h (PR #74982)

2023-12-31 Thread Anton Korobeynikov via cfe-commits

asl wrote:

Will you please provide meaningful description in the PRs from now on? Since 
this is not the first time you've been asked to do this and you are ignoring 
these requests I'm closing this PR. Please do not use PRs to debug your own 
issues, this is wasting both time of reviewers as well as CI time.

Feel free to reopen when / if you will be able to fix these issues.

For more information about proper way to contribute to LLVM consider 
familiarizing yourself with:

 * https://llvm.org/docs/Contributing.html#how-to-submit-a-patch
 * https://llvm.org/docs/CodeReview.html
Thanks.

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


[clang] [Cygwin] Cygwin basic support (PR #74868)

2023-12-31 Thread Anton Korobeynikov via cfe-commits
=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng
Message-ID:
In-Reply-To: 


asl wrote:

Will you please provide meaningful description in the PRs from now on? Since 
this is not the first time you've been asked to do this and you are ignoring 
these requests I'm closing this PR. Please do not use PRs to debug your own 
issues, this is wasting both time of reviewers as well as CI time.

Feel free to reopen when / if you will be able to fix these issues.

For more information about proper way to contribute to LLVM consider 
familiarizing yourself with:

 * https://llvm.org/docs/Contributing.html#how-to-submit-a-patch
 * https://llvm.org/docs/CodeReview.html
 
Thanks.

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


[clang] [Cygwin] Cygwin basic support (PR #74868)

2023-12-31 Thread Anton Korobeynikov via cfe-commits
=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng,=?utf-8?b?5b6Q5oyB5oGS?= Xu Chiheng
Message-ID:
In-Reply-To: 


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


[clang] [clang] Add `clang::behaves_like_std(...)` attribute (PR #76596)

2023-12-31 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

I appreciate the discussions. I know I have a tendency to get ranty in my 
writing so I just want to be clear that I mean no malice.
I can further explain my side.

> Include times
> Modules should ease that pain

I don't know how else to make it clear that we will never be including std 
headers from our core library headers and within the core engine itself. The 
include times are a non-starter. If the verdict is just use std, we are going 
to continue just marking these functions as `always_inline` and live with the 
worse code gen than a builtin but still better than a function call.

Even if libc++ becomes tolerable we have to deal with msvc stl, libstdc++, 
libc++, SCE stl, and vendor forks of libc++ that I will not mention since this 
specific company is super duper litigious over the most minor things.
If I could have an attribute that solves my problems without header includes 
and I can chuck it on the implementations in our core libraries then I am 
golden instead of trying to work around various std libraries.

I also want to highlight that we in particular have a wide range of platform 
support.
We were just able to get rid of VS2015 early 2023. We also finally removed 
GCC4.8 late 2022.
We still have to ship on a custom toolchain of VS2017 msvc for Xbox One.
We have game teams that are also on the latest VS2022.
Our macOS/iPhone support is quite wide as well.
SCE is very quick to upgrade their clang so we are on Clang 16 now if my memory 
is correct there on SCE. Any change to libc++ does not help SCE STL or the 
other vendors shipping their own fork of clang + libc++. A lot of these vendors 
will upgrade clang but not libc++ as well.

On our Linux servers we have such a variety of distros and GCC/Clang versions.

Regarding modules. Try moving the titanic that is [insert favourite game here 
that is shipping content every year].
Now try moving 3+ titanics.
Try moving that when you still have platforms that cannot move past VS2017.
Plus some vendors have no intention, as far as I am aware, of supporting 
modules in their vendor libraries which do include `` and such for 
move/forward.

Apple Clang + Xcode still don't support modules last I checked. We haven't 
upgraded to Xcode 15 yet.

We have our own build system generator. We have our own package management 
system. We have our stuff working well with PCH files where needed.
We have all the infrastructure set up to promote fast builds from the core 
libraries down the stack. I don't foresee us even considering modules for 10+ 
years.

> More general observations on the "using c++ without the STL thing":
> I don't think this is a major consideration of the language/standard 
> committee going forward.
> Reflection will also have a dependency on the STL

I don't want to speak for my peers but I think I can speak to the general 
sentiment of my community.
This is why among many many many other reasons SG14 failed and why a lot of us 
in the game dev community have just given up.
Some are at companies that do not allow any form of open source contributions 
or participation in the C++ discourse. That seems to be changing.
Thankfully I am at a company that does allows me to make these contributions 
here on my free time, LLVM license makes it easy for me to do so and I have the 
means to try to push them through. Selfishly for me but also for the game dev 
community at large.
Especially nowadays where we can basically ship with clang on almost every 
platform, a change in clang affects our entire ecosystem. It seems gone are the 
days of custom vendor compilers for every platform with EDG as the frontend.

I have followed the Reflection TS and its fine. At every game company I worked 
at our reflection needs are so esoteric that we are going to continue writing 
our own with our own code generators.
Almost every single game engine has its own way to do some form of dynamic 
casting, similar reasons that llvm also seems to have its own infrastructure 
from reading the docs, and that casting is usually very tightly integrated with 
the engine's reflection system.
Trying to highlight that in general a lot of these papers, for the language 
itself or the std, will never solve the esoteric needs of us or handle the 
esoteric platforms that we support. Not everything uses the BSD sockets API for 
example. Win32 is considered BSD compared to the stuff I've seen.
We just want a systems language that allows us to accomplish system level tasks 
while still retaining a lot of really useful core features like templates, easy 
support for intrusive data structures, control over allocations, etc.

As mentioned above our Linux servers use a variety of distros. The server 
software running in our datacentres still uses all our core libraries like all 
the game software but has more liberty with what game teams can run. We are 
less strict on what the various amount of server services are allowed to use 
since that software is usually tightly w

[clang-tools-extra] [clangd] Handle lambda scopes inside Node::getDeclContext() (PR #76329)

2023-12-31 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Ping. And Happy New Year 2024!

https://github.com/llvm/llvm-project/pull/76329
___
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)

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

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


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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -416,10 +421,15 @@ struct FormatToken {
   /// to another one please use overwriteFixedType, or even better remove the
   /// need to reassign the type.
   void setFinalizedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
+

owenca wrote:

Remove this empty line to be consistent with lines 431-432 below?

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -255,6 +255,44 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a=(b); if(x) c");
+  verifyFormat(R"(ASSIGN_OR_RETURN(auto reader,

owenca wrote:

It's hard to read the test cases with raw strings. Can you set `ColumnLimit` to 
60 so that we don't have to use raw strings?

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -255,6 +255,44 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a=(b); if(x) c");
+  verifyFormat(R"(ASSIGN_OR_RETURN(auto reader,
+ logs::proxy::Reader::NewReader(log_filename, access_options,
+reader_options),
+ _ << aa << aa << a
+   <<  << aaa << );
+)", Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b)=a=(b)");
+  EXPECT_EQ(R"(

owenca wrote:

Can you use the 1-argument version of `verifyFormat()` instead?

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -2919,6 +2912,12 @@ class ExpressionParser {
 
   void addFakeParenthesis(FormatToken *Start, prec::Level Precedence,
   FormatToken *End = nullptr) {
+// Do not assign fake parenthesis to tokens that are part of an
+// unexpanded macro call. The line within the macro call contains
+// the parenthesis and commas, and we will not find operators within
+// that structure.
+if (Start->MacroParent) return;

owenca wrote:

Please run git-clang-format locally. See 
[here](https://github.com/llvm/llvm-project/pull/76059#issuecomment-1865850011).

https://github.com/llvm/llvm-project/pull/76245
___
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)

2023-12-31 Thread Gábor Horváth 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,

Xazax-hun wrote:

Since we are changing this code, I guess we do not want to take `StringRef`s as 
const references.

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)

2023-12-31 Thread Gábor Horváth 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),

Xazax-hun wrote:

Move to field initializers?

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)

2023-12-31 Thread Gábor Horváth via cfe-commits


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

Xazax-hun wrote:

Since we mostly use `CallDescription`s with compile time known inputs, it would 
be nice to make their ctors constexpr. This is not for this PR, just a note for 
the future.

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)

2023-12-31 Thread Gábor Horváth via cfe-commits

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


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-tools-extra] Fix is spelled in source bug (PR #76668)

2023-12-31 Thread via cfe-commits

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

This fixes the issue reported in #76667 and adds an initial unit test for 
isSpelledInSource().

Note that in that issue there was still some underlying corrupted AST, but this 
at least makes isSpelledInSource() robust to it.

>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-tools-extra] Fix is spelled in source bug (PR #76668)

2023-12-31 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/76668
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-12-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: None (schenka0)


Changes

This fixes the issue reported in #76667 and adds an initial unit test 
for isSpelledInSource().

Note that in that issue there was still some underlying corrupted AST, but this 
at least makes isSpelledInSource() robust to it.

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/SourceCode.cpp (+6-1) 
- (modified) clang-tools-extra/clangd/unittests/SourceCodeTests.cpp (+15) 


``diff
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;

``




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


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

2023-12-31 Thread via cfe-commits

https://github.com/schenka0 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


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

2023-12-31 Thread via cfe-commits

schenka0 wrote:

PR: @sam-mccall 

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)

2023-12-31 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] [lld] [llvm] [flang] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2023-12-31 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/7] [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

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

2023-12-31 Thread Hristo Hristov via cfe-commits


@@ -208,8 +215,34 @@ _LIBCPP_PUSH_MACROS
 
 #if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
 
+#  if defined(_LIBCPP_WIN32API)
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#  endif
+
+// #  include 
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#  if _LIBCPP_STD_VER >= 26
+#if defined(_LIBCPP_WIN32API)
+using __filebuf_native_handle_type = HANDLE;
+_LIBCPP_EXPORTED_FROM_ABI __filebuf_native_handle_type 
__filebuf_windows_native_handle(FILE* __file);
+#else // POSIX
+using __filebuf_native_handle_type = int; // File descriptor
+#endif
+
+_LIBCPP_HIDE_FROM_ABI inline __filebuf_native_handle_type 
__filebuf_native_handle(FILE* __file) noexcept {
+#if defined(_LIBCPP_WIN32API)
+  return __filebuf_windows_native_handle(__file);
+#else
+  return ::fileno(__file);
+#endif
+}
+#  endif
+

H-G-Hristov wrote:

Great tip! Thank you!

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] [lld] [llvm] [flang] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2023-12-31 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,36 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include <__config>
+#include 
+#include 
+
+#if defined(_LIBCPP_WIN32API)
+#  define WIN32_LEAN_AND_MEAN
+#  define NOMINMAX
+#  include 
+#  include 
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+_LIBCPP_EXPORTED_FROM_ABI __filebuf_native_handle_type 
__filebuf_native_handle(FILE* __file) noexcept {

H-G-Hristov wrote:

Thank you for the tip! It helped me a lot!

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] [llvm] [lld] [flang] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2023-12-31 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/8] [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