[clang] [Clang] Allow diagnostics starting with Arm (PR #98091)

2024-07-13 Thread via cfe-commits

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


[clang] [Clang] Allow diagnostics starting with Arm (PR #98091)

2024-07-13 Thread via cfe-commits

amilendra wrote:

> This one looks fairly benign, and while I agree that it is good to upstream 
> things wherever possible, my slight objection rests mostly on two principles:
> 
> * In general the community doesn't take behavior-changing patches purely 
> on the basis of eliminating merge conflicts for code that is out of tree. 
> Things that go upstream need to have a justification that is relevant to 
> upstream.
> 
> * Changes that land need to come with tests that exercise them.
> 
> 
> FWIW, this particular change looks unlikely to be a source of merge 
> conflicts, as it adds only a single line to a table that is unlikely to be 
> touched very often. I think you'll be okay if this isn't upstream, but I 
> won't complain too loudly if you feel the need to land this anyway.

Thanks for the explanation. Yes, this seems simple enough that it won't be too 
hard to resolve even if a merge conflict appears. I'll abandon the change. 
Thanks for taking the time to review this.

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


[clang] 3fed312 - [clang][dataflow]Propagate the result object location for CXXDefaultInitExpr. (#98490)

2024-07-13 Thread via cfe-commits

Author: Samira Bazuzi
Date: 2024-07-13T00:38:49-07:00
New Revision: 3fed312d2bca7d44734ace75d18890675da0f89b

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

LOG: [clang][dataflow]Propagate the result object location for 
CXXDefaultInitExpr. (#98490)

These are not "original initializers"; the single node underneath
represents the initializing node.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 7c88917faf9c6..f734168e647bd 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -15,6 +15,7 @@
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/Type.h"
@@ -414,8 +415,8 @@ class ResultObjectVisitor : public 
AnalysisASTVisitor {
 // lowest-level AST node that initializes a given object, and nothing
 // below them can initialize the same object (or part of it).
 if (isa(E) || isa(E) || isa(E) ||
-isa(E) || isa(E) ||
-isa(E) || isa(E) ||
+isa(E) || isa(E) ||
+isa(E) ||
 // We treat `BuiltinBitCastExpr` as an "original initializer" too as
 // it may not even be casting from a record type -- and even if it is,
 // the two objects are in general of unrelated type.
@@ -463,6 +464,11 @@ class ResultObjectVisitor : public 
AnalysisASTVisitor {
   return;
 }
 
+if (auto *DIE = dyn_cast(E)) {
+  PropagateResultObject(DIE->getExpr(), Loc);
+  return;
+}
+
 // All other expression nodes that propagate a record prvalue should have
 // exactly one child.
 SmallVector Children(E->child_begin(), E->child_end());

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index bd710a00c47ce..a4ac597bb06d6 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -21,6 +21,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 namespace {
 
@@ -405,6 +406,42 @@ TEST_F(EnvironmentTest,
   Contains(Member));
 }
 
+// This is a repro of a failure case seen in the wild.
+TEST_F(EnvironmentTest, CXXDefaultInitExprResultObjIsWrappedExprResultObj) {
+  using namespace ast_matchers;
+
+  std::string Code = R"cc(
+  struct Inner {};
+
+  struct S {
+S() {}
+
+Inner i = {};
+  };
+  )cc";
+
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"});
+  auto &Context = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  auto Results =
+  match(cxxConstructorDecl(
+hasAnyConstructorInitializer(cxxCtorInitializer(
+withInitializer(expr().bind("default_init_expr")
+.bind("ctor"),
+Context);
+  const auto *Constructor = selectFirst("ctor", Results);
+  const auto *DefaultInit =
+  selectFirst("default_init_expr", Results);
+
+  Environment Env(DAContext, *Constructor);
+  Env.initialize();
+  EXPECT_EQ(&Env.getResultObjectLocation(*DefaultInit),
+&Env.getResultObjectLocation(*DefaultInit->getExpr()));
+}
+
 TEST_F(EnvironmentTest, Stmt) {
   using namespace ast_matchers;
 



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


[clang] [clang][dataflow]Propagate the result object location for CXXDefaultInitExpr. (PR #98490)

2024-07-13 Thread Gábor Horváth via cfe-commits

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


[clang] [clang] Add option to opt out of the missing_dependent_template_keyword diagnostic (PR #98613)

2024-07-13 Thread Haojian Wu via cfe-commits

hokein wrote:

It does filter out the `missing-dependent-template-keyword` warnings, but 
doesn't fix the absl case.

With 
https://github.com/llvm/llvm-project/commit/ce4aada6e2135e29839f672a6599db628b53295d,
 there is a behavior change in clang. Clang reject the following code which was 
accepted before by emitting a hard error `err_no_member`.


```
#define TYPE_OR_NONTYPE int

template
struct BaseT {
  void Foo(); // expected-note{{found by ambiguous name lookup}}
};

template
struct DerivedT : BaseT {
  void Inner();
};

template
void DerivedT::Inner() {
  this->BaseT::Foo();
}
```

- If the `TYPE_OR_NONTYPE` is `typename` (type template parameter case), clang 
emits a `missing-dependent-template-keyword` warning, which can be suppressed;
- If the `TYPE_OR_NONTYPE` is `int` (non-type template parameter case), clang 
emits a hard error `err_no_member`;

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


[clang] [clang][dataflow]Propagate the result object location for CXXDefaultInitExpr. (PR #98490)

2024-07-13 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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

Here is the relevant piece of the build log for the reference:
```
Step 6 (test) failure: build (failure)
...
29.707 [1/2/288] Linking CXX executable 
tools\lldb\unittests\ValueObject\LLDBValueObjectTests.exe
29.779 [1/1/289] Linking CXX executable 
tools\lldb\unittests\Thread\ThreadTests.exe
llvm-lit.py: 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\utils\lit\lit\llvm\config.py:57:
 note: using lit tools: C:\Users\tcwg\scoop\apps\git\2.39.0.windows.2\usr\bin
llvm-lit.py: 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\utils\lit\lit\llvm\config.py:508:
 note: using clang: 
c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe
llvm-lit.py: 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\utils\lit\lit\llvm\config.py:508:
 note: using ld.lld: 
c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\ld.lld.exe
llvm-lit.py: 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\utils\lit\lit\llvm\config.py:508:
 note: using lld-link: 
c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\lld-link.exe
llvm-lit.py: 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\utils\lit\lit\llvm\config.py:508:
 note: using ld64.lld: 
c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\ld64.lld.exe
llvm-lit.py: 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\utils\lit\lit\llvm\config.py:508:
 note: using wasm-ld: 
c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\wasm-ld.exe
29.779 [0/1/289] Running lldb lit-- Testing: 1988 tests, 2 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50..
FAIL: lldb-api :: tools/lldb-server/TestNonStop.py (1161 of 1988)
 TEST 'lldb-api :: tools/lldb-server/TestNonStop.py' FAILED 

Script:
--
C:/Users/tcwg/AppData/Local/Programs/Python/Python311-arm64/python.exe 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/llvm-project/lldb\test\API\dotest.py
 -u CXXFLAGS -u CFLAGS --env 
OBJCOPY=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/llvm-objcopy.exe
 --env LLVM_LIBS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--env 
LLVM_INCLUDE_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/include 
--env LLVM_TOOLS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--arch aarch64 --build-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-lldb\lldb-api
 --clang-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-api
 --executable 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/lldb.exe --compiler 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/clang.exe --dsymutil 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/dsymutil.exe 
--llvm-tools-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--lldb-obj-root C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb 
--lldb-libs-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--skip-category=watchpoint 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\tools\lldb-server
 -p TestNonStop.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 19.0.0git (https://github.com/llvm/llvm-project.git revision 
3fed312d2bca7d44734ace75d18890675da0f89b)
  clang revision 3fed312d2bca7d44734ace75d18890675da0f89b
  llvm revision 3fed312d2bca7d44734ace75d18890675da0f89b
Skipping the following test categories: ['watchpoint', 'libc++', 'libstdcxx', 
'dwo', 'dsym', 'gmodules', 'debugserver', 'objc', 'fork', 'pexpect']


--
Command Output (stderr):
--
lldb-server exiting...

LLVM ERROR: IO failure on output stream: bad file descriptor

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_exit_llgs (TestNonStop.LldbGdbServerTestCase.test_exit_llgs)

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_exit_query_llgs (TestNonStop.LldbGdbServerTestCase.test_exit_query_llgs) 
(skip on windows) 

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_leave_nonstop_llgs 
(TestNonStop.LldbGdbServerTestCase.test_leave_nonstop_llgs) (skip on windows) 

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_multiple_C_continue_with_signal_llgs 
(TestNonStop.LldbGdbServerTestCase.test_multiple_C_continue_with_signal_llgs

[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-13 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

I will rebase on the top of https://github.com/llvm/llvm-project/pull/97824.


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


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-07-13 Thread Kim Gräsman via cfe-commits

kimgr wrote:

@llvm-beanz Thanks! Yes, copying the headers does seem like a hack, in 
retrospect. I think I started down that path because I don't know how packaging 
works -- I had assumed I might have to bundle the headers with IWYU, but I 
guess the right procedure is to build against an installed Clang, wire the 
paths for that installation, and express a dependency in the resulting package?

So is the recommendation to:

* feed path to Clang binary in from CMake via preprocessor symbol or something 
(where do I find that on the CMake side, btw?)
* `resPath = GetResourcesPath(clangBinaryPath)`
* Add a `-resource-dir $resPath` switch as part of driver construction

?

@etcwilde Cool, that might be helpful! I don't need it on the include path, I 
need to somehow forward it into my tool so it will be able to find  
and friends at runtime. Your last example appears to get the path in a form 
where that's possible, thanks!

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


[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-13 Thread Yingwei Zheng via cfe-commits

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

>From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 21:08:27 +0800
Subject: [PATCH 01/18] [RISCV] Add support for getHostCPUFeatures using
 hwprobe

Co-authored-by: Yangyu Chen 
---
 llvm/lib/TargetParser/Host.cpp | 68 ++
 1 file changed, 68 insertions(+)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 68155acd9e5bc..b4a13b38eb380 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
 
   return true;
 }
+#elif defined(__linux__) && defined(__riscv)
+#ifdef __has_include
+#if __has_include()
+#include 
+#endif
+#endif
+bool sys::getHostCPUFeatures(StringMap &Features) {
+#ifdef RISCV_HWPROBE_KEY_MVENDORID
+  riscv_hwprobe Query[2]{
+  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
+  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
+  };
+  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
+/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  if (Ret != 0)
+return false;
+
+  uint64_t ExtMask = Query[0].value;
+  Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C;
+  Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V;
+  Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA;
+  Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB;
+  Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS;
+  Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ;
+  Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC;
+  Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB;
+  Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC;
+  Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX;
+  Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND;
+  Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE;
+  Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH;
+  Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED;
+  Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH;
+  Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT;
+  Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB;
+  Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC;
+  Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB;
+  Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG;
+  Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED;
+  Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA;
+  Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB;
+  Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED;
+  Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH;
+  Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT;
+  Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH;
+  Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN;
+  Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL;
+  Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH;
+  Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN;
+  Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA;
+  Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO;
+  Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS;
+  Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND;
+  Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE;
+
+  uint64_t MisalignedMask = Query[1].value;
+  if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) {
+Features["unaligned-scalar-mem"] = true;
+Features["unaligned-vector-mem"] = true;
+  }
+
+  return true;
+#else
+  return false;
+#endif
+}
 #else
 bool sys::getHostCPUFeatures(StringMap &Features) { return false; }
 #endif

>From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 22:10:55 +0800
Subject: [PATCH 02/18] [RISCV] Address review comments.

---
 llvm/lib/TargetParser/Host.cpp | 112 +++--
 1 file changed, 52 insertions(+), 60 deletions(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index b4a13b38eb380..ec275c0a7fded 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) 
{
   return true;
 }
 #elif defined(__linux__) && defined(__riscv)
-#ifdef __has_include
-#if __has_include()
-#include 
-#endif
-#endif
+// struct riscv_hwprobe
+struct RISCVHwProbe {
+  int64_t Key;
+  uint64_t Value;
+};
 bool sys::getHostCPUFeatures(StringMap &Features) {
-#ifdef RISCV_HWPROBE_KEY_MVENDORID
-  riscv_hwprobe Query[2]{
-  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
-  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
-  };
-  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
-/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
+  i

[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-13 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

```
dtcxzyw@bananapif3:/data/llvm-build$ bin/clang -mcpu=native 
--print-enabled-extensions
clang version 19.0.0git
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /data/llvm-build/bin
Build config: +assertions
Extensions enabled for the given RISC-V target

Name Version   Description
i2.1   'I' (Base Integer Instruction Set)
m2.0   'M' (Integer Multiplication and Division)
a2.1   'A' (Atomic Instructions)
f2.2   'F' (Single-Precision Floating-Point)
d2.2   'D' (Double-Precision Floating-Point)
c2.0   'C' (Compressed Instructions)
v1.0   'V' (Vector Extension for Application 
Processors)
zicond   1.0   'Zicond' (Integer Conditional Operations)
zicsr2.0   'zicsr' (CSRs)
zihintpause  2.0   'Zihintpause' (Pause Hint)
zmmul1.0   'Zmmul' (Integer Multiplication)
zba  1.0   'Zba' (Address Generation Instructions)
zbb  1.0   'Zbb' (Basic Bit-Manipulation)
zbc  1.0   'Zbc' (Carry-Less Multiplication)
zbs  1.0   'Zbs' (Single-Bit Instructions)
zve32f   1.0   'Zve32f' (Vector Extensions for Embedded 
Processors with maximal 32 EEW and F extension)
zve32x   1.0   'Zve32x' (Vector Extensions for Embedded 
Processors with maximal 32 EEW)
zve64d   1.0   'Zve64d' (Vector Extensions for Embedded 
Processors with maximal 64 EEW, F and D extension)
zve64f   1.0   'Zve64f' (Vector Extensions for Embedded 
Processors with maximal 64 EEW and F extension)
zve64x   1.0   'Zve64x' (Vector Extensions for Embedded 
Processors with maximal 64 EEW)
zvl128b  1.0   'Zvl' (Minimum Vector Length) 128
zvl32b   1.0   'Zvl' (Minimum Vector Length) 32
zvl64b   1.0   'Zvl' (Minimum Vector Length) 64

Experimental extensions

ISA String: 
rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicond1p0_zicsr2p0_zihintpause2p0_zmmul1p0_zba1p0_zbb1p0_zbc1p0_zbs1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0
dtcxzyw@bananapif3:/data/llvm-build$
```

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


[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-13 Thread Yingwei Zheng via cfe-commits

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

>From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 21:08:27 +0800
Subject: [PATCH 01/19] [RISCV] Add support for getHostCPUFeatures using
 hwprobe

Co-authored-by: Yangyu Chen 
---
 llvm/lib/TargetParser/Host.cpp | 68 ++
 1 file changed, 68 insertions(+)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 68155acd9e5bc..b4a13b38eb380 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
 
   return true;
 }
+#elif defined(__linux__) && defined(__riscv)
+#ifdef __has_include
+#if __has_include()
+#include 
+#endif
+#endif
+bool sys::getHostCPUFeatures(StringMap &Features) {
+#ifdef RISCV_HWPROBE_KEY_MVENDORID
+  riscv_hwprobe Query[2]{
+  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
+  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
+  };
+  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
+/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  if (Ret != 0)
+return false;
+
+  uint64_t ExtMask = Query[0].value;
+  Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C;
+  Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V;
+  Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA;
+  Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB;
+  Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS;
+  Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ;
+  Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC;
+  Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB;
+  Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC;
+  Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX;
+  Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND;
+  Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE;
+  Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH;
+  Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED;
+  Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH;
+  Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT;
+  Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB;
+  Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC;
+  Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB;
+  Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG;
+  Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED;
+  Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA;
+  Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB;
+  Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED;
+  Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH;
+  Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT;
+  Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH;
+  Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN;
+  Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL;
+  Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH;
+  Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN;
+  Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA;
+  Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO;
+  Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS;
+  Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND;
+  Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE;
+
+  uint64_t MisalignedMask = Query[1].value;
+  if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) {
+Features["unaligned-scalar-mem"] = true;
+Features["unaligned-vector-mem"] = true;
+  }
+
+  return true;
+#else
+  return false;
+#endif
+}
 #else
 bool sys::getHostCPUFeatures(StringMap &Features) { return false; }
 #endif

>From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 22:10:55 +0800
Subject: [PATCH 02/19] [RISCV] Address review comments.

---
 llvm/lib/TargetParser/Host.cpp | 112 +++--
 1 file changed, 52 insertions(+), 60 deletions(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index b4a13b38eb380..ec275c0a7fded 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) 
{
   return true;
 }
 #elif defined(__linux__) && defined(__riscv)
-#ifdef __has_include
-#if __has_include()
-#include 
-#endif
-#endif
+// struct riscv_hwprobe
+struct RISCVHwProbe {
+  int64_t Key;
+  uint64_t Value;
+};
 bool sys::getHostCPUFeatures(StringMap &Features) {
-#ifdef RISCV_HWPROBE_KEY_MVENDORID
-  riscv_hwprobe Query[2]{
-  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
-  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
-  };
-  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
-/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
+  i

[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-13 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Ping @wangpc-pp @topperc @preames 


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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits

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

Looks fine, even in this state

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits


@@ -170,3 +170,18 @@ Options
If `true` (default value) the boost headers are included as system headers
with angle brackets (`#include `), otherwise quotes are used
(`#include "boost.hpp"`).
+
+.. option:: UseReversePipe
+
+  When `true` (default `false`), fixes which involve reverse ranges will use 
the
+  pipe adaptor syntax instead of the function syntax.

PiotrZSL wrote:

Note: most of options put default value at the end of description

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits


@@ -166,6 +166,15 @@ utils::UseRangesCheck::ReplacerMap 
UseRangesCheck::getReplacerMap() const {
   return Result;
 }
 
+UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
+: utils::UseRangesCheck(Name, Context),
+  UseReversePipe(Options.get("UseReversePipe", false)) {}

PiotrZSL wrote:

this option could be moved to utils::UseRangesCheck to avoid duplications

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


[clang] [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #98160)

2024-07-13 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/98160

>From bbb0f550b72c317f02e572c2e8edf2e4df0c49bd Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 9 Jul 2024 16:08:44 +0200
Subject: [PATCH 1/9] [Clang][C++26] Implement "Ordering of constraints
 involving fold expressions"

Implement https://isocpp.org/files/papers/P2963R3.pdf
---
 clang/docs/ReleaseNotes.rst |   3 +
 clang/include/clang/Sema/Sema.h |   5 +
 clang/include/clang/Sema/SemaConcept.h  | 142 +-
 clang/lib/Sema/SemaConcept.cpp  | 602 
 clang/lib/Sema/SemaTemplateVariadic.cpp |   4 +
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 239 ++
 clang/www/cxx_status.html   |   2 +-
 7 files changed, 780 insertions(+), 217 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx2c-fold-exprs.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dc0f8b7e0bbb..a63a9d60789c5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,6 +278,9 @@ C++2c Feature Support
 
 - Implemented `P3144R2 Deleting a Pointer to an Incomplete Type Should be 
Ill-formed `_.
 
+- Implemented `P2963R3 Ordering of constraints involving fold expressions 
`_.
+
+
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6be6f6725e5b7..1113f687e69a8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14051,6 +14051,11 @@ class Sema final : public SemaBase {
   const DeclarationNameInfo &NameInfo,
   SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs within the given
+  /// expression.
+  static void collectUnexpandedParameterPacks(
+  Expr *E, SmallVectorImpl &Unexpanded);
+
   /// Invoked when parsing a template argument followed by an
   /// ellipsis, which creates a pack expansion.
   ///
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 711443505174f..b6327e729768b 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -75,6 +75,17 @@ struct AtomicConstraint {
   }
 };
 
+struct FoldExpandedConstraint;
+
+using NormalFormConstraint =
+llvm::PointerUnion;
+struct NormalizedConstraint;
+using NormalForm =
+llvm::SmallVector, 4>;
+
+NormalForm makeCNF(const NormalizedConstraint &Normalized);
+NormalForm makeDNF(const NormalizedConstraint &Normalized);
+
 /// \brief A normalized constraint, as defined in C++ [temp.constr.normal], is
 /// either an atomic constraint, a conjunction of normalized constraints or a
 /// disjunction of normalized constraints.
@@ -87,26 +98,17 @@ struct NormalizedConstraint {
   std::pair *, 1,
   CompoundConstraintKind>;
 
-  llvm::PointerUnion Constraint;
+  llvm::PointerUnion
+  Constraint;
 
   NormalizedConstraint(AtomicConstraint *C): Constraint{C} { };
+  NormalizedConstraint(FoldExpandedConstraint *C) : Constraint{C} {};
+
   NormalizedConstraint(ASTContext &C, NormalizedConstraint LHS,
-   NormalizedConstraint RHS, CompoundConstraintKind Kind)
-  : Constraint{CompoundConstraint{
-new (C) std::pair{
-std::move(LHS), std::move(RHS)}, Kind}} { };
-
-  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other) {
-if (Other.isAtomic()) {
-  Constraint = new (C) AtomicConstraint(*Other.getAtomicConstraint());
-} else {
-  Constraint = CompoundConstraint(
-  new (C) std::pair{
-  NormalizedConstraint(C, Other.getLHS()),
-  NormalizedConstraint(C, Other.getRHS())},
-  Other.getCompoundKind());
-}
-  }
+   NormalizedConstraint RHS, CompoundConstraintKind Kind);
+
+  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other);
   NormalizedConstraint(NormalizedConstraint &&Other):
   Constraint(Other.Constraint) {
 Other.Constraint = nullptr;
@@ -126,6 +128,9 @@ struct NormalizedConstraint {
   }
 
   bool isAtomic() const { return Constraint.is(); }
+  bool isFoldExpanded() const {
+return Constraint.is();
+  }
 
   NormalizedConstraint &getLHS() const {
 assert(!isAtomic() && "getLHS called on atomic constraint.");
@@ -143,6 +148,12 @@ struct NormalizedConstraint {
 return Constraint.get();
   }
 
+  FoldExpandedConstraint *getFoldExpandedConstraint() const {
+assert(isFoldExpanded() &&
+   "getFoldExpandedConstraint called on non-fold-expanded 
constraint.");
+return Constraint.get();
+  }
+
 private:
   static std::optional
   fromConstraintExprs(Sema &S, NamedDecl *D, ArrayRef E);
@@ -150,6 +161,103 @@ struct NormalizedConstraint {
   fromConstraintExpr(Sema &S, NamedDecl *D, cons

[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From a3b7eaf5792be1d4bb9dc2e727b571595b99a612 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  3 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 38 --
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 ++--
 llvm/lib/Support/Unix/Path.inc| 40 +--
 llvm/lib/Support/Unix/Process.inc | 15 ++-
 llvm/lib/Support/Unix/Program.inc | 16 +++-
 llvm/lib/Support/Unix/Unix.h  |  5 ++-
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 16 files changed, 143 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..3b785c8288cb0 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,9 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 
b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..1d933ab710974 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -34,7 +34,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#if !defined(__wasi__)
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -340,7 +342,11 @@ static GenericValue lle_X_exit(FunctionType *FT, 
ArrayRef Args) {
 static GenericValue lle_X_abort(Func

[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-13 Thread via cfe-commits

guijiyang wrote:

> > > @sam-mccall gentle ping~
> > 
> > 
> > @ChuanqiXu9 hi, can your patch add support msvc module with *.ixx suffix 
> > source? I use xmake to generate compile database, clangd cant work properly.
> 
> hi, did you meet problems when testing this? I took a quick look and I don't 
> see I treated suffix specially. This patch find module interface unit by 
> scanning instead of by suffixes.

hi, clangd got error 
`
I[17:59:54.146] Scanning modules dependencies for C:\Program Files\Microsoft 
Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\modules\std.ixx 
failed: error: no such file or directory: '/ifcOutput'
error: no such file or directory: '/interface'
error: cannot specify 
'/Fobuild\.objs\test\windows\x64\debug\0aee06d009cc4e4b8a8427a06257c7f1\std.ixx.obj'
 when compiling multiple source files
`
'/ifcOutput' and  '/interface' are flags to msvc cl,why clangd ocurr this error,
and compile_commands.json like this:
`
{
  "directory": "d:\\Code\\MyProject\\guis",
  "arguments": ["C:\\Program Files\\Microsoft Visual 
Studio\\2022\\Professional\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX64\\x64\\cl.exe",
 "/c", "/nologo", "/Zi", "/FS", 
"/Fdbuild\\windows\\x64\\debug\\compile.test.pdb", "/W3", "/WX", "/Od", 
"/std:c++latest", "/MDd", "/EHsc", "/TP", "/ifcOutput", 
"build\\.gens\\test\\windows\\x64\\debug\\rules\\bmi\\cache\\modules\\1382cb37\\std.ifc",
 "/interface", 
"/Fobuild\\.objs\\test\\windows\\x64\\debug\\0aee06d009cc4e4b8a8427a06257c7f1\\std.ixx.obj",
 "C:\\Program Files\\Microsoft Visual 
Studio\\2022\\Professional\\VC\\Tools\\MSVC\\14.39.33519\\modules\\std.ixx", 
"-imsvc", "C:\\Program Files (x86)\\Windows 
Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files 
(x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program 
Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", 
"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", 
"-imsvc", "C:\\Program Files (x86)\\Windows 
Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program 
Files\\Microsoft Visual 
Studio\\2022\\Professional\\VC\\Tools\\MSVC\\14.39.33519\\include"],
  "file": "C:\\Program Files\\Microsoft Visual 
Studio\\2022\\Professional\\VC\\Tools\\MSVC\\14.39.33519\\modules\\std.ixx"
}
`

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-13 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/98736

This patch implements consensus on the corresponding RFC documented here: 
https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/72
Specifically, I added a deprecation warning for `-Ofast`, that suggests to use 
`-O3` or `-O3` with `-ffast-math`, and a new diagnostic group for 
aforementioned warning.

>From 44b4a682f2b3d7e140f7b1bd124e7aabdbf439ad Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 13 Jul 2024 13:10:25 +0300
Subject: [PATCH] [clang] Add deprecation warning for `-Ofast` driver option

---
 clang/docs/ReleaseNotes.rst| 3 +++
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 +++
 clang/include/clang/Basic/DiagnosticGroups.td  | 2 ++
 clang/include/clang/Driver/Options.td  | 3 ++-
 clang/lib/Driver/ToolChains/Clang.cpp  | 2 ++
 clang/test/Driver/Ofast.c  | 4 
 6 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ceead8c362e9c..2f5f40f355901 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -470,6 +470,9 @@ New Compiler Flags
 Deprecated Compiler Flags
 -
 
+- ``-Ofast`` is deprecated in favor of ``-O3``, possibly combined with 
``-ffast-math``.
+  See `RFC `_ for 
details.
+
 Modified Compiler Flags
 ---
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 359c0de7f811c..3857f2f3a33ce 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..d7dba76a0fcf8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -103,6 +103,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
 EnumFloatConversion,
 EnumCompareConditional]>;
 def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
+def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedPragma,
   DeprecatedRegister,
   
DeprecatedNoRelaxedTemplateTemplateArgs,
+  DeprecatedOFast,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1e8cb87e5321..269790476c1c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -931,7 +931,8 @@ def O : Joined<["-"], "O">, Group,
 def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
-  Visibility<[ClangOption, CC1Option, FlangOption]>;
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
+  HelpText<"Deprecated; use -O3, possibly with -ffast-math">;
 def P : Flag<["-"], "P">,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   Group,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bc21d03a627b9..33e7152343171 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5712,6 +5712,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  options::OPT_fno_zero_initialized_in_bss);
 
   bool OFastEnabled = isOptimizationLevelFast(Args);
+  if (OFastEnabled)
+D.Diag(diag::warn_drv_deprecated_arg_ofast);
   // If -Ofast is the optimization level, then -fstrict-aliasing should be
   // enabled.  This alias option is being used

[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Vlad Serebrennikov (Endilll)


Changes

This patch implements consensus on the corresponding RFC documented here: 
https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/72
Specifically, I added a deprecation warning for `-Ofast`, that suggests to use 
`-O3` or `-O3` with `-ffast-math`, and a new diagnostic group for 
aforementioned warning.

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2) 
- (modified) clang/include/clang/Driver/Options.td (+2-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2) 
- (modified) clang/test/Driver/Ofast.c (+4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ceead8c362e9c..2f5f40f355901 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -470,6 +470,9 @@ New Compiler Flags
 Deprecated Compiler Flags
 -
 
+- ``-Ofast`` is deprecated in favor of ``-O3``, possibly combined with 
``-ffast-math``.
+  See `RFC `_ for 
details.
+
 Modified Compiler Flags
 ---
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 359c0de7f811c..3857f2f3a33ce 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..d7dba76a0fcf8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -103,6 +103,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
 EnumFloatConversion,
 EnumCompareConditional]>;
 def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
+def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedPragma,
   DeprecatedRegister,
   
DeprecatedNoRelaxedTemplateTemplateArgs,
+  DeprecatedOFast,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1e8cb87e5321..269790476c1c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -931,7 +931,8 @@ def O : Joined<["-"], "O">, Group,
 def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
-  Visibility<[ClangOption, CC1Option, FlangOption]>;
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
+  HelpText<"Deprecated; use -O3, possibly with -ffast-math">;
 def P : Flag<["-"], "P">,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   Group,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bc21d03a627b9..33e7152343171 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5712,6 +5712,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  options::OPT_fno_zero_initialized_in_bss);
 
   bool OFastEnabled = isOptimizationLevelFast(Args);
+  if (OFastEnabled)
+D.Diag(diag::warn_drv_deprecated_arg_ofast);
   // If -Ofast is the optimization level, then -fstrict-aliasing should be
   // enabled.  This alias option is being used to simplify the hasFlag logic.
   OptSpecifier StrictAliasingAliasOption =
diff --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c
index 8b7f2217eca2

[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-13 Thread Vlad Serebrennikov via cfe-commits

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Danny Mösch via cfe-commits

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


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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From 66199b7e958866982a909086979ed09f5932a0d4 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  3 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 38 --
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 ++--
 llvm/lib/Support/Unix/Path.inc| 40 +--
 llvm/lib/Support/Unix/Process.inc | 15 ++-
 llvm/lib/Support/Unix/Program.inc | 16 +++-
 llvm/lib/Support/Unix/Unix.h  |  5 ++-
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 16 files changed, 143 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..3b785c8288cb0 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,9 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 
b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..1d933ab710974 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -34,7 +34,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#if !defined(__wasi__)
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -340,7 +342,11 @@ static GenericValue lle_X_exit(FunctionType *FT, 
ArrayRef Args) {
 static GenericValue lle_X_abort(Func

[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-13 Thread Vlad Serebrennikov via cfe-commits


@@ -7416,10 +7416,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
 /*DiagID=*/0);
 
-  if (const AutoType *AutoT = R->getAs())
-CheckConstrainedAuto(
-AutoT,
-TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
+  if (const AutoType *AutoT = R->getAs()) {
+AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();

Endilll wrote:

Thank you for the analysis!

> The correct fix would be to make that decltype have some error type, for 
> error recovery purposes.

Can you point me out to the place in our source where this change should be 
made?

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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From 0f15e9b436b025cd4e6177f9b974c77d549719e0 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  3 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 38 +--
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 +--
 llvm/lib/Support/Unix/Path.inc| 47 ---
 llvm/lib/Support/Unix/Process.inc | 16 ++-
 llvm/lib/Support/Unix/Program.inc | 16 ++-
 llvm/lib/Support/Unix/Unix.h  |  3 ++
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 16 files changed, 147 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..3b785c8288cb0 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,9 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 
b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..1d933ab710974 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -34,7 +34,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#if !defined(__wasi__)
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -340,7 +342,11 @@ static GenericValue lle_X_exit(FunctionType *FT, 
ArrayRef Args) {
 static GenericValue lle_X_abort(FunctionTy

[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Nathan James via cfe-commits


@@ -166,6 +166,15 @@ utils::UseRangesCheck::ReplacerMap 
UseRangesCheck::getReplacerMap() const {
   return Result;
 }
 
+UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
+: utils::UseRangesCheck(Name, Context),
+  UseReversePipe(Options.get("UseReversePipe", false)) {}

njames93 wrote:

The issue with that is a downstream user who wants to implement this check for 
their library may not be able to support the alternative syntax.
The other way to get this behaviour would be a runtime parameter on the base 
class constructor to enable/disable the option. But that didn't sit right with 
me.

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Nathan James via cfe-commits

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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

whitequark wrote:

I've updated the PR to use almost exclusively 
`defined(__wasi__)`/`defined(__wasm__)`, with the exception of `HAVE_SETJMP`, 
where you could conceivably have both kinds of builds on WebAssembly depending 
on your needs.

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Hana Dusíková (hanickadot)


Changes

This implements P3309 `constexpr std::atomic & std::atomic_ref` (currently 
in LWG) by allowing constant evaluation of clang's `__c11_atomic_OP` and GCC's 
`__atomic_OP` builtins. 

Implementation in library is then simple, just marking everything constexpr, in 
`atomic_ref` is used `if consteval` code forking to avoid `reinterpret_cast` 
which is there to avoid missing capability of GCC's atomic builtins which 
doesn't support operations on floats.

---

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


7 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+42-42) 
- (modified) clang/lib/AST/ExprConstant.cpp (+412) 
- (modified) libcxx/include/__atomic/atomic.h (+49-40) 
- (modified) libcxx/include/__atomic/atomic_base.h (+46-30) 
- (modified) libcxx/include/__atomic/atomic_flag.h (+35-21) 
- (modified) libcxx/include/__atomic/atomic_ref.h (+260-116) 
- (modified) libcxx/include/__atomic/cxx_atomic_impl.h (+43-36) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Conste

[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 


github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 3b7a7f4cc43f90e79292700959c55a62ab87fd9a 
957d0cdae5ea2258f8d1671edb2c70632b7bf26d --extensions h,cpp -- 
clang/lib/AST/ExprConstant.cpp libcxx/include/__atomic/atomic.h 
libcxx/include/__atomic/atomic_base.h libcxx/include/__atomic/atomic_flag.h 
libcxx/include/__atomic/atomic_ref.h libcxx/include/__atomic/cxx_atomic_impl.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 2cb7de0ed7..e484c747d3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7940,7 +7940,7 @@ public:
 AtomicLV, AtomicVal)) {
   return false;
 }
-
+
 if (!StoreToResultAfter) {
   Result = AtomicVal;
 }
@@ -8010,7 +8010,8 @@ public:
   APFloat::opStatus St;
 
   switch (E->getOp()) {
-  case AtomicExpr::AO__c11_atomic_fetch_add: // GCC atomics doesn't 
support floats
+  case AtomicExpr::AO__c11_atomic_fetch_add: // GCC atomics doesn't support
+ // floats
 St = AtomicFlt.add(ArgumentFlt, RM);
 Replacement = APValue(AtomicFlt);
 break;
@@ -8058,7 +8059,7 @@ public:
   // not float,int,pointer?
   return false;
 }
-
+
 if (StoreToResultAfter) {
   Result = Replacement;
 }

``




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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Nikolas Klauser via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 


philnik777 wrote:

Could you split this up into separate patches for the Clang and libc++ changes? 
The Clang changes can probably be landed independently of LWG, but for the 
libc++ changes we almost always wait until plenary approval (I'd be happy to 
give early feedback though).

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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From 1112971dae09486a5f04db5018fc471a776b4060 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  4 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 39 +--
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 +--
 llvm/lib/Support/Unix/Memory.inc  |  5 ++
 llvm/lib/Support/Unix/Path.inc| 47 ---
 llvm/lib/Support/Unix/Process.inc | 16 ++-
 llvm/lib/Support/Unix/Program.inc | 16 ++-
 llvm/lib/Support/Unix/Unix.h  |  3 ++
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 17 files changed, 154 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..21a8f31e34a93 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,10 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+/* This function is expected to be present everywhere except for a subset of 
WebAssembly builds. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 
b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..1d933ab710974 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -34,7 +34,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#if !defined(__wasi__)
 #include 
+#endif
 #incl

[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/98738

From 63cefb0634ece515cbc1939c56d4fa2f0ef1eccf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jul 2024 13:12:24 +0200
Subject: [PATCH] [clang] [libc++] atomic constexpr support

---
 clang/include/clang/Basic/Builtins.td |  84 ++---
 clang/lib/AST/ExprConstant.cpp| 413 ++
 libcxx/include/__atomic/atomic.h  |  89 ++---
 libcxx/include/__atomic/atomic_base.h |  76 ++--
 libcxx/include/__atomic/atomic_flag.h |  56 +--
 libcxx/include/__atomic/atomic_ref.h  | 380 ++--
 libcxx/include/__atomic/cxx_atomic_impl.h |  79 +++--
 7 files changed, 896 insertions(+), 281 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def AtomicLoadN : AtomicBuiltin {
   let Spellings = ["__atomic_load_n"];
-  let Attributes = [CustomT

[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

hanickadot wrote:

@philnik777 I would rather not, at least for the review, manipulating two 
branches will be cumbersome. I can split it before merging, but as I don't 
expect this to happen soon, it should be fine.

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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From b64ed264311f0b0847988f141b0e2320ee9942b3 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  4 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 40 ++--
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 +--
 llvm/lib/Support/Unix/Memory.inc  |  5 ++
 llvm/lib/Support/Unix/Path.inc| 47 ---
 llvm/lib/Support/Unix/Process.inc | 16 ++-
 llvm/lib/Support/Unix/Program.inc | 16 ++-
 llvm/lib/Support/Unix/Unix.h  |  3 ++
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 17 files changed, 155 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..21a8f31e34a93 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,10 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+/* This function is expected to be present everywhere except for a subset of 
WebAssembly builds. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 
b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..1d933ab710974 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -34,7 +34,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#if !defined(__wasi__)
 #include 
+#endif
 #inc

[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> @philnik777 I would rather not, at least for the review, manipulating two 
> branches will be cumbersome. I can split it before merging, but as I don't 
> expect this to happen soon, it should be fine.

This is less about having two separate commits than having mostly unrelated 
changes in separate PRs. It's "the llvm project", but it's really not a single 
project. The people reviewing the clang part don't know what to look for in 
libc++ and vice versa. You can use tools like 
https://github.com/spacedentist/spr to make it easier to manage a stacked PR if 
you want.

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


[clang] [C2y] Claim partial conformance to WG14 N3244 (PR #98525)

2024-07-13 Thread Michał Górny via cfe-commits

mgorny wrote:

The added test fails on 32-bit x86:

```
FAIL: Clang :: C/C2y/n3244.c (1461 of 20066)
 TEST 'Clang :: C/C2y/n3244.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/19/include
 -nostdsysteminc -std=c2y 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c
 -verify -Wno-gnu-alignof-expression
+ 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/19/include
 -nostdsysteminc -std=c2y 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c
 -verify -Wno-gnu-alignof-expression
error: 'expected-error' diagnostics seen but not expected: 
  File 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c
 Line 59: static assertion failed due to requirement '_Alignof 
(CompatibleAlignment) == _Alignof(long long)': 
error: 'expected-note' diagnostics seen but not expected: 
  File 
/var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c
 Line 59: expression evaluates to '8 == 4'
2 errors generated.

--


```

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/98738

From 83645b161f62bbff2baf5a90eef2c6cd1b280180 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jul 2024 13:12:24 +0200
Subject: [PATCH] [clang] [libc++] atomic constexpr support

---
 clang/include/clang/Basic/Builtins.td |  84 ++--
 clang/lib/AST/ExprConstant.cpp| 446 +-
 libcxx/include/__atomic/atomic.h  |  89 +++--
 libcxx/include/__atomic/atomic_base.h |  76 ++--
 libcxx/include/__atomic/atomic_flag.h |  56 ++-
 libcxx/include/__atomic/atomic_ref.h  | 324 +++-
 libcxx/include/__atomic/cxx_atomic_impl.h |  77 ++--
 7 files changed, 873 insertions(+), 279 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def AtomicLoadN : AtomicBuiltin {
   let Spellings = ["__atomic_load_n"];
-  let Attributes = [CustomTypeChe

[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/98738

From c691efa7649c990814bb363511106457e306aefa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jul 2024 14:28:07 +0200
Subject: [PATCH] [clang] [libc++] atomic constexpr support

---
 clang/include/clang/Basic/Builtins.td |  84 ++--
 clang/lib/AST/ExprConstant.cpp| 449 +-
 libcxx/include/__atomic/atomic.h  |  89 +++--
 libcxx/include/__atomic/atomic_base.h |  76 ++--
 libcxx/include/__atomic/atomic_flag.h |  56 ++-
 libcxx/include/__atomic/atomic_ref.h  | 314 ++-
 libcxx/include/__atomic/cxx_atomic_impl.h |  77 ++--
 7 files changed, 871 insertions(+), 274 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def AtomicLoadN : AtomicBuiltin {
   let Spellings = ["__atomic_load_n"];
-  let Attributes = [CustomTypeChec

[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-07-13 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

LGTM!

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

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

This fixes a few of the more debatable type errors, and adds related 
annotations, as the next step towards #76664.

>From 06483bd3e398dd9dba757904e622d5dd1b37db77 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 13 Jul 2024 14:12:34 +0100
Subject: [PATCH] [libclang/python] Fix some type errors, add type annotations

---
 clang/bindings/python/clang/cindex.py | 137 +++---
 .../tests/cindex/test_code_completion.py  |  22 +--
 .../python/tests/cindex/test_comment.py   |   4 +-
 3 files changed, 100 insertions(+), 63 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 1d3ab89190407..469d602b2a642 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -43,7 +43,7 @@
 Most object information is exposed using properties, when the underlying API
 call is efficient.
 """
-from __future__ import absolute_import, division, print_function
+from __future__ import annotations
 
 # TODO
 # 
@@ -66,46 +66,77 @@
 
 import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int: ...
+def __getitem__(self, key: int) -> TSeq: ...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""
 
 @property
-def value(self):
-if super(c_char_p, self).value is None:
+def value(self) -> str | None:  # type: ignore [override]
+val = super(c_char_p, self).value
+if val is None:
 return None
-return super(c_char_p, self).value.decode("utf8")
+return val.decode("utf8")
 
 @classmethod
-def from_param(cls, param):
+def from_param(cls, param: str | bytes | None) -> c_interop_string:
 if isinstance(param, str):
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
 if param is None:
 # Support passing null to C functions expecting char arrays
-return None
+return cls(param)
 raise TypeError(
 "Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
 )
 
 @staticmethod
-def to_python_string(x, *args):
+def to_python_string(x: c_interop_string, *args: Any) -> str | None:
 return x.value
 
 
-def b(x):
+def b(x: str | bytes) -> bytes:
 if isinstance(x, bytes):
 return x
 return x.encode("utf8")
@@ -115,9 +146,7 @@ def b(x):
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p = POINTER(c_void_p)
-
-callbacks = {}
+c_object_p: TType[CObjP] = POINTER(c_void_p)
 
 ### Exception Classes ###
 
@@ -169,8 +198,11 @@ def __init__(self, enumeration, message):
 
 ### Structures and Utility Classes ###
 
+TInstance = TypeVar("TInstance")
+TResult = TypeVar("TResult")
+
 
-class CachedProperty:
+class CachedProperty(Generic[TInstance, TResult]):
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
@@ -178,16 +210,20 @@ class CachedProperty:
 property, replacing the original method.
 """
 
-def __init__(self, wrapped):
+def __init__(self, wrapped: Callable[[TInstance], TResult]):
 self.wrapped = wrapped
 try:
 self.__doc__ = wrapped.__doc__
 except:
 pass
 
-def __get__(self, instance, instance_type=None):
+def __get__(self, instance: TInstance, instance_type: Any = None) -> 
TResult:
 if instance is None:
-return self
+property_name = self.wrapped.__name__
+class_name = instance_type.__name__
+raise Type

[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

This fixes a few of the more debatable type errors, and adds related 
annotations, as the next step towards #76664.

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


3 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+87-50) 
- (modified) clang/bindings/python/tests/cindex/test_code_completion.py 
(+11-11) 
- (modified) clang/bindings/python/tests/cindex/test_comment.py (+2-2) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 1d3ab89190407..469d602b2a642 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -43,7 +43,7 @@
 Most object information is exposed using properties, when the underlying API
 call is efficient.
 """
-from __future__ import absolute_import, division, print_function
+from __future__ import annotations
 
 # TODO
 # 
@@ -66,46 +66,77 @@
 
 import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int: ...
+def __getitem__(self, key: int) -> TSeq: ...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""
 
 @property
-def value(self):
-if super(c_char_p, self).value is None:
+def value(self) -> str | None:  # type: ignore [override]
+val = super(c_char_p, self).value
+if val is None:
 return None
-return super(c_char_p, self).value.decode("utf8")
+return val.decode("utf8")
 
 @classmethod
-def from_param(cls, param):
+def from_param(cls, param: str | bytes | None) -> c_interop_string:
 if isinstance(param, str):
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
 if param is None:
 # Support passing null to C functions expecting char arrays
-return None
+return cls(param)
 raise TypeError(
 "Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
 )
 
 @staticmethod
-def to_python_string(x, *args):
+def to_python_string(x: c_interop_string, *args: Any) -> str | None:
 return x.value
 
 
-def b(x):
+def b(x: str | bytes) -> bytes:
 if isinstance(x, bytes):
 return x
 return x.encode("utf8")
@@ -115,9 +146,7 @@ def b(x):
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p = POINTER(c_void_p)
-
-callbacks = {}
+c_object_p: TType[CObjP] = POINTER(c_void_p)
 
 ### Exception Classes ###
 
@@ -169,8 +198,11 @@ def __init__(self, enumeration, message):
 
 ### Structures and Utility Classes ###
 
+TInstance = TypeVar("TInstance")
+TResult = TypeVar("TResult")
+
 
-class CachedProperty:
+class CachedProperty(Generic[TInstance, TResult]):
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
@@ -178,16 +210,20 @@ class CachedProperty:
 property, replacing the original method.
 """
 
-def __init__(self, wrapped):
+def __init__(self, wrapped: Callable[[TInstance], TResult]):
 self.wrapped = wrapped
 try:
 self.__doc__ = wrapped.__doc__
 except:
 pass
 
-def __get__(self, instance, instance_type=None):
+def __get__(self, instance: TInstance, instance_type: Any = None) -> 
TResult:
 if instance is None:
-return self
+property_name = self.wrapped.__name__
+class_name = instance_type.__name__
+raise TypeError(
+f"'{property_name}' is not a static attribute of 
'{class_name}'"
+)
 
 value = se

[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -43,7 +43,7 @@
 Most object information is exposed using properties, when the underlying API
 call is efficient.
 """
-from __future__ import absolute_import, division, print_function

DeinAlptraum wrote:

All of these are already activated by default since Python 3.0. `annotations` 
is necessary though, for some of the type annotation features used in this PR

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
1bad7024561bc64ed4bfda0772b16376b475eba5...06483bd3e398dd9dba757904e622d5dd1b37db77
 clang/bindings/python/clang/cindex.py 
clang/bindings/python/tests/cindex/test_code_completion.py 
clang/bindings/python/tests/cindex/test_comment.py
``





View the diff from darker here.


``diff
--- clang/cindex.py 2024-07-13 13:12:34.00 +
+++ clang/cindex.py 2024-07-13 13:21:02.416533 +
@@ -93,12 +93,15 @@
 CObjP: TypeAlias = _Pointer[Any]
 
 TSeq = TypeVar("TSeq", covariant=True)
 
 class NoSliceSequence(Protocol[TSeq]):
-def __len__(self) -> int: ...
-def __getitem__(self, key: int) -> TSeq: ...
+def __len__(self) -> int:
+...
+
+def __getitem__(self, key: int) -> TSeq:
+...
 
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
 def __init__(self, p: str | bytes | None = None):

``




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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

whitequark wrote:

Failed test is:
```

 TEST 'LLVM-Unit :: Support/./SupportTests.exe/41/43' 
FAILED 
Script(shard):
--
GTEST_OUTPUT=json:C:\ws\src\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-43852-41-43.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=43 GTEST_SHARD_INDEX=41 
C:\ws\src\build\unittests\Support\.\SupportTests.exe
--
Script:
--
C:\ws\src\build\unittests\Support\.\SupportTests.exe 
--gtest_filter=LockFileManagerTest.Basic
--
C:\ws\src\llvm\unittests\Support\LockFileManagerTest.cpp(35): error: Expected: 
(LockFileManager::LFS_Owned) != (Locked2.getState()), actual: 0 vs 0
C:\ws\src\llvm\unittests\Support\LockFileManagerTest.cpp:35
Expected: (LockFileManager::LFS_Owned) != (Locked2.getState()), actual: 0 vs 0

```

This doesn't seem to make any sense since expected == actual here?

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


[clang] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-13 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From 826c21d6070bbb629edc525340f10c2ad068f4b8 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  4 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 40 ++--
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 +--
 llvm/lib/Support/Unix/Memory.inc  |  5 ++
 llvm/lib/Support/Unix/Path.inc| 47 ---
 llvm/lib/Support/Unix/Process.inc | 16 ++-
 llvm/lib/Support/Unix/Program.inc | 16 ++-
 llvm/lib/Support/Unix/Unix.h  |  3 ++
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 17 files changed, 155 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..21a8f31e34a93 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,10 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+/* This function is expected to be present everywhere except for a subset of 
WebAssembly builds. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 
b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..1d933ab710974 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -34,7 +34,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#if !defined(__wasi__)
 #include 
+#endif
 #inc

[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -66,46 +66,77 @@
 
 import collections.abc
 import os
+import sys

DeinAlptraum wrote:

This is used for `sys.stdout.flush()` in this file, and leads to a type error. 
I don't know why this isn't already imported

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -200,13 +236,16 @@ class _CXString(Structure):
 
 _fields_ = [("spelling", c_char_p), ("free", c_int)]
 
-def __del__(self):
+def __del__(self) -> None:
 conf.lib.clang_disposeString(self)
 
 @staticmethod
-def from_result(res, fn=None, args=None):
+def from_result(res: _CXString, fn: Any = None, args: Any = None) -> str:
 assert isinstance(res, _CXString)
-return conf.lib.clang_getCString(res)
+pystr: str | None = conf.lib.clang_getCString(res)
+if pystr is None:
+return ""
+return pystr

DeinAlptraum wrote:

`conf.lib.clang_getCString` may sometimes (though seemingly rarely) return 
`None` instead of a Python `str`. `_CXString.from_result()` is used in a lot of 
places throughout this file, and while parts of it seem to be aware of this 
(e.g. doc string saying that this may return `None`) other places are not (e.g. 
calling `len` on the return value). Many parts of the interface also directly 
return the result of this function, and having to check for `None` in all of 
these places seems potentially impractical, so I went for returning empty 
strings instead of `None` instead.

But due to the inconsistent usage throughout this file, I'm not sure how far 
this corresponds more or less to the original intention.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -115,9 +146,7 @@ def b(x):
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p = POINTER(c_void_p)
-
-callbacks = {}

DeinAlptraum wrote:

`callbacks` could have been a `TypedDict`, but these are always a mouthful and 
I don't see a reason to have this dict in the first place, so I removed it.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -66,46 +66,77 @@
 
 import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int: ...
+def __getitem__(self, key: int) -> TSeq: ...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""
 
 @property
-def value(self):
-if super(c_char_p, self).value is None:
+def value(self) -> str | None:  # type: ignore [override]
+val = super(c_char_p, self).value
+if val is None:
 return None
-return super(c_char_p, self).value.decode("utf8")
+return val.decode("utf8")

DeinAlptraum wrote:

This violates the superclass' interface, but I highly doubt that we actually 
want to return `bytes` here as the superclass mandates, so I had to `type: 
ignore` this.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -66,46 +66,77 @@
 
 import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int: ...
+def __getitem__(self, key: int) -> TSeq: ...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""

DeinAlptraum wrote:

This violated the `__str__` magic method definition, as it is not allowed to 
return `None`. I guess this is also worth a "potentially breaking change"?

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -3895,28 +3932,28 @@ def register_function(lib, item, ignore_errors):
 func.errcheck = item[3]
 
 
-def register_functions(lib, ignore_errors):
+def register_functions(lib: CDLL, ignore_errors: bool) -> None:
 """Register function prototypes with a libclang library instance.
 
 This must be called as part of library instantiation so Python knows how
 to call out to the shared library.
 """
 
-def register(item):
-return register_function(lib, item, ignore_errors)
+def register(item: LibFunc) -> None:
+register_function(lib, item, ignore_errors)

DeinAlptraum wrote:

`return` removed since `register_function()` doesn't return anything anyway.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -169,25 +198,32 @@ def __init__(self, enumeration, message):
 
 ### Structures and Utility Classes ###
 
+TInstance = TypeVar("TInstance")
+TResult = TypeVar("TResult")
+
 
-class CachedProperty:
+class CachedProperty(Generic[TInstance, TResult]):
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
 executed. The value it returns is set as the new value of that instance's
 property, replacing the original method.
 """
 
-def __init__(self, wrapped):
+def __init__(self, wrapped: Callable[[TInstance], TResult]):
 self.wrapped = wrapped
 try:
 self.__doc__ = wrapped.__doc__
 except:
 pass
 
-def __get__(self, instance, instance_type=None):
+def __get__(self, instance: TInstance, instance_type: Any = None) -> 
TResult:
 if instance is None:
-return self
+property_name = self.wrapped.__name__
+class_name = instance_type.__name__
+raise TypeError(
+f"'{property_name}' is not a static attribute of 
'{class_name}'"
+)

DeinAlptraum wrote:

`CachedProperty` is a decorator used as a replacement for `@property` where the 
actual function might include heavier computations, so after the first call 
this caches the result of a decorated function as an attribute of the instance 
it belongs to.

The `if instance is None` case occurs only when trying to call this statically, 
i.e. when the decorated function is called on the class it belongs to, instead 
of on an instance. In that case the existing implementation returns the 
`CachedProperty` object, which... doesn't seem to make any sense. That object 
itself is useless, it is an implementation detail that the user is not supposed 
to see, so I can't think of a reason why this would return `self`. This would 
also make the type annotation more complicated, so I changed this to throw an 
error instead, when trying to access a property as if it were a static attribute

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


[clang] b22adf0 - [clang][Interp] Clear pointers pointing to dead blocks

2024-07-13 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-13T15:55:55+02:00
New Revision: b22adf02a2d2cc290d618fe47bec5aeec47ab992

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

LOG: [clang][Interp] Clear pointers pointing to dead blocks

before free()ing the dead blocks. Otherwise, we might end up with
dangling Pointers to those dead blocks.

Added: 


Modified: 
clang/lib/AST/Interp/InterpState.cpp
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/lifetimes.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpState.cpp 
b/clang/lib/AST/Interp/InterpState.cpp
index 550bc9f1a84b..a8538541f491 100644
--- a/clang/lib/AST/Interp/InterpState.cpp
+++ b/clang/lib/AST/Interp/InterpState.cpp
@@ -33,7 +33,15 @@ InterpState::~InterpState() {
   }
 }
 
-void InterpState::cleanup() {}
+void InterpState::cleanup() {
+  // As a last resort, make sure all pointers still pointing to a dead block
+  // don't point to it anymore.
+  for (DeadBlock *DB = DeadBlocks; DB; DB = DB->Next) {
+for (Pointer *P = DB->B.Pointers; P; P = P->Next) {
+  P->PointeeStorage.BS.Pointee = nullptr;
+}
+  }
+}
 
 Frame *InterpState::getCurrentFrame() {
   if (Current && Current->Caller)

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 3515f525a22f..6e9e8675306e 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -635,6 +635,7 @@ class Pointer {
   friend class Block;
   friend class DeadBlock;
   friend class MemberPointer;
+  friend class InterpState;
   friend struct InitMap;
 
   Pointer(Block *Pointee, unsigned Base, uint64_t Offset);

diff  --git a/clang/test/AST/Interp/lifetimes.cpp 
b/clang/test/AST/Interp/lifetimes.cpp
index c544baba6178..d47533ab547b 100644
--- a/clang/test/AST/Interp/lifetimes.cpp
+++ b/clang/test/AST/Interp/lifetimes.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=expected,both %s
 // RUN: %clang_cc1 -verify=ref,both %s
 
+/// FIXME: Slight 
diff erence in diagnostic output here.
+
 struct Foo {
   int a;
 };
@@ -20,3 +22,14 @@ static_assert(dead1() == 1, ""); // both-error {{not an 
integral constant expres
  // both-note {{in call to}}
 
 
+struct S {
+  int &&r; // both-note {{reference member declared here}}
+  int t;
+  constexpr S() : r(0), t(r) {} // both-error {{reference member 'r' binds to 
a temporary object whose lifetime would be shorter than the lifetime of the 
constructed object}} \
+// ref-note {{read of object outside its 
lifetime is not allowed in a constant expression}} \
+// expected-note {{temporary created here}} \
+// expected-note {{read of temporary whose 
lifetime has ended}}
+};
+constexpr int k1 = S().t; // both-error {{must be initialized by a constant 
expression}} \
+  // ref-note {{in call to}} \
+  // expected-note {{in call to}}



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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum updated 
https://github.com/llvm/llvm-project/pull/98745

>From 2c31f3fe5d232381b868e96158be6f2acf7da1c6 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 13 Jul 2024 14:12:34 +0100
Subject: [PATCH] [libclang/python] Fix some type errors, add type annotations

---
 clang/bindings/python/clang/cindex.py | 192 +++---
 .../tests/cindex/test_code_completion.py  |  22 +-
 .../python/tests/cindex/test_comment.py   |   4 +-
 3 files changed, 127 insertions(+), 91 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 1d3ab89190407..9b50192068213 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -43,7 +43,7 @@
 Most object information is exposed using properties, when the underlying API
 call is efficient.
 """
-from __future__ import absolute_import, division, print_function
+from __future__ import annotations
 
 # TODO
 # 
@@ -64,48 +64,78 @@
 
 from ctypes import *
 
-import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int: ...
+def __getitem__(self, key: int) -> TSeq: ...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""
 
 @property
-def value(self):
-if super(c_char_p, self).value is None:
+def value(self) -> str | None:  # type: ignore [override]
+val = super(c_char_p, self).value
+if val is None:
 return None
-return super(c_char_p, self).value.decode("utf8")
+return val.decode("utf8")
 
 @classmethod
-def from_param(cls, param):
+def from_param(cls, param: str | bytes | None) -> c_interop_string:
 if isinstance(param, str):
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
 if param is None:
 # Support passing null to C functions expecting char arrays
-return None
+return cls(param)
 raise TypeError(
 "Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
 )
 
 @staticmethod
-def to_python_string(x, *args):
+def to_python_string(x: c_interop_string, *args: Any) -> str | None:
 return x.value
 
 
-def b(x):
+def b(x: str | bytes) -> bytes:
 if isinstance(x, bytes):
 return x
 return x.encode("utf8")
@@ -115,9 +145,7 @@ def b(x):
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p = POINTER(c_void_p)
-
-callbacks = {}
+c_object_p: TType[CObjP] = POINTER(c_void_p)
 
 ### Exception Classes ###
 
@@ -169,8 +197,11 @@ def __init__(self, enumeration, message):
 
 ### Structures and Utility Classes ###
 
+TInstance = TypeVar("TInstance")
+TResult = TypeVar("TResult")
+
 
-class CachedProperty:
+class CachedProperty(Generic[TInstance, TResult]):
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
@@ -178,16 +209,20 @@ class CachedProperty:
 property, replacing the original method.
 """
 
-def __init__(self, wrapped):
+def __init__(self, wrapped: Callable[[TInstance], TResult]):
 self.wrapped = wrapped
 try:
 self.__doc__ = wrapped.__doc__
 except:
 pass
 
-def __get__(self, instance, instance_type=None):
+def __get__(self, instance: TInstance, instance_type: Any = None) -> 
TResult:
 if instance is None:
-return self
+property_name = self.wrapped.__name__
+class_name = instance_type.__name__
+raise TypeError(
+f"'{property_name}' is not a static attribute of 
'{class_name}'"
+   

[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -2318,25 +2356,25 @@ def kind(self):
 """Return the kind of this type."""
 return TypeKind.from_id(self._kind_id)
 
-def argument_types(self):
+def argument_types(self) -> NoSliceSequence[Type]:
 """Retrieve a container for the non-variadic arguments for this type.
 
 The returned object is iterable and indexable. Each item in the
 container is a Type instance.
 """
 
-class ArgumentsIterator(collections.abc.Sequence):

DeinAlptraum wrote:

This is a type-error since `ArgumentsIterator` doesn't actually implement the 
`Sequence` protocol: it does not support slicing.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum updated 
https://github.com/llvm/llvm-project/pull/98745

>From c9e439d18ccc0749153e211d796ae202554cb229 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 13 Jul 2024 14:12:34 +0100
Subject: [PATCH] [libclang/python] Fix some type errors, add type annotations

---
 clang/bindings/python/clang/cindex.py | 195 +++---
 .../tests/cindex/test_code_completion.py  |  22 +-
 .../python/tests/cindex/test_comment.py   |   4 +-
 3 files changed, 130 insertions(+), 91 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 1d3ab89190407..e71cdcdddcc48 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -43,7 +43,7 @@
 Most object information is exposed using properties, when the underlying API
 call is efficient.
 """
-from __future__ import absolute_import, division, print_function
+from __future__ import annotations
 
 # TODO
 # 
@@ -64,48 +64,81 @@
 
 from ctypes import *
 
-import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int:
+...
+
+def __getitem__(self, key: int) -> TSeq:
+...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""
 
 @property
-def value(self):
-if super(c_char_p, self).value is None:
+def value(self) -> str | None:  # type: ignore [override]
+val = super(c_char_p, self).value
+if val is None:
 return None
-return super(c_char_p, self).value.decode("utf8")
+return val.decode("utf8")
 
 @classmethod
-def from_param(cls, param):
+def from_param(cls, param: str | bytes | None) -> c_interop_string:
 if isinstance(param, str):
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
 if param is None:
 # Support passing null to C functions expecting char arrays
-return None
+return cls(param)
 raise TypeError(
 "Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
 )
 
 @staticmethod
-def to_python_string(x, *args):
+def to_python_string(x: c_interop_string, *args: Any) -> str | None:
 return x.value
 
 
-def b(x):
+def b(x: str | bytes) -> bytes:
 if isinstance(x, bytes):
 return x
 return x.encode("utf8")
@@ -115,9 +148,7 @@ def b(x):
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p = POINTER(c_void_p)
-
-callbacks = {}
+c_object_p: TType[CObjP] = POINTER(c_void_p)
 
 ### Exception Classes ###
 
@@ -169,8 +200,11 @@ def __init__(self, enumeration, message):
 
 ### Structures and Utility Classes ###
 
+TInstance = TypeVar("TInstance")
+TResult = TypeVar("TResult")
+
 
-class CachedProperty:
+class CachedProperty(Generic[TInstance, TResult]):
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
@@ -178,16 +212,20 @@ class CachedProperty:
 property, replacing the original method.
 """
 
-def __init__(self, wrapped):
+def __init__(self, wrapped: Callable[[TInstance], TResult]):
 self.wrapped = wrapped
 try:
 self.__doc__ = wrapped.__doc__
 except:
 pass
 
-def __get__(self, instance, instance_type=None):
+def __get__(self, instance: TInstance, instance_type: Any = None) -> 
TResult:
 if instance is None:
-return self
+property_name = self.wrapped.__name__
+class_name = instance_type.__name__
+raise TypeError(
+f"'{property_name}' is not a static attrib

[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits


@@ -64,48 +64,81 @@
 
 from ctypes import *
 
-import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+from typing_extensions import Protocol, TypeAlias
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int:
+...
+
+def __getitem__(self, key: int) -> TSeq:
+...

DeinAlptraum wrote:

This defines the proper interface for all the classes with "Iterator" in their 
name. None of them are actually iterators in terms of the Python protocol 
`Iterator`, as they are expected to support `__len__` and __getitem__`. They're 
the closest to the `Sequence` protocol, but without the support for slicing.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum updated 
https://github.com/llvm/llvm-project/pull/98745

>From c0216b8a50f7ccc6ee24db69802055c3942a183e Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 13 Jul 2024 14:12:34 +0100
Subject: [PATCH] [libclang/python] Fix some type errors, add type annotations

---
 clang/bindings/python/clang/cindex.py | 195 +++---
 .../tests/cindex/test_code_completion.py  |  22 +-
 .../python/tests/cindex/test_comment.py   |   4 +-
 3 files changed, 130 insertions(+), 91 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 1d3ab89190407..e8b7c006b6679 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -43,7 +43,7 @@
 Most object information is exposed using properties, when the underlying API
 call is efficient.
 """
-from __future__ import absolute_import, division, print_function
+from __future__ import annotations
 
 # TODO
 # 
@@ -64,48 +64,81 @@
 
 from ctypes import *
 
-import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+Any,
+Callable,
+Generic,
+Optional,
+Type as TType,
+TypeVar,
+TYPE_CHECKING,
+Union as TUnion,
+)
+
+if TYPE_CHECKING:
+from ctypes import _Pointer
+from typing_extensions import Protocol, TypeAlias
+
+StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+LibFunc: TypeAlias = TUnion[
+"tuple[str, Optional[list[Any]]]",
+"tuple[str, Optional[list[Any]], Any]",
+"tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
+]
+CObjP: TypeAlias = _Pointer[Any]
+
+TSeq = TypeVar("TSeq", covariant=True)
+
+class NoSliceSequence(Protocol[TSeq]):
+def __len__(self) -> int:
+...
+
+def __getitem__(self, key: int) -> TSeq:
+...
+
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p=None):
+def __init__(self, p: str | bytes | None = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
+def __str__(self) -> str:
+return self.value or ""
 
 @property
-def value(self):
-if super(c_char_p, self).value is None:
+def value(self) -> str | None:  # type: ignore [override]
+val = super(c_char_p, self).value
+if val is None:
 return None
-return super(c_char_p, self).value.decode("utf8")
+return val.decode("utf8")
 
 @classmethod
-def from_param(cls, param):
+def from_param(cls, param: str | bytes | None) -> c_interop_string:
 if isinstance(param, str):
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
 if param is None:
 # Support passing null to C functions expecting char arrays
-return None
+return cls(param)
 raise TypeError(
 "Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
 )
 
 @staticmethod
-def to_python_string(x, *args):
+def to_python_string(x: c_interop_string, *args: Any) -> str | None:
 return x.value
 
 
-def b(x):
+def b(x: str | bytes) -> bytes:
 if isinstance(x, bytes):
 return x
 return x.encode("utf8")
@@ -115,9 +148,7 @@ def b(x):
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p = POINTER(c_void_p)
-
-callbacks = {}
+c_object_p: TType[CObjP] = POINTER(c_void_p)
 
 ### Exception Classes ###
 
@@ -169,8 +200,11 @@ def __init__(self, enumeration, message):
 
 ### Structures and Utility Classes ###
 
+TInstance = TypeVar("TInstance")
+TResult = TypeVar("TResult")
+
 
-class CachedProperty:
+class CachedProperty(Generic[TInstance, TResult]):
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
@@ -178,16 +212,20 @@ class CachedProperty:
 property, replacing the original method.
 """
 
-def __init__(self, wrapped):
+def __init__(self, wrapped: Callable[[TInstance], TResult]):
 self.wrapped = wrapped
 try:
 self.__doc__ = wrapped.__doc__
 except:
 pass
 
-def __get__(self, instance, instance_type=None):
+def __get__(self, instance: TInstance, instance_type: Any = None) -> 
TResult:
 if instance is None:
-return self
+property_name = self.wrapped.__name__
+class_name = instance_type.__name__
+raise TypeError(
+f"'{property_name}' is not a static at

[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-07-13 Thread via cfe-commits


@@ -160,6 +160,8 @@ static char GetFirstChar(const Preprocessor &PP, const 
Token &Tok) {
 bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok,
  const Token &PrevTok,
  const Token &Tok) const {
+  if (PrevTok.is(tok::annot_module_name))
+return false;

yronglin wrote:

Added.

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

@Endilll I am once again asking for your support
This PR collects several of the changes towards #78114 that I assume might need 
some discussion. I tried to leave PR comments with explanations in each of 
those places.
@boomanaiden154 @linux4life798 review from you would also be appreciated!

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

2024-07-13 Thread Jannick Kremer via cfe-commits

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


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-13 Thread Phoebe Wang via cfe-commits


@@ -38,11 +38,11 @@ int test4(volatile int *addr) {
   return (int)oldval;
 }
 
-// This should have both inputs be of type x86_mmx.
+// This should have both inputs be of type <1 x i64>.

phoebewang wrote:

Does it conflict with comment in mmx-inlineasm.ll

> Verify that the mmx 'y' constraint works with arbitrary IR types.

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


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-13 Thread Phoebe Wang via cfe-commits


@@ -44,8 +44,8 @@ Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) 
{
   case FP128TyID : return getFP128Ty(C);
   case PPC_FP128TyID : return getPPC_FP128Ty(C);
   case LabelTyID : return getLabelTy(C);
-  case MetadataTyID  : return getMetadataTy(C);
-  case X86_MMXTyID   : return getX86_MMXTy(C);
+  case MetadataTyID:
+return getMetadataTy(C);

phoebewang wrote:

Keep the old format.

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


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-13 Thread Phoebe Wang via cfe-commits


@@ -57594,6 +57599,86 @@ static SDValue combinePDEP(SDNode *N, SelectionDAG 
&DAG,
   return SDValue();
 }
 
+// Fixup the MMX intrinsics' types: in IR they are expressed with <1 x i64>,

phoebewang wrote:

Are we able to do it in DAGtoDAG?

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


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-13 Thread Phoebe Wang via cfe-commits


@@ -1,9 +0,0 @@
-; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: verify-uselistorder %s
-; Basic smoke test for x86_mmx type.
-
-; CHECK: define x86_mmx @sh16

phoebewang wrote:

What will it be after this patch?

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


[clang] [clang] Prevent dangling StringRefs (PR #98699)

2024-07-13 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/98699

>From 07648c7efab15786c36dbcd265015d945b627725 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 12 Jul 2024 17:40:59 -0500
Subject: [PATCH 1/2] [clang] Prevent dangling StringRefs

Fix locations where dangling StringRefs are created.

* `ConstraintSatisfaction::SubstitutionDiagnostic`:
   typedef of `std::pair`

* `concepts::Requirement::SubstitutionDiagnostic`:
   struct whose 1st and 3rd data members are `StringRef`s

Fixes #98667
---
 clang/lib/Serialization/ASTReaderStmt.cpp | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 6ccb4b01a036a..da67a4fcab5cb 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -796,10 +796,13 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
   if (/* IsDiagnostic */Record.readInt()) {
 SourceLocation DiagLocation = Record.readSourceLocation();
 std::string DiagMessage = Record.readString();
+char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
+std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+
 Satisfaction.Details.emplace_back(
 new (Record.getContext())
 ConstraintSatisfaction::SubstitutionDiagnostic(DiagLocation,
-   DiagMessage));
+   StringRef(DBuf, 
DiagMessage.size(;
   } else
 Satisfaction.Details.emplace_back(Record.readExpr());
 }
@@ -821,11 +824,18 @@ void ASTStmtReader::VisitConceptSpecializationExpr(
 static concepts::Requirement::SubstitutionDiagnostic *
 readSubstitutionDiagnostic(ASTRecordReader &Record) {
   std::string SubstitutedEntity = Record.readString();
+  char *SBuf = new (Record.getContext()) char[SubstitutedEntity.size()];
+  std::copy(SubstitutedEntity.begin(), SubstitutedEntity.end(), SBuf);
+
   SourceLocation DiagLoc = Record.readSourceLocation();
   std::string DiagMessage = Record.readString();
+  char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
+  std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+
   return new (Record.getContext())
-  concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
-DiagMessage};
+  concepts::Requirement::SubstitutionDiagnostic{
+  StringRef(SBuf, SubstitutedEntity.size()), DiagLoc,
+  StringRef(DBuf, DiagMessage.size())};
 }
 
 void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {

>From 3b4dc1fe464bb914ac76d460d96dc39f75afd79a Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sat, 13 Jul 2024 10:04:37 -0500
Subject: [PATCH 2/2] Extract mem alloc & string copy logic to helper function

Add Clang release note item
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Serialization/ASTReaderStmt.cpp | 28 ---
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dc0f8b7e0bbb..055b426860df2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -830,6 +830,8 @@ Bug Fixes in This Version
 - ``__is_trivially_equality_comparable`` no longer returns true for types which
   have a constrained defaulted comparison operator (#GH89293).
 
+- Fixed Clang from generating dangling StringRefs when deserializing Exprs & 
Stmts (#GH98667)
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index da67a4fcab5cb..b2b0a30457d23 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -785,6 +785,12 @@ void 
ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
   E->setRParenLoc(readSourceLocation());
 }
 
+static StringRef saveStrToCtx(const std::string &S, ASTContext &Ctx) {
+  char *Buf = new (Ctx) char[S.size()];
+  std::copy(S.begin(), S.end(), Buf);
+  return StringRef(Buf, S.size());
+}
+
 static ConstraintSatisfaction
 readConstraintSatisfaction(ASTRecordReader &Record) {
   ConstraintSatisfaction Satisfaction;
@@ -795,14 +801,13 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
 for (unsigned i = 0; i != NumDetailRecords; ++i) {
   if (/* IsDiagnostic */Record.readInt()) {
 SourceLocation DiagLocation = Record.readSourceLocation();
-std::string DiagMessage = Record.readString();
-char *DBuf = new (Record.getContext()) char[DiagMessage.size()];
-std::copy(DiagMessage.begin(), DiagMessage.end(), DBuf);
+StringRef DiagMessage =
+saveStrToCtx(Record.readString(), Record.getContext());
 
 Satisfaction.Details.emplace_bac

[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-13 Thread via cfe-commits

https://github.com/memory-thrasher updated 
https://github.com/llvm/llvm-project/pull/97792

>From d47a70e4715a3f6f4740570877799d3bfbb8a713 Mon Sep 17 00:00:00 2001
From: Sidney Kelley 
Date: Thu, 4 Jul 2024 23:03:16 -0700
Subject: [PATCH] Adds support to clang"s windows mangler to handle template
 argument values that are pointers one-past-the-end of a non-array symbol.
 Also improves error messages in other template argument scenarios where clang
 bails.

---
 clang/lib/AST/MicrosoftMangle.cpp | 64 ++-
 .../CodeGen/ms_mangler_templatearg_opte.cpp   | 19 ++
 2 files changed, 68 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/ms_mangler_templatearg_opte.cpp

diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index fac14ce1dce8c..7f0c012a61a4b 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1922,11 +1922,19 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 if (WithScalarType)
   mangleType(T, SourceRange(), QMM_Escape);
 
-// We don't know how to mangle past-the-end pointers yet.
-if (V.isLValueOnePastTheEnd())
-  break;
-
 APValue::LValueBase Base = V.getLValueBase();
+
+// this might not cover every case but did cover issue 97756
+// see test CodeGen/ms_mangler_templatearg_opte
+if (V.isLValueOnePastTheEnd()) {
+  Out << "5E";
+  auto *VD = Base.dyn_cast();
+  if (VD)
+mangle(VD);
+  Out << "@";
+  return;
+}
+
 if (!V.hasLValuePath() || V.getLValuePath().empty()) {
   // Taking the address of a complete object has a special-case mangling.
   if (Base.isNull()) {
@@ -1938,12 +1946,23 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 mangleNumber(V.getLValueOffset().getQuantity());
   } else if (!V.hasLValuePath()) {
 // FIXME: This can only happen as an extension. Invent a mangling.
-break;
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID =
+Diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "cannot mangle this template argument yet "
+  "(extension not comaptible with ms 
mangler)");
+Diags.Report(DiagID);
+return;
   } else if (auto *VD = Base.dyn_cast()) {
 Out << "E";
 mangle(VD);
   } else {
-break;
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error,
+"cannot mangle this template argument yet (undeclared base)");
+Diags.Report(DiagID);
+return;
   }
 } else {
   if (TAK == TplArgKind::ClassNTTP && T->isPointerType())
@@ -1988,8 +2007,14 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 Out << *I;
 
   auto *VD = Base.dyn_cast();
-  if (!VD)
-break;
+  if (!VD) {
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error,
+"cannot mangle this template argument yet (null value decl)");
+Diags.Report(DiagID);
+return;
+  }
   Out << (TAK == TplArgKind::ClassNTTP ? 'E' : '1');
   mangle(VD);
 
@@ -2104,15 +2129,24 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 return;
   }
 
-  case APValue::AddrLabelDiff:
-  case APValue::FixedPoint:
-break;
+  case APValue::AddrLabelDiff: {
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error, "cannot mangle this template argument yet "
+  "(value type: address label diff)");
+Diags.Report(DiagID);
+return;
   }
 
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID = Diags.getCustomDiagID(
-  DiagnosticsEngine::Error, "cannot mangle this template argument yet");
-  Diags.Report(DiagID);
+  case APValue::FixedPoint: {
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error,
+"cannot mangle this template argument yet (value type: fixed point)");
+Diags.Report(DiagID);
+return;
+  }
+  }
 }
 
 void MicrosoftCXXNameMangler::mangleObjCProtocol(const ObjCProtocolDecl *PD) {
diff --git a/clang/test/CodeGen/ms_mangler_templatearg_opte.cpp 
b/clang/test/CodeGen/ms_mangler_templatearg_opte.cpp
new file mode 100644
index 0..ce6b620de3c11
--- /dev/null
+++ b/clang/test/CodeGen/ms_mangler_templatearg_opte.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -std=c++20 -x c++ 
< %s | FileCheck -check-prefix=WIN64 %s
+
+struct A {
+  const int* ptr;
+};
+
+template void tfn() {};
+
+// WIN64: ??$tfn@$2UA@@PEBH5CE?ints@@3QBHB06@YAXXZ
+constexpr int ints[]

[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-13 Thread via cfe-commits

memory-thrasher wrote:

an unrelated test (Modules/prune.m) is now failing on my end. I'm doing a clean 
build because I suspect there's something stale in a cache somewhere.

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-13 Thread Brian Cain via cfe-commits


@@ -0,0 +1,62 @@
+//===-- xray_init.cpp ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// XRay initialisation logic for DSOs.
+//===--===//
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "xray_defs.h"
+#include "xray_flags.h"
+#include "xray_interface_internal.h"
+
+using namespace __sanitizer;
+
+extern "C" {
+extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));

androm3da wrote:

> With -fxray-enable, are you refering to the general -fxray-instrument flag or 
> -fxray-enable-shared?

Yes, the general flag.

> If the main executable was built entirely without -fxray-instrument, linking 
> the DSO will fail, as the __xray_register_dso and __xray_deregister_dso 
> functions could not be resolved.

Ok, right - that makes sense.

> However, this would probably be best as a separate PR.

Agreed - if you decide it's appropriate, good for a follow-up.

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


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-13 Thread Brian Cain via cfe-commits


@@ -0,0 +1,62 @@
+//===-- xray_init.cpp ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// XRay initialisation logic for DSOs.
+//===--===//
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "xray_defs.h"
+#include "xray_flags.h"
+#include "xray_interface_internal.h"
+
+using namespace __sanitizer;
+
+extern "C" {
+extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+
+#if SANITIZER_MAC

androm3da wrote:

If undefined it defaults to `0`.  If that's safe then you can leave it as-is.

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


[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)

2024-07-13 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/94693

>From 4e4bcdc19268543a8348736dede46d8f8cad0066 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 4 Jun 2024 23:22:00 -0700
Subject: [PATCH 1/3] [Clang] Introduce [[clang::coro_inplace_task]]

---
 clang/include/clang/AST/ExprCXX.h | 26 --
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 19 +
 clang/lib/CodeGen/CGBlocks.cpp|  5 +-
 clang/lib/CodeGen/CGCUDARuntime.cpp   |  5 +-
 clang/lib/CodeGen/CGCUDARuntime.h |  8 +-
 clang/lib/CodeGen/CGCXXABI.h  | 10 +--
 clang/lib/CodeGen/CGClass.cpp | 16 ++--
 clang/lib/CodeGen/CGCoroutine.cpp | 30 +--
 clang/lib/CodeGen/CGExpr.cpp  | 41 +
 clang/lib/CodeGen/CGExprCXX.cpp   | 60 +++--
 clang/lib/CodeGen/CodeGenFunction.h   | 64 --
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 16 ++--
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 18 ++--
 clang/lib/Sema/SemaCoroutine.cpp  | 58 -
 clang/lib/Serialization/ASTReaderStmt.cpp | 10 ++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  3 +-
 clang/test/CodeGenCoroutines/Inputs/utility.h | 13 +++
 .../coro-structured-concurrency.cpp   | 84 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 llvm/include/llvm/IR/Intrinsics.td|  3 +
 .../lib/Transforms/Coroutines/CoroCleanup.cpp |  9 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  | 58 -
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |  1 +
 .../coro-elide-structured-concurrency.ll  | 64 ++
 25 files changed, 496 insertions(+), 134 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/Inputs/utility.h
 create mode 100644 clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp
 create mode 100644 
llvm/test/Transforms/Coroutines/coro-elide-structured-concurrency.ll

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index c2feac525c1ea..0cf62aee41b66 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5082,7 +5082,8 @@ class CoroutineSuspendExpr : public Expr {
   enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count };
 
   Stmt *SubExprs[SubExpr::Count];
-  OpaqueValueExpr *OpaqueValue = nullptr;
+  OpaqueValueExpr *CommonExprOpaqueValue = nullptr;
+  OpaqueValueExpr *InplaceCallOpaqueValue = nullptr;
 
 public:
   // These types correspond to the three C++ 'await_suspend' return variants
@@ -5090,10 +5091,10 @@ class CoroutineSuspendExpr : public Expr {
 
   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand,
Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume,
-   OpaqueValueExpr *OpaqueValue)
+   OpaqueValueExpr *CommonExprOpaqueValue)
   : Expr(SC, Resume->getType(), Resume->getValueKind(),
  Resume->getObjectKind()),
-KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
+KeywordLoc(KeywordLoc), CommonExprOpaqueValue(CommonExprOpaqueValue) {
 SubExprs[SubExpr::Operand] = Operand;
 SubExprs[SubExpr::Common] = Common;
 SubExprs[SubExpr::Ready] = Ready;
@@ -5128,7 +5129,16 @@ class CoroutineSuspendExpr : public Expr {
   }
 
   /// getOpaqueValue - Return the opaque value placeholder.
-  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
+  OpaqueValueExpr *getCommonExprOpaqueValue() const {
+return CommonExprOpaqueValue;
+  }
+
+  OpaqueValueExpr *getInplaceCallOpaqueValue() const {
+return InplaceCallOpaqueValue;
+  }
+  void setInplaceCallOpaqueValue(OpaqueValueExpr *E) {
+InplaceCallOpaqueValue = E;
+  }
 
   Expr *getReadyExpr() const {
 return static_cast(SubExprs[SubExpr::Ready]);
@@ -5194,9 +5204,9 @@ class CoawaitExpr : public CoroutineSuspendExpr {
 public:
   CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue, bool IsImplicit = false)
+  OpaqueValueExpr *CommonExprOpaqueValue, bool IsImplicit = false)
   : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common,
- Ready, Suspend, Resume, OpaqueValue) {
+ Ready, Suspend, Resume, CommonExprOpaqueValue) {
 CoawaitBits.IsImplicit = IsImplicit;
   }
 
@@ -5275,9 +5285,9 @@ class CoyieldExpr : public CoroutineSuspendExpr {
 public:
   CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue)
+  OpaqueValueExpr *CommonExprOpaqueValue)
   : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common,
-  

[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)

2024-07-13 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/94693

>From 4e4bcdc19268543a8348736dede46d8f8cad0066 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 4 Jun 2024 23:22:00 -0700
Subject: [PATCH 1/3] [Clang] Introduce [[clang::coro_inplace_task]]

---
 clang/include/clang/AST/ExprCXX.h | 26 --
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 19 +
 clang/lib/CodeGen/CGBlocks.cpp|  5 +-
 clang/lib/CodeGen/CGCUDARuntime.cpp   |  5 +-
 clang/lib/CodeGen/CGCUDARuntime.h |  8 +-
 clang/lib/CodeGen/CGCXXABI.h  | 10 +--
 clang/lib/CodeGen/CGClass.cpp | 16 ++--
 clang/lib/CodeGen/CGCoroutine.cpp | 30 +--
 clang/lib/CodeGen/CGExpr.cpp  | 41 +
 clang/lib/CodeGen/CGExprCXX.cpp   | 60 +++--
 clang/lib/CodeGen/CodeGenFunction.h   | 64 --
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 16 ++--
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 18 ++--
 clang/lib/Sema/SemaCoroutine.cpp  | 58 -
 clang/lib/Serialization/ASTReaderStmt.cpp | 10 ++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  3 +-
 clang/test/CodeGenCoroutines/Inputs/utility.h | 13 +++
 .../coro-structured-concurrency.cpp   | 84 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 llvm/include/llvm/IR/Intrinsics.td|  3 +
 .../lib/Transforms/Coroutines/CoroCleanup.cpp |  9 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  | 58 -
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |  1 +
 .../coro-elide-structured-concurrency.ll  | 64 ++
 25 files changed, 496 insertions(+), 134 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/Inputs/utility.h
 create mode 100644 clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp
 create mode 100644 
llvm/test/Transforms/Coroutines/coro-elide-structured-concurrency.ll

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index c2feac525c1ea..0cf62aee41b66 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5082,7 +5082,8 @@ class CoroutineSuspendExpr : public Expr {
   enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count };
 
   Stmt *SubExprs[SubExpr::Count];
-  OpaqueValueExpr *OpaqueValue = nullptr;
+  OpaqueValueExpr *CommonExprOpaqueValue = nullptr;
+  OpaqueValueExpr *InplaceCallOpaqueValue = nullptr;
 
 public:
   // These types correspond to the three C++ 'await_suspend' return variants
@@ -5090,10 +5091,10 @@ class CoroutineSuspendExpr : public Expr {
 
   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand,
Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume,
-   OpaqueValueExpr *OpaqueValue)
+   OpaqueValueExpr *CommonExprOpaqueValue)
   : Expr(SC, Resume->getType(), Resume->getValueKind(),
  Resume->getObjectKind()),
-KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
+KeywordLoc(KeywordLoc), CommonExprOpaqueValue(CommonExprOpaqueValue) {
 SubExprs[SubExpr::Operand] = Operand;
 SubExprs[SubExpr::Common] = Common;
 SubExprs[SubExpr::Ready] = Ready;
@@ -5128,7 +5129,16 @@ class CoroutineSuspendExpr : public Expr {
   }
 
   /// getOpaqueValue - Return the opaque value placeholder.
-  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
+  OpaqueValueExpr *getCommonExprOpaqueValue() const {
+return CommonExprOpaqueValue;
+  }
+
+  OpaqueValueExpr *getInplaceCallOpaqueValue() const {
+return InplaceCallOpaqueValue;
+  }
+  void setInplaceCallOpaqueValue(OpaqueValueExpr *E) {
+InplaceCallOpaqueValue = E;
+  }
 
   Expr *getReadyExpr() const {
 return static_cast(SubExprs[SubExpr::Ready]);
@@ -5194,9 +5204,9 @@ class CoawaitExpr : public CoroutineSuspendExpr {
 public:
   CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue, bool IsImplicit = false)
+  OpaqueValueExpr *CommonExprOpaqueValue, bool IsImplicit = false)
   : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common,
- Ready, Suspend, Resume, OpaqueValue) {
+ Ready, Suspend, Resume, CommonExprOpaqueValue) {
 CoawaitBits.IsImplicit = IsImplicit;
   }
 
@@ -5275,9 +5285,9 @@ class CoyieldExpr : public CoroutineSuspendExpr {
 public:
   CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue)
+  OpaqueValueExpr *CommonExprOpaqueValue)
   : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common,
-  

[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-07-13 Thread Chris B via cfe-commits

llvm-beanz wrote:

@kimgr you should be able to have CMake query the path of libclang and go from 
there. Something like:

```cmake
get_target_property(SHARED_LIB_DIR libclang RUNTIME_OUTPUT_DIRECTORY)
```

That should give you the binary location of libclang, which should work for 
resolving the final path.

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


[clang] d91ff3f - [HLSL] Rework implicit conversion sequences (#96011)

2024-07-13 Thread via cfe-commits

Author: Chris B
Date: 2024-07-13T12:23:22-05:00
New Revision: d91ff3f2409a721b61b68c6a8438ea6c59323df8

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

LOG: [HLSL] Rework implicit conversion sequences (#96011)

This PR reworks HLSL's implicit conversion sequences. Initially I was
seeking to match DXC's behavior more closely, but that was leading to a
pile of special case rules to tie-break ambiguous cases that should
really be left as ambiguous. We've decided that we're going to break
compatibility with DXC here, and we may port this new behavior over to
DXC instead.

This change is a bit closer to C++'s overload resolution rules, but it
does have a bit of nuance around how dimension adjustment conversions
are ranked. Conversion sequence ranks for HLSL are:

* Exact match
* Scalar Widening (i.e. splat)
* Promotion
* Scalar Widening with Promotion
* Conversion
* Scalar Widening with Conversion
* Dimension Reduction (i.e. truncation)
* Dimension Reduction with Promotion
* Dimension Reduction with Conversion

In this implementation I've folded the disambiguation into the
conversion sequence ranks which does add some complexity as compared to
C++, however this avoids needing to add special casing in
`CompareStandardConversionSequences`. I believe the added conversion
rank values provide a simpler approach, but feedback is appreciated.

The HLSL language spec updates are in the PR here:
https://github.com/microsoft/hlsl-specs/pull/261

Added: 
clang/test/SemaHLSL/SplatOverloadResolution.hlsl
clang/test/SemaHLSL/TruncationOverloadResolution.hlsl

Modified: 
clang/docs/HLSL/ExpectedDifferences.rst
clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CodeGenHLSL/BasicFeatures/standard_conversion_sequences.hlsl
clang/test/CodeGenHLSL/builtins/dot.hlsl
clang/test/CodeGenHLSL/builtins/lerp.hlsl
clang/test/CodeGenHLSL/builtins/mad.hlsl
clang/test/SemaHLSL/ScalarOverloadResolution.hlsl
clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl
clang/test/SemaHLSL/VectorElementOverloadResolution.hlsl
clang/test/SemaHLSL/VectorOverloadResolution.hlsl
clang/test/SemaHLSL/standard_conversion_sequences.hlsl

Removed: 
clang/test/SemaHLSL/OverloadResolutionBugs.hlsl



diff  --git a/clang/docs/HLSL/ExpectedDifferences.rst 
b/clang/docs/HLSL/ExpectedDifferences.rst
index d1b6010f10f43..a29b6348e0b8e 100644
--- a/clang/docs/HLSL/ExpectedDifferences.rst
+++ b/clang/docs/HLSL/ExpectedDifferences.rst
@@ -67,12 +67,16 @@ behavior between Clang and DXC. Some examples include:
   void takesDoubles(double, double, double);
 
   cbuffer CB {
+bool B;
 uint U;
 int I;
 float X, Y, Z;
 double3 A, B;
   }
 
+  void twoParams(int, int);
+  void twoParams(float, float);
+
   export void call() {
 halfOrInt16(U); // DXC: Fails with call ambiguous between int16_t and 
uint16_t overloads
 // Clang: Resolves to halfOrInt16(uint16_t).
@@ -98,6 +102,13 @@ behavior between Clang and DXC. Some examples include:
   // FXC: Expands to compute double dot product with 
fmul/fadd
   // Clang: Resolves to dot(float3, float3), emits 
conversion warnings.
 
+  #ifndef IGNORE_ERRORS
+tan(B); // DXC: resolves to tan(float).
+// Clang: Fails to resolve, ambiguous between integer types.
+
+twoParams(I, X); // DXC: resolves twoParams(int, int).
+ // Clang: Fails to resolve ambiguous conversions.
+  #endif
   }
 
 .. note::

diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 4a5c9e8ca1229..9d8b797af6663 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -201,6 +201,9 @@ class Sema;
 /// HLSL non-decaying array rvalue cast.
 ICK_HLSL_Array_RValue,
 
+// HLSL vector splat from scalar or boolean type.
+ICK_HLSL_Vector_Splat,
+
 /// The number of conversion kinds
 ICK_Num_Conversion_Kinds,
   };
@@ -213,15 +216,27 @@ class Sema;
 /// Exact Match
 ICR_Exact_Match = 0,
 
+/// HLSL Scalar Widening
+ICR_HLSL_Scalar_Widening,
+
 /// Promotion
 ICR_Promotion,
 
+/// HLSL Scalar Widening with promotion
+ICR_HLSL_Scalar_Widening_Promotion,
+
+/// HLSL Matching Dimension Reduction
+ICR_HLSL_Dimension_Reduction,
+
 /// Conversion
 ICR_Conversion,
 
 /// OpenCL Scalar Widening
 ICR_OCL_Scalar_Widening,
 
+/// HLSL Scalar Widening with conversion
+ICR_HLSL_Scalar_Widening_Conversion,
+
 /// Complex <-> Real conversion
 ICR_Complex_Real_Conversion,
 
@@ -233,11 +248,21 @@ class Sema;
 
 /// Conversion not allowed by the C stand

[clang] [HLSL] Rework implicit conversion sequences (PR #96011)

2024-07-13 Thread Chris B via cfe-commits

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-07-13 Thread Thomas Wucher via cfe-commits

thomaswucher wrote:

Thank you for your approval, @DeinAlptraum!

@AaronBallman and @Endilll, is there anything else I need to do to get this 
merged? Would one of you be so kind to approve the remaining GitHub workflows?

Thanks for all your support and quick responses!

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


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-13 Thread via cfe-commits

memory-thrasher wrote:

ya it's something with my local build env. same test is now failing when built 
from the commit before mine. Looks like they passed on the build server though 
so this should be ready. I fixed the things you mentioned @bolshakov-a . Let me 
know if you have a different phrasing for those diagnositcs in mind or if you 
want any other changes made.

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Hana Dusíková via cfe-commits

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


[clang] [clang] constexpr atomic builtins (__c11_atomic_OP and __atomic_OP) (PR #98756)

2024-07-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot created 
https://github.com/llvm/llvm-project/pull/98756

This implements clang support for P3309 constexpr std::atomic & std::atomic_ref 
(currently in LWG) by allowing constant evaluation of clang's __c11_atomic_OP 
and GCC's __atomic_OP builtins.

From e42b4a8877fed0096e44961235a61192ecb8e620 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jul 2024 20:10:26 +0200
Subject: [PATCH] [clang] constexpr atomic builtins (__c11_atomic_OP and
 __atomic_OP)

---
 clang/include/clang/Basic/Builtins.td |  84 +--
 clang/lib/AST/ExprConstant.cpp| 553 +-
 .../SemaCXX/atomic-constexpr-c11-builtins.cpp | 288 +
 .../SemaCXX/atomic-constexpr-gcc-builtins.cpp | 494 
 4 files changed, 1371 insertions(+), 48 deletions(-)
 create mode 100644 clang/test/SemaCXX/atomic-constexpr-c11-builtins.cpp
 create mode 100644 clang/test/SemaCXX/atomic-constexpr-gcc-builtins.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [

[clang] [clang] constexpr atomic builtins (__c11_atomic_OP and __atomic_OP) (PR #98756)

2024-07-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hana Dusíková (hanickadot)


Changes

This implements clang support for P3309 constexpr std::atomic & 
std::atomic_ref (currently in LWG) by allowing constant evaluation of clang's 
__c11_atomic_OP and GCC's __atomic_OP builtins.

---

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


4 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+42-42) 
- (modified) clang/lib/AST/ExprConstant.cpp (+547-6) 
- (added) clang/test/SemaCXX/atomic-constexpr-c11-builtins.cpp (+288) 
- (added) clang/test/SemaCXX/atomic-constexpr-gcc-builtins.cpp (+494) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def AtomicLoadN : AtomicBuiltin {
   let Spellings = ["__atomic_load_n"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let

[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-13 Thread via cfe-commits

https://github.com/akshaykumars614 created 
https://github.com/llvm/llvm-project/pull/98757

added a check to remove '->' if exists

>From 283ec53fe19f0008c3c04210ea5c9b20c3d9781c Mon Sep 17 00:00:00 2001
From: akshaykumars614 
Date: Sat, 13 Jul 2024 14:14:53 -0400
Subject: [PATCH] clang-tidy: readability-redundant-smartptr-get does not
 remove -> (#97964)

added a check to remove '->' if exists
---
 .../clang-tidy/readability/RedundantSmartptrGetCheck.cpp  | 4 
 1 file changed, 4 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 8837ac16e8828..be52af77ae0a5 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -164,6 +164,10 @@ void RedundantSmartptrGetCheck::check(const 
MatchFinder::MatchResult &Result) {
   StringRef SmartptrText = Lexer::getSourceText(
   CharSourceRange::getTokenRange(Smartptr->getSourceRange()),
   *Result.SourceManager, getLangOpts());
+  // Check if the last two characters are "->" and remove them
+  if (SmartptrText.ends_with("->")) {
+SmartptrText = SmartptrText.drop_back(2);
+  }
   // Replace foo->get() with *foo, and foo.get() with foo.
   std::string Replacement = Twine(IsPtrToPtr ? "*" : "", SmartptrText).str();
   diag(GetCall->getBeginLoc(), "redundant get() call on smart pointer")

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


[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-13 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: None (akshaykumars614)


Changes

added a check to remove '->' if exists

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


1 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp (+4) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 8837ac16e8828..be52af77ae0a5 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -164,6 +164,10 @@ void RedundantSmartptrGetCheck::check(const 
MatchFinder::MatchResult &Result) {
   StringRef SmartptrText = Lexer::getSourceText(
   CharSourceRange::getTokenRange(Smartptr->getSourceRange()),
   *Result.SourceManager, getLangOpts());
+  // Check if the last two characters are "->" and remove them
+  if (SmartptrText.ends_with("->")) {
+SmartptrText = SmartptrText.drop_back(2);
+  }
   // Replace foo->get() with *foo, and foo.get() with foo.
   std::string Replacement = Twine(IsPtrToPtr ? "*" : "", SmartptrText).str();
   diag(GetCall->getBeginLoc(), "redundant get() call on smart pointer")

``




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


[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-13 Thread via cfe-commits

akshaykumars614 wrote:

I am not sure if I need to write a test case for clang-tidy

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


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-13 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/98758

In the previous patch https://github.com/llvm/llvm-project/pull/95660, we used 
a strategy of eagerly instantiating local constexpr lambdas. However, that 
caused a regression in recursive local lambda calls.

This patch addressed that by adding an instantiation requirement to the 
expression constant evaluation, like what we did when deducing the function 
return type.

Closes https://github.com/llvm/llvm-project/issues/98526

(The reduced examples in https://github.com/llvm/llvm-project/issues/97680 seem 
different, as they don't compile in Clang 18 either. However, #97680 per se 
should work again with this patch.)

>From d615943c09abecd777485279645a4c80a63ba199 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 14 Jul 2024 02:06:59 +0800
Subject: [PATCH] [Clang] Reconsider the timing of instantiation of local
 constexpr lambdas

---
 clang/lib/Sema/SemaExpr.cpp   | 55 +++
 .../SemaTemplate/instantiate-local-class.cpp  | 26 +
 2 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 852344d895ffd..8414f5c7e46c4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -59,6 +59,7 @@
 #include "clang/Sema/Template.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLForwardCompat.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -5340,20 +5341,31 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation 
CallLoc, FunctionDecl *FD,
 
 struct ImmediateCallVisitor : public RecursiveASTVisitor 
{
   const ASTContext &Context;
-  ImmediateCallVisitor(const ASTContext &Ctx) : Context(Ctx) {}
+  llvm::SmallPtrSetImpl *ReferencedFunctions;
+
+  ImmediateCallVisitor(const ASTContext &Ctx,
+   llvm::SmallPtrSetImpl
+   *ReferencedFunctions = nullptr)
+  : Context(Ctx), ReferencedFunctions(ReferencedFunctions) {}
 
   bool HasImmediateCalls = false;
   bool shouldVisitImplicitCode() const { return true; }
 
   bool VisitCallExpr(CallExpr *E) {
-if (const FunctionDecl *FD = E->getDirectCallee())
+if (const FunctionDecl *FD = E->getDirectCallee()) {
   HasImmediateCalls |= FD->isImmediateFunction();
+  if (ReferencedFunctions)
+ReferencedFunctions->insert(FD);
+}
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
-if (const FunctionDecl *FD = E->getConstructor())
+if (const FunctionDecl *FD = E->getConstructor()) {
   HasImmediateCalls |= FD->isImmediateFunction();
+  if (ReferencedFunctions)
+ReferencedFunctions->insert(FD);
+}
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
@@ -16983,6 +16995,30 @@ Sema::VerifyIntegerConstantExpression(Expr *E, 
llvm::APSInt *Result,
   SmallVector Notes;
   EvalResult.Diag = &Notes;
 
+  // Check if the expression refers to local functions yet to be instantiated.
+  // If so, instantiate them now, as the constant evaluation requires the
+  // function definition.
+  if (!PendingLocalImplicitInstantiations.empty()) {
+llvm::SmallPtrSet ReferencedFunctions;
+ImmediateCallVisitor V(getASTContext(), &ReferencedFunctions);
+V.TraverseStmt(E);
+
+auto Pred = [&](PendingImplicitInstantiation Pair) {
+  ValueDecl *VD = Pair.first;
+  return isa(VD) &&
+ ReferencedFunctions.contains(cast(VD));
+};
+// Workaround: A lambda with captures cannot be copy-assigned, which is
+// required by llvm::make_filter_range().
+llvm::function_ref PredRef = Pred;
+
+auto R =
+llvm::make_filter_range(PendingLocalImplicitInstantiations, PredRef);
+LocalEagerInstantiationScope InstantiateReferencedLocalFunctions(*this);
+PendingLocalImplicitInstantiations = {R.begin(), R.end()};
+InstantiateReferencedLocalFunctions.perform();
+  }
+
   // Try to evaluate the expression, and produce diagnostics explaining why 
it's
   // not a constant expression as a side-effect.
   bool Folded =
@@ -17938,17 +17974,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
 
 if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
 Func->isConstexpr()) {
-  if (Func->isConstexpr())
+  if (isa(Func->getDeclContext()) &&
+  cast(Func->getDeclContext())->isLocalClass() &&
+  CodeSynthesisContexts.size())
+PendingLocalImplicitInstantiations.push_back(
+std::make_pair(Func, PointOfInstantiation));
+  else if (Func->isConstexpr())
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call back into Sema if it sees a
 // call to such a function.
 InstantiateF

[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

In the previous patch https://github.com/llvm/llvm-project/pull/95660, we used 
a strategy of eagerly instantiating local constexpr lambdas. However, that 
caused a regression in recursive local lambda calls.

This patch addressed that by adding an instantiation requirement to the 
expression constant evaluation, like what we did when deducing the function 
return type.

Closes https://github.com/llvm/llvm-project/issues/98526

(The reduced examples in https://github.com/llvm/llvm-project/issues/97680 seem 
different, as they don't compile in Clang 18 either. However, #97680 
per se should work again with this patch.)

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+45-10) 
- (modified) clang/test/SemaTemplate/instantiate-local-class.cpp (+26) 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 852344d895ffd..8414f5c7e46c4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -59,6 +59,7 @@
 #include "clang/Sema/Template.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLForwardCompat.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -5340,20 +5341,31 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation 
CallLoc, FunctionDecl *FD,
 
 struct ImmediateCallVisitor : public RecursiveASTVisitor 
{
   const ASTContext &Context;
-  ImmediateCallVisitor(const ASTContext &Ctx) : Context(Ctx) {}
+  llvm::SmallPtrSetImpl *ReferencedFunctions;
+
+  ImmediateCallVisitor(const ASTContext &Ctx,
+   llvm::SmallPtrSetImpl
+   *ReferencedFunctions = nullptr)
+  : Context(Ctx), ReferencedFunctions(ReferencedFunctions) {}
 
   bool HasImmediateCalls = false;
   bool shouldVisitImplicitCode() const { return true; }
 
   bool VisitCallExpr(CallExpr *E) {
-if (const FunctionDecl *FD = E->getDirectCallee())
+if (const FunctionDecl *FD = E->getDirectCallee()) {
   HasImmediateCalls |= FD->isImmediateFunction();
+  if (ReferencedFunctions)
+ReferencedFunctions->insert(FD);
+}
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
-if (const FunctionDecl *FD = E->getConstructor())
+if (const FunctionDecl *FD = E->getConstructor()) {
   HasImmediateCalls |= FD->isImmediateFunction();
+  if (ReferencedFunctions)
+ReferencedFunctions->insert(FD);
+}
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
@@ -16983,6 +16995,30 @@ Sema::VerifyIntegerConstantExpression(Expr *E, 
llvm::APSInt *Result,
   SmallVector Notes;
   EvalResult.Diag = &Notes;
 
+  // Check if the expression refers to local functions yet to be instantiated.
+  // If so, instantiate them now, as the constant evaluation requires the
+  // function definition.
+  if (!PendingLocalImplicitInstantiations.empty()) {
+llvm::SmallPtrSet ReferencedFunctions;
+ImmediateCallVisitor V(getASTContext(), &ReferencedFunctions);
+V.TraverseStmt(E);
+
+auto Pred = [&](PendingImplicitInstantiation Pair) {
+  ValueDecl *VD = Pair.first;
+  return isa(VD) &&
+ ReferencedFunctions.contains(cast(VD));
+};
+// Workaround: A lambda with captures cannot be copy-assigned, which is
+// required by llvm::make_filter_range().
+llvm::function_ref PredRef = Pred;
+
+auto R =
+llvm::make_filter_range(PendingLocalImplicitInstantiations, PredRef);
+LocalEagerInstantiationScope InstantiateReferencedLocalFunctions(*this);
+PendingLocalImplicitInstantiations = {R.begin(), R.end()};
+InstantiateReferencedLocalFunctions.perform();
+  }
+
   // Try to evaluate the expression, and produce diagnostics explaining why 
it's
   // not a constant expression as a side-effect.
   bool Folded =
@@ -17938,17 +17974,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
 
 if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
 Func->isConstexpr()) {
-  if (Func->isConstexpr())
+  if (isa(Func->getDeclContext()) &&
+  cast(Func->getDeclContext())->isLocalClass() &&
+  CodeSynthesisContexts.size())
+PendingLocalImplicitInstantiations.push_back(
+std::make_pair(Func, PointOfInstantiation));
+  else if (Func->isConstexpr())
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call back into Sema if it sees a
 // call to such a function.
 InstantiateFunctionDefinition(PointOfInstantiation, Func);
-  else if (isa(Func->getDeclContext()) &&
-   cast(Func->getDeclContext())
-   ->isLocalC

[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-13 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-13 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> I am not sure if I need to write a test case for clang-tidy

Yes, and release notes entry,

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


[clang] [clang] constexpr atomic builtins (__c11_atomic_OP and __atomic_OP) (PR #98756)

2024-07-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/98756

From 76fe494219d085247e537b3633c321ffe2917226 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jul 2024 20:10:26 +0200
Subject: [PATCH] [clang] constexpr atomic builtins (__c11_atomic_OP and
 __atomic_OP)

---
 clang/include/clang/Basic/Builtins.td |  84 +--
 clang/lib/AST/ExprConstant.cpp| 528 ++
 .../SemaCXX/atomic-constexpr-c11-builtins.cpp | 288 ++
 .../SemaCXX/atomic-constexpr-gcc-builtins.cpp | 494 
 4 files changed, 1352 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/SemaCXX/atomic-constexpr-c11-builtins.cpp
 create mode 100644 clang/test/SemaCXX/atomic-constexpr-gcc-builtins.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def AtomicLoadN : AtomicBuiltin {
   let Spellings = ["__atomic_load_n"];
-  let

[clang] [clang][driver] Improve Clang-CL support for C++20 standard modules (PR #98761)

2024-07-13 Thread Sharadh Rajaraman via cfe-commits

https://github.com/sharadhr created 
https://github.com/llvm/llvm-project/pull/98761

This PR is the first step in improving the situation for `clang-cl` detailed in 
[this LLVM Discourse 
thread](https://discourse.llvm.org/t/clang-cl-exe-support-for-c-modules/72257/28).
 There has been some work done in #89772. I believe this is somewhat orthogonal.

This is a work-in-progress; the functionality has only been tested with the 
[basic 'Hello World' 
example](https://clang.llvm.org/docs/StandardCPlusPlusModules.html#quick-start),
 and proper test cases need to be written. Additionally, the `/std:c++20` 
command-line argument is considered unused (although it is very much required, 
and compilation fails without it) with the following warning:

```
clang: warning: argument unused during compilation: '/std:c++20' 
[-Wunused-command-line-argument]
```

I suspect the issue is somewhere around 
https://github.com/llvm/llvm-project/blob/8802c9fd73da9451e69e15eed53b396c7d44a866/clang/lib/Driver/ToolChains/Clang.cpp#L6285-L6300

I'd like some thoughts on this, thanks!

>From 1fed92a00f0d732a2575861c2bf6a6d053407255 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman 
Date: Sat, 13 Jul 2024 19:25:47 +0100
Subject: [PATCH] Allow `--precompile` and `-fprebuilt-module-path` to be
 passed directly into CL driver without `/clang:` prefix

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

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4ab8638175dd3..ca7cfef8453a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3085,7 +3085,7 @@ def fmodules_user_build_path : Separate<["-"], 
"fmodules-user-build-path">, Grou
   HelpText<"Specify the module user build path">,
   MarshallingInfoString>;
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
-  Flags<[]>, Visibility<[ClangOption, CC1Option]>,
+  Flags<[]>, Visibility<[ClangOption, CLOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Specify the prebuilt module path">;
 defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
@@ -5874,6 +5874,7 @@ def _output : Separate<["--"], "output">, Alias;
 def _param : Separate<["--"], "param">, Group;
 def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
 def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CLOption]>,
   Group, HelpText<"Only precompile the input">;
 def _prefix_EQ : Joined<["--"], "prefix=">, Alias;
 def _prefix : Separate<["--"], "prefix">, Alias;

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


[clang] [clang][driver] Improve Clang-CL support for C++20 standard modules (PR #98761)

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


[clang] [clang][driver] Improve Clang-CL support for C++20 standard modules (PR #98761)

2024-07-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sharadh Rajaraman (sharadhr)


Changes

This PR is the first step in improving the situation for `clang-cl` detailed in 
[this LLVM Discourse 
thread](https://discourse.llvm.org/t/clang-cl-exe-support-for-c-modules/72257/28).
 There has been some work done in #89772. I believe this is somewhat 
orthogonal.

This is a work-in-progress; the functionality has only been tested with the 
[basic 'Hello World' 
example](https://clang.llvm.org/docs/StandardCPlusPlusModules.html#quick-start),
 and proper test cases need to be written. Additionally, the `/std:c++20` 
command-line argument is considered unused (although it is very much required, 
and compilation fails without it) with the following warning:

```
clang: warning: argument unused during compilation: '/std:c++20' 
[-Wunused-command-line-argument]
```

I suspect the issue is somewhere around 
https://github.com/llvm/llvm-project/blob/8802c9fd73da9451e69e15eed53b396c7d44a866/clang/lib/Driver/ToolChains/Clang.cpp#L6285-L6300

I'd like some thoughts on this, thanks!

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


1 Files Affected:

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


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4ab8638175dd3..ca7cfef8453a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3085,7 +3085,7 @@ def fmodules_user_build_path : Separate<["-"], 
"fmodules-user-build-path">, Grou
   HelpText<"Specify the module user build path">,
   MarshallingInfoString>;
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
-  Flags<[]>, Visibility<[ClangOption, CC1Option]>,
+  Flags<[]>, Visibility<[ClangOption, CLOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Specify the prebuilt module path">;
 defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
@@ -5874,6 +5874,7 @@ def _output : Separate<["--"], "output">, Alias;
 def _param : Separate<["--"], "param">, Group;
 def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
 def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CLOption]>,
   Group, HelpText<"Only precompile the input">;
 def _prefix_EQ : Joined<["--"], "prefix=">, Alias;
 def _prefix : Separate<["--"], "prefix">, Alias;

``




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


[clang] [clang] constexpr atomic builtins (__c11_atomic_OP and __atomic_OP) (PR #98756)

2024-07-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/98756

From 76fe494219d085247e537b3633c321ffe2917226 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jul 2024 20:10:26 +0200
Subject: [PATCH 1/2] [clang] constexpr atomic builtins (__c11_atomic_OP and
 __atomic_OP)

---
 clang/include/clang/Basic/Builtins.td |  84 +--
 clang/lib/AST/ExprConstant.cpp| 528 ++
 .../SemaCXX/atomic-constexpr-c11-builtins.cpp | 288 ++
 .../SemaCXX/atomic-constexpr-gcc-builtins.cpp | 494 
 4 files changed, 1352 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/SemaCXX/atomic-constexpr-c11-builtins.cpp
 create mode 100644 clang/test/SemaCXX/atomic-constexpr-gcc-builtins.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f8..0716cf02f5110 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1682,97 +1682,97 @@ def SyncSwapN : Builtin, SyncBuiltinsTemplate {
 // C11 _Atomic operations for .
 def C11AtomicInit : AtomicBuiltin {
   let Spellings = ["__c11_atomic_init"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicLoad : AtomicBuiltin {
   let Spellings = ["__c11_atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicStore : AtomicBuiltin {
   let Spellings = ["__c11_atomic_store"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicExchange : AtomicBuiltin {
   let Spellings = ["__c11_atomic_exchange"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeStrong : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_strong"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicCompareExchangeWeak : AtomicBuiltin {
   let Spellings = ["__c11_atomic_compare_exchange_weak"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAdd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_add"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchSub : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_sub"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchAnd : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_and"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchOr : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_or"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchXor : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_xor"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchNand : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_nand"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMax : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_max"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicFetchMin : AtomicBuiltin {
   let Spellings = ["__c11_atomic_fetch_min"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def C11AtomicThreadFence : Builtin {
   let Spellings = ["__c11_atomic_thread_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
 def C11AtomicSignalFence : Builtin {
   let Spellings = ["__c11_atomic_signal_fence"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   let Prototype = "void(int)";
 }
 
@@ -1785,157 +1785,157 @@ def C11AtomicIsLockFree : Builtin {
 // GNU atomic builtins.
 def AtomicLoad : AtomicBuiltin {
   let Spellings = ["__atomic_load"];
-  let Attributes = [CustomTypeChecking];
+  let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def AtomicLoadN : AtomicBuiltin {
   let Spellings = ["__atomic_load_n"];
- 

[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-13 Thread via cfe-commits

akshaykumars614 wrote:

can you tell me where to add test case and release notes entry

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


  1   2   >