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

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

tbaederr wrote:

There's a conflict in the `ReleaseNotes.rst` again unfortunately :(

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


[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

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

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


[lldb] [clang] [compiler-rt] [libcxx] [flang] [lld] [clang-tools-extra] [mlir] [llvm] [libc] GFX12: Add LoopDataPrefetchPass (PR #75625)

2023-12-18 Thread Mariusz Sikora via cfe-commits

https://github.com/mariusz-sikora-at-amd closed 
https://github.com/llvm/llvm-project/pull/75625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-12-18 Thread David Green via cfe-commits

davemgreen wrote:

It looks like there is a downstream implementation of this that was never 
upstreamed. Perhaps someone can fish it out for you to show how it looked? It 
might be using the wrong predefined macro, but does have some tests.

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


[clang] [llvm] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110 (PR #75516)

2023-12-18 Thread David Green via cfe-commits


@@ -81,6 +81,15 @@ static bool DecodeAArch64Features(const Driver , StringRef 
text,
 else
   return false;
 
+// +jsconv and +complxnum implies +neon and +fp-armv8

davemgreen wrote:

I believe this ideally would not be in the driver, as it does not apply to 
target attributes, only -march options.

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


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

Is #75799 related?

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


[libunwind] [llvm] [clang] [clang-tools-extra] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

2023-12-18 Thread Alexander Richardson via cfe-commits


@@ -2974,6 +2966,39 @@ bool UnwindCursor::getFunctionName(char *buf, 
size_t bufLen,
  buf, bufLen, offset);
 }
 
+#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+template 
+bool UnwindCursor::isReadableAddr(const pint_t addr) const {
+  // This code is heavily based on Abseil's 'address_is_readable.cc',
+  // which is Copyright Abseil Authors (2017), and provided under
+  // the Apache License 2.0.
+
+  // Align to 8-bytes.
+  const auto alignedAddr = addr & ~pint_t{7};
+  const auto sigsetAddr = reinterpret_cast(alignedAddr);
+  // We have to check that addr is nullptr because sigprocmask allows that
+  // as an argument without failure.
+  if (!sigsetAddr)
+return false;
+
+  // We MUST use the raw sigprocmask syscall here, as wrappers may try to
+  // access sigsetAddr which may cause a SIGSEGV. The raw syscall however is
+  // safe. Additionally, we need to pass the kernel_sigset_size, which is
+  // different from libc sizeof(sigset_t). Some archs have sigset_t
+  // defined as unsigned long, so let's use that.
+  const auto approxKernelSigsetSize = sizeof(unsigned long);
+  [[maybe_unused]] const int Result =
+  syscall(SYS_rt_sigprocmask, /*how=*/~0, sigsetAddr, sigsetAddr,
+  approxKernelSigsetSize);
+  // Because our "how" is invalid, this syscall should always fail, and our

arichardson wrote:

I would add a comment that this code relies on the Linux kernel checking 
copy_from_user success before checking the how argument is valid. I think this 
is somewhat fragile but I guess the kernel can't change this behaviour anymore 
without breaking userspace.

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


[clang] [Clang][Wswitch-default] Warning for enum even completely covered the cases (PR #75900)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (hstk30-hw)


Changes



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


1 Files Affected:

- (modified) clang/test/Sema/switch-default.c (+11) 


``diff
diff --git a/clang/test/Sema/switch-default.c b/clang/test/Sema/switch-default.c
index 854b561b37c48e..342a97ee68b1e2 100644
--- a/clang/test/Sema/switch-default.c
+++ b/clang/test/Sema/switch-default.c
@@ -15,3 +15,14 @@ int f2(int a) {
   }
   return a;
 }
+
+// Warn even completely covered Enum cases(GCC compatibility).
+enum E { A, B };
+enum E check_enum(enum E e) {
+  switch (e) {// expected-warning {{'switch' missing 'default' 
label}}
+case A: break;
+case B: break;
+  }
+  return e;
+}
+

``




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


[clang] [Clang][Wswitch-default] Warning for enum even completely covered the cases (PR #75900)

2023-12-18 Thread via cfe-commits

https://github.com/hstk30-hw created 
https://github.com/llvm/llvm-project/pull/75900

None

>From 735595ba881de8ab58a7d8f74a31534d90cf5b3a Mon Sep 17 00:00:00 2001
From: hstk-hw 
Date: Tue, 19 Dec 2023 14:54:16 +0800
Subject: [PATCH] test: add test for Wswitch-default

---
 clang/test/Sema/switch-default.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/clang/test/Sema/switch-default.c b/clang/test/Sema/switch-default.c
index 854b561b37c48e..342a97ee68b1e2 100644
--- a/clang/test/Sema/switch-default.c
+++ b/clang/test/Sema/switch-default.c
@@ -15,3 +15,14 @@ int f2(int a) {
   }
   return a;
 }
+
+// Warn even completely covered Enum cases(GCC compatibility).
+enum E { A, B };
+enum E check_enum(enum E e) {
+  switch (e) {// expected-warning {{'switch' missing 'default' 
label}}
+case A: break;
+case B: break;
+  }
+  return e;
+}
+

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


[llvm] [clang] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-18 Thread Craig Topper via cfe-commits

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


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits


@@ -104,3 +106,14 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+extern __global__ void external_func();
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

PatriosTheGreat wrote:

This case is checked by flag "-implicit-check-not=external_" at the line 6, so 
we can check that external is not mentioned anywhere at the device code.

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


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits

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


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits


@@ -104,3 +106,14 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+extern __global__ void external_func();
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+extern void* const external_arr[] = {};
+
+void* host_fun() {
+  (void) external_dep;
+  (void) external_arr;
+}

PatriosTheGreat wrote:

This case is checked by flag "-implicit-check-not=external_" at the line 6, so 
we can check that external is not mentioned anywhere at the device code.

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


[llvm] [clang] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-18 Thread Yeting Kuo via cfe-commits


@@ -165,6 +167,10 @@ def SP : GPRRegisterClass<(add X2)>;
 def SR07 : GPRRegisterClass<(add (sequence "X%u", 8, 9),
  (sequence "X%u", 18, 23))>;
 
+def GPRX1X5 : RegisterClass<"RISCV", [XLenVT], 32, (add X1, X5)> {

yetingk wrote:

Done.

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


[llvm] [clang] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-18 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/66043

>From 01222b781e3a0a925d2cdf793c54c7d6050f82af Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 12 Sep 2023 12:28:00 +0800
Subject: [PATCH 1/2] [RISCV] Add MC layer support for Zicfiss.

The patch adds the instructions in Zicfiss extension. Zicfiss extension is
to support shadow stack for control flow integrity.

Differential Revision: https://reviews.llvm.org/D152793
---
 .../test/Preprocessor/riscv-target-features.c |   9 ++
 llvm/docs/RISCVUsage.rst  |   2 +-
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  25 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   7 ++
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |   9 +-
 .../lib/Target/RISCV/RISCVInstrInfoZicfiss.td |  71 
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp   |   3 +
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|   9 ++
 llvm/test/MC/RISCV/attribute-arch.s   |   3 +
 llvm/test/MC/RISCV/compressed-zicfiss.s   |  53 +
 llvm/test/MC/RISCV/rv32zicfiss-invalid.s  |  17 +++
 llvm/test/MC/RISCV/rv64zicfiss-invalid.s  |  17 +++
 llvm/test/MC/RISCV/zicfiss-valid.s| 102 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   1 +
 15 files changed, 325 insertions(+), 5 deletions(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
 create mode 100644 llvm/test/MC/RISCV/compressed-zicfiss.s
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/zicfiss-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 35208b2eae8fbd..a480877dc5f2a0 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -119,6 +119,7 @@
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
+// CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
@@ -1278,3 +1279,11 @@
 // RUN: %clang --target=riscv64-unknown-linux-gnu -march=rv64i -E -dM %s \
 // RUN:   -munaligned-access -o - | FileCheck %s 
--check-prefix=CHECK-MISALIGNED-FAST
 // CHECK-MISALIGNED-FAST: __riscv_misaligned_fast 1
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32izicfiss0p4 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64izicfiss0p4 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// CHECK-ZICFISS-EXT: __riscv_zicfiss 4000{{$}}
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 842ebf45305952..6bb00c096fde36 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -196,7 +196,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
   LLVM implements assembler support for the `0.8.0 draft specification 
`_.
 
-``experimental-zicfilp``
+``experimental-zicfilp``, ``experimental-zicfiss``
   LLVM implements the `0.4 draft specification 
`__.
 
 ``experimental-zicond``
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 85c34dd6206307..c8f1047c2fd47c 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -175,6 +175,8 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 4}},
+{"zicfiss", RISCVExtensionVersion{0, 4}},
+
 {"zicond", RISCVExtensionVersion{1, 0}},
 
 {"ztso", RISCVExtensionVersion{0, 1}},
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 53e2b6b4d94ea0..8e7ba6a7029c29 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -74,6 +74,17 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst , 
uint32_t RegNo,
   return MCDisassembler::Success;
 }
 
+static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst , uint32_t RegNo,
+   uint64_t Address,
+   const MCDisassembler *Decoder) {
+  MCRegister Reg = RISCV::X0 + RegNo;
+  if (Reg != RISCV::X1 && Reg != RISCV::X5)
+return MCDisassembler::Fail;
+
+  Inst.addOperand(MCOperand::createReg(Reg));
+  return MCDisassembler::Success;
+}
+
 

[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-12-18 Thread Levon Ter-Grigoryan via cfe-commits

PatriosTheGreat wrote:

FYI

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


[libcxx] [compiler-rt] [libc] [clang-tools-extra] [llvm] [flang] [clang] [IR] Disallow ZeroInit for spirv.Image (PR #73887)

2023-12-18 Thread via cfe-commits

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


[libcxx] [compiler-rt] [libc] [llvm] [clang] [compiler-rt]Add lld into dependency for apple builds now that lld Mach-O backend is available (PR #75884)

2023-12-18 Thread Petr Hosek via cfe-commits

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


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


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-12-18 Thread Chuanqi Xu via cfe-commits

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


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-12-18 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

As I summarized in 
https://discourse.llvm.org/t/rfc-c-20-modules-introduce-thin-bmi-and-decls-hash/74755/43,
 people are interested in this direction, but it may be too early for us to 
implement it. Let's postpone this.

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


[clang] [C++20] [Modules] Introduce thin BMI (PR #71622)

2023-12-18 Thread Chuanqi Xu via cfe-commits

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


[clang] [C++20] [Modules] Introduce thin BMI (PR #71622)

2023-12-18 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Since there is no meaningful review opinions here, let's continue it in a new 
and clean PR: https://github.com/llvm/llvm-project/pull/75894

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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2023-12-18 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

My impression to the feedbacks is that every one of us loves the direction, 
while we may need more agreement on the user interfaces.

To make it easier to review, I split all the user interfaces related part to 
following patches. So that the current patch won't affect users.

This patch introduced an CC1 option `-emit-thin-module-interface` and tests the 
behavior for almost every places we can to make sure it is stable. While the 
diff is big, we can find most parts of it are boiler plate, so don't be panic.

I feel the patch good and hope we can land this quickly so that we can start 
the work to help users actually.



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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2023-12-18 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff cdc03926696d674c6aa61b55d5b509d7118ed023 
6354bb468098f25b869deae3a475bf6bcfe37d40 -- 
clang/include/clang/Frontend/FrontendActions.h 
clang/include/clang/Frontend/FrontendOptions.h 
clang/include/clang/Serialization/ASTWriter.h 
clang/lib/Frontend/CompilerInvocation.cpp 
clang/lib/Frontend/FrontendActions.cpp 
clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp 
clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp 
clang/lib/Serialization/GeneratePCH.cpp 
clang/test/CXX/basic/basic.link/p10-ex2.cpp 
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4-friend-in-reachable-class.cpp
 clang/test/Modules/InheritDefaultArguments.cppm 
clang/test/Modules/Reachability-Private.cpp 
clang/test/Modules/Reachability-func-default-arg.cpp 
clang/test/Modules/Reachability-func-ret.cpp 
clang/test/Modules/Reachability-template-default-arg.cpp 
clang/test/Modules/Reachability-template-instantiation.cpp 
clang/test/Modules/Reachability-using-templates.cpp 
clang/test/Modules/Reachability-using.cpp clang/test/Modules/concept.cppm 
clang/test/Modules/concept_differ.cppm clang/test/Modules/ctor.arg.dep.cppm 
clang/test/Modules/cxx20-10-1-ex1.cpp clang/test/Modules/cxx20-10-1-ex2.cpp 
clang/test/Modules/cxx20-10-2-ex2.cpp clang/test/Modules/cxx20-10-2-ex5.cpp 
clang/test/Modules/cxx20-10-3-ex1.cpp clang/test/Modules/cxx20-10-3-ex2.cpp 
clang/test/Modules/cxx20-10-5-ex1.cpp 
clang/test/Modules/cxx20-import-diagnostics-a.cpp 
clang/test/Modules/cxx20-import-diagnostics-b.cpp 
clang/test/Modules/cxx20-module-file-info-macros.cpp 
clang/test/Modules/deduction-guide.cppm 
clang/test/Modules/deduction-guide2.cppm 
clang/test/Modules/deduction-guide3.cppm clang/test/Modules/derived_class.cpp 
clang/test/Modules/duplicated-module-file-eq-module-name.cppm 
clang/test/Modules/enum-class.cppm 
clang/test/Modules/explicitly-specialized-template.cpp 
clang/test/Modules/export-language-linkage.cppm 
clang/test/Modules/ftime-trace.cppm 
clang/test/Modules/inconsistent-deduction-guide-linkage.cppm 
clang/test/Modules/inconsistent-export.cppm 
clang/test/Modules/inherited_arg.cppm 
clang/test/Modules/instantiation-argdep-lookup.cppm 
clang/test/Modules/lambdas.cppm 
clang/test/Modules/merge-concepts-cxx-modules.cpp 
clang/test/Modules/merge-constrained-friends.cpp 
clang/test/Modules/merge-lambdas.cppm 
clang/test/Modules/merge-requires-with-lambdas.cppm 
clang/test/Modules/merge-var-template-spec-cxx-modules.cppm 
clang/test/Modules/mismatch-diagnostics.cpp 
clang/test/Modules/module-init-duplicated-import.cppm 
clang/test/Modules/named-modules-adl-2.cppm 
clang/test/Modules/named-modules-adl-3.cppm 
clang/test/Modules/named-modules-adl.cppm 
clang/test/Modules/no-duplicate-codegen-in-GMF.cppm 
clang/test/Modules/pair-unambiguous-ctor.cppm 
clang/test/Modules/partial_specialization.cppm 
clang/test/Modules/placement-new-reachable.cpp 
clang/test/Modules/polluted-operator.cppm clang/test/Modules/pr54457.cppm 
clang/test/Modules/pr56916.cppm clang/test/Modules/pr58532.cppm 
clang/test/Modules/pr58716.cppm clang/test/Modules/pr59719.cppm 
clang/test/Modules/pr59780.cppm clang/test/Modules/pr5.cppm 
clang/test/Modules/pr60036.cppm clang/test/Modules/pr60085.cppm 
clang/test/Modules/pr60275.cppm clang/test/Modules/pr60486.cppm 
clang/test/Modules/pr60693.cppm clang/test/Modules/pr60775.cppm 
clang/test/Modules/pr60890.cppm clang/test/Modules/pr61065.cppm 
clang/test/Modules/pr61065_2.cppm clang/test/Modules/pr61067.cppm 
clang/test/Modules/pr61317.cppm clang/test/Modules/pr61783.cppm 
clang/test/Modules/pr61892.cppm clang/test/Modules/pr62158.cppm 
clang/test/Modules/pr62359.cppm clang/test/Modules/pr62589.cppm 
clang/test/Modules/pr62705.cppm clang/test/Modules/pr62796.cppm 
clang/test/Modules/pr62943.cppm clang/test/Modules/pr63544.cppm 
clang/test/Modules/pr63595.cppm clang/test/Modules/pr67627.cppm 
clang/test/Modules/pr67893.cppm clang/test/Modules/predefined.cpp 
clang/test/Modules/preferred_name.cppm 
clang/test/Modules/redefinition-merges.cppm 
clang/test/Modules/redundant-template-default-arg.cpp 
clang/test/Modules/redundant-template-default-arg2.cpp 
clang/test/Modules/redundant-template-default-arg3.cpp 
clang/test/Modules/search-partitions.cpp 
clang/test/Modules/seperated-member-function-definition-for-template-class.cppm 
clang/test/Modules/template-function-specialization.cpp 
clang/test/Modules/template-lambdas.cppm clang/test/Modules/template-pack.cppm 
clang/test/Modules/template_default_argument.cpp 
clang/unittests/Sema/SemaNoloadLookupTest.cpp 
clang/unittests/Serialization/ForceCheckFileInputTest.cpp 
clang/unittests/Serialization/NoCommentsTest.cpp 
clang/unittests/Serialization/VarDeclConstantInitTest.cpp
``





View the diff from clang-format here.


``diff

[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2023-12-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

Close https://github.com/llvm/llvm-project/issues/71034

See
https://discourse.llvm.org/t/rfc-c-20-modules-introduce-thin-bmi-and-decls-hash/74755

This patch introduces reduced BMI, which doesn't contain the definitions of 
functions and variables if its definitions won't contribute to the ABI.

Testing is a big part of the patch. We want to make sure the reduced BMI 
contains the same behavior with the existing and relatively stable fatBMI. This 
is pretty helpful for further reduction.

The user interfaces part it left to following patches to ease the reviewing.

---

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


108 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+3-1) 
- (modified) clang/include/clang/Frontend/FrontendActions.h (+13-1) 
- (modified) clang/include/clang/Frontend/FrontendOptions.h (+5-1) 
- (modified) clang/include/clang/Serialization/ASTWriter.h (+28-2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+2) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+30-6) 
- (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+2) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+18-14) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+38-7) 
- (modified) clang/lib/Serialization/GeneratePCH.cpp (+35-2) 
- (modified) clang/test/CXX/basic/basic.link/p10-ex2.cpp (+2) 
- (modified) 
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4-friend-in-reachable-class.cpp
 (+4-1) 
- (modified) clang/test/Modules/InheritDefaultArguments.cppm (+3) 
- (modified) clang/test/Modules/Reachability-Private.cpp (+10) 
- (modified) clang/test/Modules/Reachability-func-default-arg.cpp (+3) 
- (modified) clang/test/Modules/Reachability-func-ret.cpp (+3) 
- (modified) clang/test/Modules/Reachability-template-default-arg.cpp (+3) 
- (modified) clang/test/Modules/Reachability-template-instantiation.cpp (+4) 
- (modified) clang/test/Modules/Reachability-using-templates.cpp (+3) 
- (modified) clang/test/Modules/Reachability-using.cpp (+3) 
- (modified) clang/test/Modules/concept.cppm (+4) 
- (modified) clang/test/Modules/concept_differ.cppm (+5) 
- (modified) clang/test/Modules/ctor.arg.dep.cppm (+4) 
- (modified) clang/test/Modules/cxx20-10-1-ex1.cpp (+13) 
- (modified) clang/test/Modules/cxx20-10-1-ex2.cpp (+30-6) 
- (modified) clang/test/Modules/cxx20-10-2-ex2.cpp (+12) 
- (modified) clang/test/Modules/cxx20-10-2-ex5.cpp (+12) 
- (modified) clang/test/Modules/cxx20-10-3-ex1.cpp (+14) 
- (modified) clang/test/Modules/cxx20-10-3-ex2.cpp (+10) 
- (modified) clang/test/Modules/cxx20-10-5-ex1.cpp (+12) 
- (modified) clang/test/Modules/cxx20-import-diagnostics-a.cpp (+39) 
- (modified) clang/test/Modules/cxx20-import-diagnostics-b.cpp (+25) 
- (modified) clang/test/Modules/cxx20-module-file-info-macros.cpp (+3) 
- (modified) clang/test/Modules/deduction-guide.cppm (+3) 
- (modified) clang/test/Modules/deduction-guide2.cppm (+3) 
- (modified) clang/test/Modules/deduction-guide3.cppm (+3) 
- (modified) clang/test/Modules/derived_class.cpp (+3) 
- (modified) clang/test/Modules/duplicated-module-file-eq-module-name.cppm (+4) 
- (modified) clang/test/Modules/enum-class.cppm (+3) 
- (modified) clang/test/Modules/explicitly-specialized-template.cpp (+3) 
- (modified) clang/test/Modules/export-language-linkage.cppm (+7-1) 
- (modified) clang/test/Modules/ftime-trace.cppm (+9) 
- (modified) clang/test/Modules/inconsistent-deduction-guide-linkage.cppm (+6) 
- (modified) clang/test/Modules/inconsistent-export.cppm (+13) 
- (modified) clang/test/Modules/inherited_arg.cppm (+11) 
- (modified) clang/test/Modules/instantiation-argdep-lookup.cppm (+3) 
- (modified) clang/test/Modules/lambdas.cppm (+15) 
- (modified) clang/test/Modules/merge-concepts-cxx-modules.cpp (+12) 
- (modified) clang/test/Modules/merge-constrained-friends.cpp (+3) 
- (modified) clang/test/Modules/merge-lambdas.cppm (+4) 
- (modified) clang/test/Modules/merge-requires-with-lambdas.cppm (+19) 
- (modified) clang/test/Modules/merge-var-template-spec-cxx-modules.cppm (+5) 
- (modified) clang/test/Modules/mismatch-diagnostics.cpp (+11) 
- (modified) clang/test/Modules/module-init-duplicated-import.cppm (+11) 
- (modified) clang/test/Modules/named-modules-adl-2.cppm (+4) 
- (modified) clang/test/Modules/named-modules-adl-3.cppm (+17) 
- (modified) clang/test/Modules/named-modules-adl.cppm (+3) 
- (modified) clang/test/Modules/no-duplicate-codegen-in-GMF.cppm (+8) 
- (modified) clang/test/Modules/pair-unambiguous-ctor.cppm (+9) 
- (modified) clang/test/Modules/partial_specialization.cppm (+3) 
- (modified) clang/test/Modules/placement-new-reachable.cpp (+3) 
- (modified) clang/test/Modules/polluted-operator.cppm (+3) 
- (modified) clang/test/Modules/pr54457.cppm (+3) 
- (modified) clang/test/Modules/pr56916.cppm (+12) 

[clang] [Concepts] Avoid substituting into constraints for invalid TemplateDecls (PR #75697)

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


@@ -353,6 +353,10 @@ static ExprResult calculateConstraintSatisfaction(
   if (Inst.isInvalid())
 return ExprError();
 
+  // An empty expression for substitution failure messages.
+  if (Template && Template->isInvalidDecl())
+return ExprEmpty();

zyn0217 wrote:

My initial thought was to emit substitution details (`[T = double]` here). But 
now I feel like this is puzzling since we're now giving "constraints not 
satisfied" rather than "constraint must be of type 'bool'" in the case.

I'm a bit torn here: either we lose substitution details or produce inaccurate 
error-recovery messages. The latter matches what we're doing now in 
assertion-free builds. https://cpp1.godbolt.org/z/3KzPEYhn3

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


[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

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


@@ -283,6 +283,28 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   case CK_ToVoid:
 return discard(SubExpr);
 
+  case CK_IntegralRealToComplex:
+  case CK_FloatingRealToComplex: {
+// We're creating a complex value here, so we need to
+// allocate storage for it.
+if (!Initializing) {
+  std::optional LocalIndex =
+  allocateLocal(CE, /*IsExtended=*/true);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, CE))
+return false;
+}
+
+if (!this->visitArrayElemInit(0, SubExpr))

tbaederr wrote:

That's just how it works, i.e. in 
https://github.com/llvm/llvm-project/pull/75485/ we return `0` for 
`__imag(primitive)`, so we initialize the imaginary part to `0` here when 
creating a complex number from a primitive.

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


[mlir] [clang] [llvm] [clang-tools-extra] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)

2023-12-18 Thread via cfe-commits

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


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


[mlir] [clang] [llvm] [clang-tools-extra] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)

2023-12-18 Thread via cfe-commits


@@ -362,14 +362,20 @@ mlir::scf::tileUsingSCFForOp(RewriterBase , 
TilingInterface op,
   auto clonedOp = cast(
   cloneOpAndUpdateDestinationArgs(rewriter, op, clonedOpDestination));
 
-  // 5b. Tile the cloned operation.
+  // 5b. Early return cloned op if tiling is not happening.

MaheshRavishankar wrote:

Yeah, can't replace an op with itself. In theory you could say the caller 
should check for this and not do the replace, but that is strange. Let's go 
with this.

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


[lldb] [libc] [libcxx] [clang-tools-extra] [compiler-rt] [llvm] [mlir] [clang] [lld] [flang] Don't emit relax relocs like R_X86_64_REX_GOTPCRELX on X86 target for OPENMP internal vars. (PR #75564)

2023-12-18 Thread via cfe-commits

UmeshKalappa0 wrote:

> Scattering around `setDSOLocal(false)` makes the logic hard to understand. 
> I'd strongly prefer to fix the initial setting of dso_local when we create 
> the global variable. We can refactor the code to make that work.

@efriedma-quic  ,thank you for the suggestions and was not sure about adding 
dso_local for openmp weak linkage vars ,but from the weak semantics point ,its 
ok to add the dso_local for no-pic /no-pie code  ,so updated changes 
accordingly .

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


[libc] [libcxx] [compiler-rt] [llvm] [clang] [compiler-rt]Add lld into dependency for apple builds now that lld Mach-O backend is available (PR #75884)

2023-12-18 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/75884

>From 2af4eed3a742173b8f385a5b8222e74d1c6e71ed Mon Sep 17 00:00:00 2001
From: Mingming Liu 
Date: Mon, 18 Dec 2023 17:22:10 -0800
Subject: [PATCH] [compiler-rt]Add lld into dependency for apple builds now
 that lld Mach-O backend is available

---
 compiler-rt/test/profile/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/profile/CMakeLists.txt 
b/compiler-rt/test/profile/CMakeLists.txt
index 975e4c42f4b640..3057abebbe52cf 100644
--- a/compiler-rt/test/profile/CMakeLists.txt
+++ b/compiler-rt/test/profile/CMakeLists.txt
@@ -7,7 +7,7 @@ set(PROFILE_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} 
compiler-rt-headers)
 list(APPEND PROFILE_TEST_DEPS profile)
 if(NOT COMPILER_RT_STANDALONE_BUILD)
   list(APPEND PROFILE_TEST_DEPS llvm-profdata llvm-cov)
-  if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
+  if(COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
 list(APPEND PROFILE_TEST_DEPS lld)
   endif()
 endif()

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


[clang] [flang] [lld] [llvm] [lldb] [libc] [mlir] [libcxx] [compiler-rt] [clang-tools-extra] Don't emit relax relocs like R_X86_64_REX_GOTPCRELX on X86 target for OPENMP internal vars. (PR #75564)

2023-12-18 Thread via cfe-commits

https://github.com/UmeshKalappa0 updated 
https://github.com/llvm/llvm-project/pull/75564

>From 4125e4a709c594562fa6c52f045ba7442e3cb523 Mon Sep 17 00:00:00 2001
From: Umesh Kalappa 
Date: Fri, 15 Dec 2023 11:52:52 +0530
Subject: [PATCH 1/3] Problem :For Kernel Modules ,emitting the relocs like
 R_X86_64_REX_GOTPCRELX  for the OPENMP internal vars like
 https://godbolt.org/z/hhh7ozojz.

Solution : Mark the OpenMP internal variables with dso_local
conditionally for no-pic and no-pie ,then
a)reset the dso_local for thread_local and weak linkage vars.
---
 .../test/OpenMP/gomp_critical_dso_local_var.c | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/OpenMP/gomp_critical_dso_local_var.c

diff --git a/clang/test/OpenMP/gomp_critical_dso_local_var.c 
b/clang/test/OpenMP/gomp_critical_dso_local_var.c
new file mode 100644
index 00..915f6773bf67bf
--- /dev/null
+++ b/clang/test/OpenMP/gomp_critical_dso_local_var.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s 
--check-prefix=DSO_LOCAL
+
+// DSO_LOCAL-DAG: @.gomp_critical_user_.var = common dso_local global [8 x 
i32] zeroinitializer, align 8
+int omp_critical_test()
+{
+  int sum;
+  int known_sum;
+
+  sum=0;
+#pragma omp parallel
+  {
+int mysum=0;
+int i;
+#pragma omp for
+for (i = 0; i < 1000; i++)
+  mysum = mysum + i;
+#pragma omp critical
+sum = mysum +sum;
+  }
+  known_sum = 999 * 1000 / 2;
+  return (known_sum == sum);
+}
+

>From 842245de490ab15f8a901b94576ae4539c760e1e Mon Sep 17 00:00:00 2001
From: Umesh Kalappa 
Date: Fri, 15 Dec 2023 12:49:48 +0530
Subject: [PATCH 2/3] testcases are changed accordignly.

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp   | 2 ++
 clang/test/OpenMP/critical_codegen.cpp  | 6 +++---
 clang/test/OpenMP/critical_codegen_attr.cpp | 6 +++---
 clang/test/OpenMP/for_reduction_codegen.cpp | 8 
 clang/test/OpenMP/gomp_critical_dso_local_var.c | 1 -
 clang/test/OpenMP/simd_codegen.cpp  | 4 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp   | 8 
 7 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 7f7e6f53066644..183c757d72b8a7 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1793,6 +1793,8 @@ Address 
CGOpenMPRuntime::getAddrOfArtificialThreadPrivate(CodeGenFunction ,
   if (CGM.getLangOpts().OpenMP && CGM.getLangOpts().OpenMPUseTLS &&
   CGM.getTarget().isTLSSupported()) {
 GAddr->setThreadLocal(/*Val=*/true);
+/// reset the dso_local for thread_local.
+GAddr->setDSOLocal(/*Val=*/false);
 return Address(GAddr, GAddr->getValueType(),
CGM.getContext().getTypeAlignInChars(VarType));
   }
diff --git a/clang/test/OpenMP/critical_codegen.cpp 
b/clang/test/OpenMP/critical_codegen.cpp
index 24145d44d962e5..9a613161ac294a 100644
--- a/clang/test/OpenMP/critical_codegen.cpp
+++ b/clang/test/OpenMP/critical_codegen.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // ALL:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
-// ALL:   [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
+// ALL:   [[UNNAMED_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK1:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
 
 // ALL:   define {{.*}}void [[FOO:@.+]]()
 
diff --git a/clang/test/OpenMP/critical_codegen_attr.cpp 
b/clang/test/OpenMP/critical_codegen_attr.cpp
index 34d90a9e3a6e48..5f1a76e2ad0f1f 100644
--- a/clang/test/OpenMP/critical_codegen_attr.cpp
+++ b/clang/test/OpenMP/critical_codegen_attr.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // ALL:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
-// ALL:   [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
+// ALL:   [[UNNAMED_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK1:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
 
 // ALL:   define {{.*}}void [[FOO:@.+]]()
 
diff --git a/clang/test/OpenMP/for_reduction_codegen.cpp 
b/clang/test/OpenMP/for_reduction_codegen.cpp
index 893c606f8d7b9f..b128bd5d79c251 100644
--- a/clang/test/OpenMP/for_reduction_codegen.cpp
+++ b/clang/test/OpenMP/for_reduction_codegen.cpp
@@ -528,12 +528,12 @@ int main() {
 
 #endif
 //.
-// CHECK1: 

[clang] [openmp] [Clang][OpenMP] Fix mapping of structs to device (PR #75642)

2023-12-18 Thread Shilei Tian via cfe-commits

shiltian wrote:

The newly added test `offloading/struct_mapping_with_pointers.cpp` fails on 
NVIDIA GPUs as well.
```
 TEST 'libomptarget :: nvptx64-nvidia-cuda :: 
offloading/struct_mapping_with_pointers.cpp' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/gpfs/jlse-fs0/users/ac.shilei.tian/build/llvm/release/bin/clang++ -fopenmp 
-pthread   -I 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test -I 
/gpfs/jlse
-fs0/users/ac.shilei.tian/build/openmp/release/runtime/src -L 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget -L 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/ll
vm/release/./lib -L 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/runtime/src  
-Wl,-rpath,/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget
 -Wl,-rpa
th,/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/runtime/src 
-Wl,-rpath,/gpfs/jlse-fs0/users/ac.shilei.tian/build/llvm/release/./lib 
-Wl,-rpath,/soft/compilers/cuda/cud
a-11.8.0/targets/x86_64-linux/lib 
--libomptarget-nvptx-bc-path=/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget/DeviceRTL
 -fopenmp-targets=nvptx64-nvidia-cuda
 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
 -o /gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/releas
e/libomptarget/test/nvptx64-nvidia-cuda/offloading/Output/struct_mapping_with_pointers.cpp.tmp
 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget/libomptarget.d
evicertl.a && env LIBOMPTARGET_DEBUG=1 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget/test/nvptx64-nvidia-cuda/offloading/Output/struct_mapping_with_pointer
s.cpp.tmp 2>&1 | 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/llvm/release/bin/FileCheck 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test/offloading/struct
_mapping_with_pointers.cpp
# executed command: 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/llvm/release/bin/clang++ -fopenmp 
-pthread -I 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/
test -I /gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/runtime/src -L 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget -L 
/gpfs/jlse-fs0/users/ac.sh
ilei.tian/build/llvm/release/./lib -L 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/runtime/src 
-Wl,-rpath,/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libo
mptarget 
-Wl,-rpath,/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/runtime/src 
-Wl,-rpath,/gpfs/jlse-fs0/users/ac.shilei.tian/build/llvm/release/./lib 
-Wl,-rpath,/soft/c
ompilers/cuda/cuda-11.8.0/targets/x86_64-linux/lib 
--libomptarget-nvptx-bc-path=/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget/DeviceRTL
 -fopenmp-targets=nv
ptx64-nvidia-cuda 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
 -o /gpfs/jlse-fs0/users/ac.shilei.tian/bu
ild/openmp/release/libomptarget/test/nvptx64-nvidia-cuda/offloading/Output/struct_mapping_with_pointers.cpp.tmp
 /gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarg
et/libomptarget.devicertl.a
# executed command: env LIBOMPTARGET_DEBUG=1 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/openmp/release/libomptarget/test/nvptx64-nvidia-cuda/offloading/Output/struct_mapping_with_p
ointers.cpp.tmp
# executed command: 
/gpfs/jlse-fs0/users/ac.shilei.tian/build/llvm/release/bin/FileCheck 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test/offloading/str
uct_mapping_with_pointers.cpp
# .---command stderr
# | 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp:106:12:
 error: CHECK: expected string not found in inpu
t
# |  // CHECK: dat.datum[dat.arr[0][0]] = 0
# |^
# | :124:24: note: scanning from here
# | dat.val_more_datum = 18
# |^
# | :125:1: note: possible intended match here
# | dat.datum[dat.arr[0][0]] = 32542
# | ^
# |
# | Input file: 
# | Check file: 
/home/ac.shilei.tian/Documents/vscode/llvm-project/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
# |
# | -dump-input=help explains the following input dump.
# |
# | Input was:
# | <<
# |  .
# |  .
# |  .
# |119: omptarget --> Done unregistering library!
# |120: omptarget --> Deinit offload library!
# |121: TARGET CUDA RTL --> Missing 2 resources to be returned
# |122: dat.xi = 4
# |123: dat.val_datum = 8
# |124: dat.val_more_datum = 18
# | check:106'0X error: no match found
# |125: dat.datum[dat.arr[0][0]] = 32542
# | check:106'0 ~
# | check:106'1 ?   

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

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

MaxEW707 wrote:

MSVC STL requires the x64 adc intel intrinsics. I moved those to a separate 
file `adcintrin.h` that can be included from `immintrin.h` and `intrin0.h` for 
x64.

I also made a table [here 
](https://gist.github.com/MaxEW707/2f4bf26801bc1b6b088aa7a2fadba526) of all the 
intrinsics available with MSVC's `intrin0.h`, which intrinsics are used by MSVC 
STL, which are used by MSVC STL when compiled under clang and which intrinsics 
are provided as builtins from clang.

You will notice that the `_ReadWriteBarrier` compiler barrier isn't supported 
on arm by clang.  This [godbolt](https://godbolt.org/z/xEv3oEbK6) appears to 
corroborate that finding. I am not too worried about this since I believe 
Microsoft is dropping 32-bit ARM in a future Windows 11 update if my memory is 
correct.

The last table at the end shows the intrinsics that aren't implemented in clang 
but MSVC STL has workarounds using the clang intrinsics instead. We don't have 
to worry about supporting those.


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


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

2023-12-18 Thread via cfe-commits

ChipsSpectre wrote:

@shafik ok, done 

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


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

2023-12-18 Thread via cfe-commits

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


[clang] fix issue 73559. (PR #74926)

2023-12-18 Thread via cfe-commits

https://github.com/ChipsSpectre updated 
https://github.com/llvm/llvm-project/pull/74926

>From 9b703f6fcdb67eb921b3b5cf67b92bbd24144cf9 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Tue, 19 Dec 2023 05:14:06 +0100
Subject: [PATCH] [clang][Parse] `TryAnnotateCXXScopeToken` to be called only
 when parsing C++

Assume `TryAnnotateCXXScopeToken` to be parsing C++ code in all of its paths.

Fixes: https://github.com/llvm/llvm-project/issues/73559.
---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Parse/ParseDecl.cpp| 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 ++
 clang/test/Parser/cxx-in-c.c | 3 +++
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..ce2f56df1d3f3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -688,6 +688,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ece3698967e2f6..5d1c19ae07cb54 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3483,7 +3483,8 @@ void Parser::ParseDeclarationSpecifiers(
 
 case tok::coloncolon: // ::foo::bar
   // C++ scope specifier.  Annotate and loop, or bail out on error.
-  if (TryAnnotateCXXScopeToken(EnteringContext)) {
+  if (getLangOpts().CPlusPlus &&
+  TryAnnotateCXXScopeToken(EnteringContext)) {
 if (!DS.hasTypeSpecifier())
   DS.SetTypeSpecError();
 goto DoneWithDeclSpec;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 910112ecae964c..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2679,6 +2679,8 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes ,
const ParsedTemplateInfo ,
ParsingDeclRAIIObject *TemplateDiags) {
+  assert(getLangOpts().CPlusPlus &&
+ "Call sites of this function should be guarded by checking for C++");
   if (Tok.is(tok::at)) {
 if (getLangOpts().ObjC && NextToken().isObjCAtKeyword(tok::objc_defs))
   Diag(Tok, diag::err_at_defs_cxx);
diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index f5fa39bd0cb99b..034a44cdf12bfa 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,3 +3,6 @@
 // PR9137
 void f0(int x) : {}; // expected-error{{expected function body after function 
declarator}}
 void f1(int x) try {}; // expected-error{{expected function body after 
function declarator}}
+
+// GH73559
+::; // expected-error{{expected identifier or '('}}

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


[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-18 Thread Shafik Yaghmour via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s
+
+int f1(int a) {
+  switch (a) {// expected-warning {{'switch' missing 'default' 
label}}
+case 1: a++; break;
+case 2: a += 2; break;
+  }
+  return a;
+}

shafik wrote:

Might be worth adding a test case that shows that this warns even for 
completely covered switches e.g. https://godbolt.org/z/zbqr6P5xc

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


[clang] [libc] [clang-tools-extra] [compiler-rt] [flang] [libcxx] [mlir] [lldb] [lld] [llvm] GFX12: Add LoopDataPrefetchPass (PR #75625)

2023-12-18 Thread Matt Arsenault via cfe-commits

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


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


[llvm] [clang] [RISCV] Add sifive-p450 CPU. (PR #75760)

2023-12-18 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

Add test in `clang/test/Driver/riscv-cpus.c`?

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


[clang] Recommit [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (#73765) (PR #75890)

2023-12-18 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff cdc03926696d674c6aa61b55d5b509d7118ed023 
43ecdfdc5d96d1b53ccfc851e3dce8547b2f6fe9 -- 
clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c 
clang/lib/Driver/ToolChains/Gnu.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7e70626faf..38361d6889 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1806,16 +1806,16 @@ selectRISCVMultilib(const MultilibSet 
, StringRef Arch,
   // Check the XLEN explicitly.
   if (MLConfigISAInfo->getXLen() == 32) {
 NewMultilib.flag("-m32");
-NewMultilib.flag("-m64", /*Disallow*/true);
+NewMultilib.flag("-m64", /*Disallow*/ true);
   } else {
-NewMultilib.flag("-m32", /*Disallow*/true);
+NewMultilib.flag("-m32", /*Disallow*/ true);
 NewMultilib.flag("-m64");
   }
 
   // Atomic extension must be explicitly checked, soft and hard atomic
   // operation never co-work correctly.
   if (!MLConfigISAInfo->hasExtension("a"))
-NewMultilib.flag("-a", /*Disallow*/true);
+NewMultilib.flag("-a", /*Disallow*/ true);
 }
 
 if (Skip)

``




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


[clang] Recommit [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (#73765) (PR #75890)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Brandon Wu (4vtomat)


Changes

Extend the multi-lib re-use selection mechanism for RISC-V.
This funciton will try to re-use multi-lib if they are compatible.
Definition of compatible:
  - ABI must be the same.
  - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
is a subset of march=rv32imc.
  - march that contains atomic extension can't reuse multi-lib that
doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
march=rv32ima are not compatible, because software and hardware
atomic operation can't work together correctly.


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+126-1) 
- (added) clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c (+81) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 835215a83c4037..7e70626faf8cce 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1715,6 +1716,129 @@ static void findCSKYMultilibs(const Driver , const 
llvm::Triple ,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+selectRISCVMultilib(const MultilibSet , StringRef Arch,
+const Multilib::flags_list ,
+llvm::SmallVectorImpl ) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto  = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.starts_with("!march=") || Flag.starts_with("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (const auto  : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back all flags except -march.
+  if (!Flag.consume_front("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  llvm::Expected> MLConfigParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Flag, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might get a parsing error if rv32e in the list, we could just 
skip
+// that and process the rest of multi-lib configs.
+Skip = true;
+continue;
+  }
+  auto  = *MLConfigParseResult;
+
+  const llvm::RISCVISAInfo::OrderedExtensionMap  =
+  MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if (AllArchExts.insert(ExtName).second) {
+  addMultilibFlag(ISAInfo->hasExtension(ExtName),
+  Twine("-", ExtName).str(), NewFlags);
+}
+  }
+
+  // Check the XLEN explicitly.
+  if (MLConfigISAInfo->getXLen() == 32) {
+NewMultilib.flag("-m32");
+NewMultilib.flag("-m64", /*Disallow*/true);
+  } 

[clang] Recommit [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (#73765) (PR #75890)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




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

Author: Brandon Wu (4vtomat)


Changes

Extend the multi-lib re-use selection mechanism for RISC-V.
This funciton will try to re-use multi-lib if they are compatible.
Definition of compatible:
  - ABI must be the same.
  - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
is a subset of march=rv32imc.
  - march that contains atomic extension can't reuse multi-lib that
doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
march=rv32ima are not compatible, because software and hardware
atomic operation can't work together correctly.


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+126-1) 
- (added) clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c (+81) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 835215a83c4037..7e70626faf8cce 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1715,6 +1716,129 @@ static void findCSKYMultilibs(const Driver , const 
llvm::Triple ,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+selectRISCVMultilib(const MultilibSet , StringRef Arch,
+const Multilib::flags_list ,
+llvm::SmallVectorImpl ) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto  = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.starts_with("!march=") || Flag.starts_with("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (const auto  : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back all flags except -march.
+  if (!Flag.consume_front("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  llvm::Expected> MLConfigParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Flag, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might get a parsing error if rv32e in the list, we could just 
skip
+// that and process the rest of multi-lib configs.
+Skip = true;
+continue;
+  }
+  auto  = *MLConfigParseResult;
+
+  const llvm::RISCVISAInfo::OrderedExtensionMap  =
+  MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if (AllArchExts.insert(ExtName).second) {
+  addMultilibFlag(ISAInfo->hasExtension(ExtName),
+  Twine("-", ExtName).str(), NewFlags);
+}
+  }
+
+  // Check the XLEN explicitly.
+  if (MLConfigISAInfo->getXLen() == 32) {
+NewMultilib.flag("-m32");
+NewMultilib.flag("-m64", /*Disallow*/true);
+  

[clang] Recommit [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (#73765) (PR #75890)

2023-12-18 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/75890

Extend the multi-lib re-use selection mechanism for RISC-V.
This funciton will try to re-use multi-lib if they are compatible.
Definition of compatible:
  - ABI must be the same.
  - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
is a subset of march=rv32imc.
  - march that contains atomic extension can't reuse multi-lib that
doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
march=rv32ima are not compatible, because software and hardware
atomic operation can't work together correctly.


>From 43ecdfdc5d96d1b53ccfc851e3dce8547b2f6fe9 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Mon, 18 Dec 2023 15:52:14 +0800
Subject: [PATCH] Recommit [RISCV] Implement multi-lib reuse rule for RISC-V
 bare-metal toolchain (#73765)

Extend the multi-lib re-use selection mechanism for RISC-V.
This funciton will try to re-use multi-lib if they are compatible.
Definition of compatible:
  - ABI must be the same.
  - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
is a subset of march=rv32imc.
  - march that contains atomic extension can't reuse multi-lib that
doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
march=rv32ima are not compatible, because software and hardware
atomic operation can't work together correctly.
---
 clang/lib/Driver/ToolChains/Gnu.cpp   | 127 +-
 .../riscv-toolchain-gcc-multilib-reuse.c  |  81 +++
 2 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 835215a83c4037..7e70626faf8cce 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1715,6 +1716,129 @@ static void findCSKYMultilibs(const Driver , const 
llvm::Triple ,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+selectRISCVMultilib(const MultilibSet , StringRef Arch,
+const Multilib::flags_list ,
+llvm::SmallVectorImpl ) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto  = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.starts_with("!march=") || Flag.starts_with("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (const auto  : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back all flags except -march.
+  if (!Flag.consume_front("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  llvm::Expected> MLConfigParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Flag, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might get a parsing error if rv32e in the list, we could 

[lld] [llvm] [clang] [LTO] Improve diagnostics handling when parsing module-level inline assembly (PR #75726)

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


@@ -418,6 +418,8 @@ void BackendConsumer::anchor() { }
 } // namespace clang
 
 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo ) {
+  if (DI.getSeverity() == DS_Error)
+HasErrors = true;

MaskRay wrote:

I created https://github.com/llvm/llvm-project/pull/75889 to improve this case 
a bit.

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


[llvm] [clang] DiagnosticHandler: refactor error checking (PR #75889)

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


@@ -256,10 +256,13 @@ void LLVMContext::diagnose(const DiagnosticInfo ) {
   RS->emit(*OptDiagBase);
 
   // If there is a report handler, use it.
-  if (pImpl->DiagHandler &&
-  (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
-  pImpl->DiagHandler->handleDiagnostics(DI))
-return;
+  if (pImpl->DiagHandler) {
+if (DI.getSeverity() == DS_Error)
+  pImpl->DiagHandler->HasErrors = true;

MaskRay wrote:

This unfortunately exposes the detail of DiagnosticHandler, but the alternative 
(set HasErrors in `DiagnosticHandler::handleDiagnostics`) isn't better and a 
new client may forget to call the base.

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


[llvm] [clang] DiagnosticHandler: refactor error checking (PR #75889)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

In LLVMContext::diagnose, set `HasErrors` for `DS_Error` so that all
derived `DiagnosticHandler` have correct `HasErrors` information.

An alternative is to set `HasErrors` in
`DiagnosticHandler::handleDiagnostics`, but all derived
`handleDiagnostics` would have to call the base function.


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


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenAction.cpp (-2) 
- (modified) llvm/lib/IR/LLVMContext.cpp (+7-4) 
- (modified) llvm/tools/llc/llc.cpp (+3-14) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 4121a3709bc3af..753a8fd74fa696 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -418,8 +418,6 @@ void BackendConsumer::anchor() { }
 } // namespace clang
 
 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo ) {
-  if (DI.getSeverity() == DS_Error)
-HasErrors = true;
   BackendCon->DiagnosticHandlerImpl(DI);
   return true;
 }
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index 8ddf51537ec1af..57077e786efc26 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -256,10 +256,13 @@ void LLVMContext::diagnose(const DiagnosticInfo ) {
   RS->emit(*OptDiagBase);
 
   // If there is a report handler, use it.
-  if (pImpl->DiagHandler &&
-  (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
-  pImpl->DiagHandler->handleDiagnostics(DI))
-return;
+  if (pImpl->DiagHandler) {
+if (DI.getSeverity() == DS_Error)
+  pImpl->DiagHandler->HasErrors = true;
+if ((!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
+pImpl->DiagHandler->handleDiagnostics(DI))
+  return;
+  }
 
   if (!isDiagnosticEnabled(DI))
 return;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 8d906cf372878f..4a1957588a2243 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -307,16 +307,12 @@ static std::unique_ptr 
GetOutputStream(const char *TargetName,
 }
 
 struct LLCDiagnosticHandler : public DiagnosticHandler {
-  bool *HasError;
-  LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
   bool handleDiagnostics(const DiagnosticInfo ) override {
+DiagnosticHandler::handleDiagnostics(DI);
 if (DI.getKind() == llvm::DK_SrcMgr) {
   const auto  = cast(DI);
   const SMDiagnostic  = DISM.getSMDiag();
 
-  if (SMD.getKind() == SourceMgr::DK_Error)
-*HasError = true;
-
   SMD.print(nullptr, errs());
 
   // For testing purposes, we print the LocCookie here.
@@ -326,9 +322,6 @@ struct LLCDiagnosticHandler : public DiagnosticHandler {
   return true;
 }
 
-if (DI.getSeverity() == DS_Error)
-  *HasError = true;
-
 if (auto *Remark = dyn_cast())
   if (!Remark->isEnabled())
 return true;
@@ -413,9 +406,7 @@ int main(int argc, char **argv) {
   Context.setDiscardValueNames(DiscardValueNames);
 
   // Set a diagnostic handler that doesn't exit on the first error
-  bool HasError = false;
-  Context.setDiagnosticHandler(
-  std::make_unique());
+  Context.setDiagnosticHandler(std::make_unique());
 
   Expected> RemarksFileOrErr =
   setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
@@ -757,9 +748,7 @@ static int compileModule(char **argv, LLVMContext ) 
{
 
 PM.run(*M);
 
-auto HasError =
-((const LLCDiagnosticHandler 
*)(Context.getDiagHandlerPtr()))->HasError;
-if (*HasError)
+if (Context.getDiagHandlerPtr()->HasErrors)
   return 1;
 
 // Compare the two outputs and make sure they're the same

``




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


[llvm] [clang] DiagnosticHandler: refactor error checking (PR #75889)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Fangrui Song (MaskRay)


Changes

In LLVMContext::diagnose, set `HasErrors` for `DS_Error` so that all
derived `DiagnosticHandler` have correct `HasErrors` information.

An alternative is to set `HasErrors` in
`DiagnosticHandler::handleDiagnostics`, but all derived
`handleDiagnostics` would have to call the base function.


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


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenAction.cpp (-2) 
- (modified) llvm/lib/IR/LLVMContext.cpp (+7-4) 
- (modified) llvm/tools/llc/llc.cpp (+3-14) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 4121a3709bc3af..753a8fd74fa696 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -418,8 +418,6 @@ void BackendConsumer::anchor() { }
 } // namespace clang
 
 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo ) {
-  if (DI.getSeverity() == DS_Error)
-HasErrors = true;
   BackendCon->DiagnosticHandlerImpl(DI);
   return true;
 }
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index 8ddf51537ec1af..57077e786efc26 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -256,10 +256,13 @@ void LLVMContext::diagnose(const DiagnosticInfo ) {
   RS->emit(*OptDiagBase);
 
   // If there is a report handler, use it.
-  if (pImpl->DiagHandler &&
-  (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
-  pImpl->DiagHandler->handleDiagnostics(DI))
-return;
+  if (pImpl->DiagHandler) {
+if (DI.getSeverity() == DS_Error)
+  pImpl->DiagHandler->HasErrors = true;
+if ((!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
+pImpl->DiagHandler->handleDiagnostics(DI))
+  return;
+  }
 
   if (!isDiagnosticEnabled(DI))
 return;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 8d906cf372878f..4a1957588a2243 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -307,16 +307,12 @@ static std::unique_ptr 
GetOutputStream(const char *TargetName,
 }
 
 struct LLCDiagnosticHandler : public DiagnosticHandler {
-  bool *HasError;
-  LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
   bool handleDiagnostics(const DiagnosticInfo ) override {
+DiagnosticHandler::handleDiagnostics(DI);
 if (DI.getKind() == llvm::DK_SrcMgr) {
   const auto  = cast(DI);
   const SMDiagnostic  = DISM.getSMDiag();
 
-  if (SMD.getKind() == SourceMgr::DK_Error)
-*HasError = true;
-
   SMD.print(nullptr, errs());
 
   // For testing purposes, we print the LocCookie here.
@@ -326,9 +322,6 @@ struct LLCDiagnosticHandler : public DiagnosticHandler {
   return true;
 }
 
-if (DI.getSeverity() == DS_Error)
-  *HasError = true;
-
 if (auto *Remark = dyn_cast())
   if (!Remark->isEnabled())
 return true;
@@ -413,9 +406,7 @@ int main(int argc, char **argv) {
   Context.setDiscardValueNames(DiscardValueNames);
 
   // Set a diagnostic handler that doesn't exit on the first error
-  bool HasError = false;
-  Context.setDiagnosticHandler(
-  std::make_unique());
+  Context.setDiagnosticHandler(std::make_unique());
 
   Expected> RemarksFileOrErr =
   setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
@@ -757,9 +748,7 @@ static int compileModule(char **argv, LLVMContext ) 
{
 
 PM.run(*M);
 
-auto HasError =
-((const LLCDiagnosticHandler 
*)(Context.getDiagHandlerPtr()))->HasError;
-if (*HasError)
+if (Context.getDiagHandlerPtr()->HasErrors)
   return 1;
 
 // Compare the two outputs and make sure they're the same

``




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


[clang] [llvm] DiagnosticHandler: refactor error checking (PR #75889)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Fangrui Song (MaskRay)


Changes

In LLVMContext::diagnose, set `HasErrors` for `DS_Error` so that all
derived `DiagnosticHandler` have correct `HasErrors` information.

An alternative is to set `HasErrors` in
`DiagnosticHandler::handleDiagnostics`, but all derived
`handleDiagnostics` would have to call the base function.


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


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenAction.cpp (-2) 
- (modified) llvm/lib/IR/LLVMContext.cpp (+7-4) 
- (modified) llvm/tools/llc/llc.cpp (+3-14) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 4121a3709bc3af..753a8fd74fa696 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -418,8 +418,6 @@ void BackendConsumer::anchor() { }
 } // namespace clang
 
 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo ) {
-  if (DI.getSeverity() == DS_Error)
-HasErrors = true;
   BackendCon->DiagnosticHandlerImpl(DI);
   return true;
 }
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index 8ddf51537ec1af..57077e786efc26 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -256,10 +256,13 @@ void LLVMContext::diagnose(const DiagnosticInfo ) {
   RS->emit(*OptDiagBase);
 
   // If there is a report handler, use it.
-  if (pImpl->DiagHandler &&
-  (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
-  pImpl->DiagHandler->handleDiagnostics(DI))
-return;
+  if (pImpl->DiagHandler) {
+if (DI.getSeverity() == DS_Error)
+  pImpl->DiagHandler->HasErrors = true;
+if ((!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
+pImpl->DiagHandler->handleDiagnostics(DI))
+  return;
+  }
 
   if (!isDiagnosticEnabled(DI))
 return;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 8d906cf372878f..4a1957588a2243 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -307,16 +307,12 @@ static std::unique_ptr 
GetOutputStream(const char *TargetName,
 }
 
 struct LLCDiagnosticHandler : public DiagnosticHandler {
-  bool *HasError;
-  LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
   bool handleDiagnostics(const DiagnosticInfo ) override {
+DiagnosticHandler::handleDiagnostics(DI);
 if (DI.getKind() == llvm::DK_SrcMgr) {
   const auto  = cast(DI);
   const SMDiagnostic  = DISM.getSMDiag();
 
-  if (SMD.getKind() == SourceMgr::DK_Error)
-*HasError = true;
-
   SMD.print(nullptr, errs());
 
   // For testing purposes, we print the LocCookie here.
@@ -326,9 +322,6 @@ struct LLCDiagnosticHandler : public DiagnosticHandler {
   return true;
 }
 
-if (DI.getSeverity() == DS_Error)
-  *HasError = true;
-
 if (auto *Remark = dyn_cast())
   if (!Remark->isEnabled())
 return true;
@@ -413,9 +406,7 @@ int main(int argc, char **argv) {
   Context.setDiscardValueNames(DiscardValueNames);
 
   // Set a diagnostic handler that doesn't exit on the first error
-  bool HasError = false;
-  Context.setDiagnosticHandler(
-  std::make_unique());
+  Context.setDiagnosticHandler(std::make_unique());
 
   Expected> RemarksFileOrErr =
   setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
@@ -757,9 +748,7 @@ static int compileModule(char **argv, LLVMContext ) 
{
 
 PM.run(*M);
 
-auto HasError =
-((const LLCDiagnosticHandler 
*)(Context.getDiagHandlerPtr()))->HasError;
-if (*HasError)
+if (Context.getDiagHandlerPtr()->HasErrors)
   return 1;
 
 // Compare the two outputs and make sure they're the same

``




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


[llvm] [clang] DiagnosticHandler: refactor error checking (PR #75889)

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

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/75889

In LLVMContext::diagnose, set `HasErrors` for `DS_Error` so that all
derived `DiagnosticHandler` have correct `HasErrors` information.

An alternative is to set `HasErrors` in
`DiagnosticHandler::handleDiagnostics`, but all derived
`handleDiagnostics` would have to call the base function.


>From 855adfece4c0c70b0198bbffa1831ccf7060e715 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 18 Dec 2023 19:32:52 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/CodeGenAction.cpp |  2 --
 llvm/lib/IR/LLVMContext.cpp | 11 +++
 llvm/tools/llc/llc.cpp  | 17 +++--
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 4121a3709bc3af..753a8fd74fa696 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -418,8 +418,6 @@ void BackendConsumer::anchor() { }
 } // namespace clang
 
 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo ) {
-  if (DI.getSeverity() == DS_Error)
-HasErrors = true;
   BackendCon->DiagnosticHandlerImpl(DI);
   return true;
 }
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index 8ddf51537ec1af..57077e786efc26 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -256,10 +256,13 @@ void LLVMContext::diagnose(const DiagnosticInfo ) {
   RS->emit(*OptDiagBase);
 
   // If there is a report handler, use it.
-  if (pImpl->DiagHandler &&
-  (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
-  pImpl->DiagHandler->handleDiagnostics(DI))
-return;
+  if (pImpl->DiagHandler) {
+if (DI.getSeverity() == DS_Error)
+  pImpl->DiagHandler->HasErrors = true;
+if ((!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
+pImpl->DiagHandler->handleDiagnostics(DI))
+  return;
+  }
 
   if (!isDiagnosticEnabled(DI))
 return;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 8d906cf372878f..4a1957588a2243 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -307,16 +307,12 @@ static std::unique_ptr 
GetOutputStream(const char *TargetName,
 }
 
 struct LLCDiagnosticHandler : public DiagnosticHandler {
-  bool *HasError;
-  LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
   bool handleDiagnostics(const DiagnosticInfo ) override {
+DiagnosticHandler::handleDiagnostics(DI);
 if (DI.getKind() == llvm::DK_SrcMgr) {
   const auto  = cast(DI);
   const SMDiagnostic  = DISM.getSMDiag();
 
-  if (SMD.getKind() == SourceMgr::DK_Error)
-*HasError = true;
-
   SMD.print(nullptr, errs());
 
   // For testing purposes, we print the LocCookie here.
@@ -326,9 +322,6 @@ struct LLCDiagnosticHandler : public DiagnosticHandler {
   return true;
 }
 
-if (DI.getSeverity() == DS_Error)
-  *HasError = true;
-
 if (auto *Remark = dyn_cast())
   if (!Remark->isEnabled())
 return true;
@@ -413,9 +406,7 @@ int main(int argc, char **argv) {
   Context.setDiscardValueNames(DiscardValueNames);
 
   // Set a diagnostic handler that doesn't exit on the first error
-  bool HasError = false;
-  Context.setDiagnosticHandler(
-  std::make_unique());
+  Context.setDiagnosticHandler(std::make_unique());
 
   Expected> RemarksFileOrErr =
   setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
@@ -757,9 +748,7 @@ static int compileModule(char **argv, LLVMContext ) 
{
 
 PM.run(*M);
 
-auto HasError =
-((const LLCDiagnosticHandler 
*)(Context.getDiagHandlerPtr()))->HasError;
-if (*HasError)
+if (Context.getDiagHandlerPtr()->HasErrors)
   return 1;
 
 // Compare the two outputs and make sure they're the same

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


[clang] fix issue 73559. (PR #74926)

2023-12-18 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

In the future please add a more description title to your PR. Your summary is 
great though.

Also in this case this is a clang and parser fix so you should prefix your 
title with `[Clang][Parser]`

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


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

2023-12-18 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@sam-mccall ping~

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] fix issue 73559. (PR #74926)

2023-12-18 Thread Shafik Yaghmour via cfe-commits


@@ -641,6 +641,8 @@ Bug Fixes in This Version
   Fixes (`#67317 `_)
 - Clang now properly diagnoses use of stand-alone OpenMP directives after a
   label (including ``case`` or ``default`` labels).
+- Fix crash when using C++ only tokens like ``::`` in C compiler clang.

shafik wrote:

It looks like you added your note in the middle of another note that has a 
before and after description of the bug they fixed.

Please make sure you move this to the end of the list. 

After that I think this is good.

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


[libcxx] [clang] [llvm] [compiler-rt] [libc] [compiler-rt]Add lld into dependency for apple builds now that lld Mach-O backend is available (PR #75884)

2023-12-18 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

thanks for the reviews!

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


[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

2023-12-18 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

We need a release note and please add a more detailed summary. A description of 
the problem being solved and the solution to the fix provides.

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


[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

2023-12-18 Thread Shafik Yaghmour via cfe-commits


@@ -283,6 +283,28 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   case CK_ToVoid:
 return discard(SubExpr);
 
+  case CK_IntegralRealToComplex:
+  case CK_FloatingRealToComplex: {
+// We're creating a complex value here, so we need to
+// allocate storage for it.
+if (!Initializing) {
+  std::optional LocalIndex =
+  allocateLocal(CE, /*IsExtended=*/true);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, CE))
+return false;
+}
+
+if (!this->visitArrayElemInit(0, SubExpr))

shafik wrote:

Why the different init for first and second element? Complex is basiclly an 
array underneath: https://eel.is/c++draft/complex.numbers#general-4 but I am 
not sure I understand the difference in how we init the first and second 
element. 

Seems like a comment would be helpful.

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


[libcxx] [clang] [llvm] [compiler-rt] [libc] [compiler-rt]Add lld into dependency for apple builds now that lld Mach-O backend is available (PR #75884)

2023-12-18 Thread Shoaib Meenai via cfe-commits

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

LGTM, thanks!

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


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Erich Keane via cfe-commits

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


[clang] fdee0a3 - [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (#75052)

2023-12-18 Thread via cfe-commits

Author: Erich Keane
Date: 2023-12-18T18:53:37-08:00
New Revision: fdee0a35d9da1febfab20ead8565cf6167103b51

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

LOG: [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (#75052)

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing. While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.

Added: 
clang/test/ParserOpenACC/parse-clauses.c

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/OpenACCKinds.h
clang/lib/Parse/ParseOpenACC.cpp
clang/test/ParserOpenACC/parse-cache-construct.c
clang/test/ParserOpenACC/parse-constructs.c
clang/test/ParserOpenACC/parse-wait-construct.c
clang/test/ParserOpenACC/unimplemented.c
clang/test/ParserOpenACC/unimplemented.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;

diff  --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..3117d584d347b9 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,30 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+/// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  // 'finalize' clause, allowed on 'exit data' directive.
+  Finalize,
+  // 'if_present' clause, allowed on 'host_data' and 'update' directives.
+  IfPresent,
+  // 'seq' clause, allowed on 'loop' and 'routine' directives.
+  Seq,
+  // 'independent' clause, allowed on 'loop' directives.
+  Independent,
+  // 'auto' clause, allowed on 'loop' directives.
+  Auto,
+  // 'worker' clause, allowed on 'loop' and 'routine' directives.
+  Worker,
+  // 'vector' clause, allowed on 'loop' and 'routine' directives. Takes no
+  // arguments for 'routine', so the 'loop' version is not yet implemented
+  // completely.
+  Vector,
+  // 'nohost' clause, allowed on 'routine' directives.
+  NoHost,
+  // Represents an invalid clause, for the purposes of parsing.
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H

diff  --git a/clang/lib/Parse/ParseOpenACC.cpp 
b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..67325f0a286a99 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+ Tok.getIdentifierInfo()->getName())
+  .Case("auto", OpenACCClauseKind::Auto)
+  .Case("finalize", OpenACCClauseKind::Finalize)
+  .Case("if_present", OpenACCClauseKind::IfPresent)
+  .Case("independent", OpenACCClauseKind::Independent)
+  .Case("nohost", OpenACCClauseKind::NoHost)
+  .Case("seq", OpenACCClauseKind::Seq)
+  .Case("vector", OpenACCClauseKind::Vector)
+  .Case("worker", OpenACCClauseKind::Worker)
+  .Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ 

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/75052

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH 1/4] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? 

[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

2023-12-18 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Can we please have a more detailed summary for this PR? We rely on more 
detailed summaries in git logs.

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


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Shafik Yaghmour via cfe-commits


@@ -2061,13 +2070,13 @@ DeclResult Sema::CheckClassTemplate(
   if (!(TUK == TUK_Friend && CurContext->isDependentContext()) &&
   CheckTemplateParameterList(
   TemplateParams,
-  PrevClassTemplate
-  ? PrevClassTemplate->getMostRecentDecl()->getTemplateParameters()
-  : nullptr,
+  PrevClassTemplate ? GetTemplateParameterList(PrevClassTemplate)
+: nullptr,
   (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
SemanticContext->isDependentContext())
   ? TPC_ClassTemplateMember
-  : TUK == TUK_Friend ? TPC_FriendClassTemplate : 
TPC_ClassTemplate,
+  : TUK == TUK_Friend ? TPC_FriendClassTemplate

shafik wrote:

This looks like an unrelated change and it looks funny.

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


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Can we please add more detailed summaries, we want the git log to be sufficient 
for triaging various issues without having to dig into each commit individually.

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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-18 Thread via cfe-commits

koachan wrote:

Ping?

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


[compiler-rt] [llvm] [libc] [libcxx] [clang] [compiler-rt]Add lld into dependency for apple builds now that lld Mach-O backend is available (PR #75884)

2023-12-18 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/75884

>From 2af4eed3a742173b8f385a5b8222e74d1c6e71ed Mon Sep 17 00:00:00 2001
From: Mingming Liu 
Date: Mon, 18 Dec 2023 17:22:10 -0800
Subject: [PATCH] [compiler-rt]Add lld into dependency for apple builds now
 that lld Mach-O backend is available

---
 compiler-rt/test/profile/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/profile/CMakeLists.txt 
b/compiler-rt/test/profile/CMakeLists.txt
index 975e4c42f4b640..3057abebbe52cf 100644
--- a/compiler-rt/test/profile/CMakeLists.txt
+++ b/compiler-rt/test/profile/CMakeLists.txt
@@ -7,7 +7,7 @@ set(PROFILE_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} 
compiler-rt-headers)
 list(APPEND PROFILE_TEST_DEPS profile)
 if(NOT COMPILER_RT_STANDALONE_BUILD)
   list(APPEND PROFILE_TEST_DEPS llvm-profdata llvm-cov)
-  if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
+  if(COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
 list(APPEND PROFILE_TEST_DEPS lld)
   endif()
 endif()

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2023-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

It seems we were forgetting to call `checkArgsForPlaceholders` on the placement 
arguments of new-expressions in Sema. I don't think that was intendedā€”at least 
doing so doesn't seem to break anythingā€”so this pr adds that.

This also fixes #65053

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


5 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+4) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+4-8) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+3) 
- (added) clang/test/CodeGenCXX/ms-property-new.cpp (+52) 
- (added) clang/test/SemaCXX/ms-property-new.cpp (+44) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a4f8fc1845b1ce..90be0a648f0124 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2108,6 +2108,10 @@ class Sema final {
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
 
+  /// Check an argument list for placeholders that we won't try to
+  /// handle later.
+  bool CheckArgsForPlaceholders(MultiExprArg args);
+
   /// Build a function type.
   ///
   /// This routine checks the function type according to C++ rules and
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c7185d56cc9973..2442c1e104055b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5058,8 +5058,6 @@ static QualType getDependentArraySubscriptType(Expr *LHS, 
Expr *RHS,
   return Result->isDependentType() ? Result : Ctx.DependentTy;
 }
 
-static bool checkArgsForPlaceholders(Sema , MultiExprArg args);
-
 ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base,
  SourceLocation lbLoc,
  MultiExprArg ArgExprs,
@@ -5163,7 +5161,7 @@ ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr 
*base,
   return ExprError();
 ArgExprs[0] = result.get();
   } else {
-if (checkArgsForPlaceholders(*this, ArgExprs))
+if (CheckArgsForPlaceholders(ArgExprs))
   return ExprError();
   }
 
@@ -6912,15 +6910,13 @@ static bool isPlaceholderToRemoveAsArg(QualType type) {
   llvm_unreachable("bad builtin type kind");
 }
 
-/// Check an argument list for placeholders that we won't try to
-/// handle later.
-static bool checkArgsForPlaceholders(Sema , MultiExprArg args) {
+bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
   // Apply this processing to all the arguments at once instead of
   // dying at the first failure.
   bool hasInvalid = false;
   for (size_t i = 0, e = args.size(); i != e; i++) {
 if (isPlaceholderToRemoveAsArg(args[i]->getType())) {
-  ExprResult result = S.CheckPlaceholderExpr(args[i]);
+  ExprResult result = CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
 }
@@ -7194,7 +7190,7 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
   if (Result.isInvalid()) return ExprError();
   Fn = Result.get();
 
-  if (checkArgsForPlaceholders(*this, ArgExprs))
+  if (CheckArgsForPlaceholders(ArgExprs))
 return ExprError();
 
   if (getLangOpts().CPlusPlus) {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 081b568762ae22..49f0921ce324fc 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2286,6 +2286,9 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   bool PassAlignment = getLangOpts().AlignedAllocation &&
Alignment > NewAlignment;
 
+  if (CheckArgsForPlaceholders(PlacementArgs))
+return ExprError();
+
   AllocationFunctionScope Scope = UseGlobal ? AFS_Global : AFS_Both;
   if (!AllocType->isDependentType() &&
   !Expr::hasAnyTypeDependentArguments(PlacementArgs) &&
diff --git a/clang/test/CodeGenCXX/ms-property-new.cpp 
b/clang/test/CodeGenCXX/ms-property-new.cpp
new file mode 100644
index 00..e21ec3d6702f62
--- /dev/null
+++ b/clang/test/CodeGenCXX/ms-property-new.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t 
%s
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility 
-include-pch %t -verify %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+struct S {
+  int GetX() { return 42; }
+  __declspec(property(get=GetX)) int x;
+
+  int GetY(int i, int j) { return i+j; }
+  __declspec(property(get=GetY)) int y[];
+
+  void* operator new(__SIZE_TYPE__, int);
+};
+
+template 
+struct TS {
+  T GetT() { return T(); }
+  __declspec(property(get=GetT)) T t;
+
+  T GetR(T i, T j) { return i+j; }
+  __declspec(property(get=GetR)) T r[];
+};
+
+// CHECK-LABEL: main
+int main(int argc, char **argv) {
+  S *s;
+  TS *ts;
+

[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2023-12-18 Thread via cfe-commits

Sirraide wrote:

CC @AaronBallman 

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2023-12-18 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/75883

It seems we were forgetting to call `checkArgsForPlaceholders` on the placement 
arguments of new-expressions in Sema. I don't think that was intendedā€”at least 
doing so doesn't seem to break anythingā€”so this pr adds that.

This also fixes #65053

>From f51b382fd33d4cf3f75bdaa172bb8697a6cadc9e Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 19 Dec 2023 02:48:25 +0100
Subject: [PATCH] [Clang] Support MSPropertyRefExpr as placement arg to
 new-expression

---
 clang/include/clang/Sema/Sema.h   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   | 12 ++
 clang/lib/Sema/SemaExprCXX.cpp|  3 ++
 clang/test/CodeGenCXX/ms-property-new.cpp | 52 +++
 clang/test/SemaCXX/ms-property-new.cpp| 44 +++
 5 files changed, 107 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/ms-property-new.cpp
 create mode 100644 clang/test/SemaCXX/ms-property-new.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a4f8fc1845b1ce..90be0a648f0124 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2108,6 +2108,10 @@ class Sema final {
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
 
+  /// Check an argument list for placeholders that we won't try to
+  /// handle later.
+  bool CheckArgsForPlaceholders(MultiExprArg args);
+
   /// Build a function type.
   ///
   /// This routine checks the function type according to C++ rules and
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c7185d56cc9973..2442c1e104055b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5058,8 +5058,6 @@ static QualType getDependentArraySubscriptType(Expr *LHS, 
Expr *RHS,
   return Result->isDependentType() ? Result : Ctx.DependentTy;
 }
 
-static bool checkArgsForPlaceholders(Sema , MultiExprArg args);
-
 ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base,
  SourceLocation lbLoc,
  MultiExprArg ArgExprs,
@@ -5163,7 +5161,7 @@ ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr 
*base,
   return ExprError();
 ArgExprs[0] = result.get();
   } else {
-if (checkArgsForPlaceholders(*this, ArgExprs))
+if (CheckArgsForPlaceholders(ArgExprs))
   return ExprError();
   }
 
@@ -6912,15 +6910,13 @@ static bool isPlaceholderToRemoveAsArg(QualType type) {
   llvm_unreachable("bad builtin type kind");
 }
 
-/// Check an argument list for placeholders that we won't try to
-/// handle later.
-static bool checkArgsForPlaceholders(Sema , MultiExprArg args) {
+bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
   // Apply this processing to all the arguments at once instead of
   // dying at the first failure.
   bool hasInvalid = false;
   for (size_t i = 0, e = args.size(); i != e; i++) {
 if (isPlaceholderToRemoveAsArg(args[i]->getType())) {
-  ExprResult result = S.CheckPlaceholderExpr(args[i]);
+  ExprResult result = CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
 }
@@ -7194,7 +7190,7 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
   if (Result.isInvalid()) return ExprError();
   Fn = Result.get();
 
-  if (checkArgsForPlaceholders(*this, ArgExprs))
+  if (CheckArgsForPlaceholders(ArgExprs))
 return ExprError();
 
   if (getLangOpts().CPlusPlus) {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 081b568762ae22..49f0921ce324fc 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2286,6 +2286,9 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   bool PassAlignment = getLangOpts().AlignedAllocation &&
Alignment > NewAlignment;
 
+  if (CheckArgsForPlaceholders(PlacementArgs))
+return ExprError();
+
   AllocationFunctionScope Scope = UseGlobal ? AFS_Global : AFS_Both;
   if (!AllocType->isDependentType() &&
   !Expr::hasAnyTypeDependentArguments(PlacementArgs) &&
diff --git a/clang/test/CodeGenCXX/ms-property-new.cpp 
b/clang/test/CodeGenCXX/ms-property-new.cpp
new file mode 100644
index 00..e21ec3d6702f62
--- /dev/null
+++ b/clang/test/CodeGenCXX/ms-property-new.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t 
%s
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility 
-include-pch %t -verify %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+struct S {
+  int GetX() { return 42; }
+  __declspec(property(get=GetX)) int x;
+
+  int GetY(int i, int j) { return i+j; }
+  

[clang] [clang-tools-extra] [clang-tidy]Ā Added new check to detect redundant inline keyword (PR #73069)

2023-12-18 Thread FĆ©lix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 01/13] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20de?=
 =?UTF-8?q?tect=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..811310db8c721a 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..3ce7bfecaecba6 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 00..e73b570df75915
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] [flang] [flang][driver] Rename `flang-new` as `flang` (PR #74377)

2023-12-18 Thread via cfe-commits

h-vetinari wrote:

It appears this PR now has conflicts that need resolving...

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-12-18 Thread Daniel Chen via cfe-commits

DanielCChen wrote:

I see. So Fortran and C interoperability of F2003/F2008 is not supported yet in 
Flang? Those ~100ish regression test cases we have were passing before this PR 
though. 
Unfortunately, those test cases are not made public available yet. I think I 
can copy the source code of one test case here, but it needs to be run 
manually. Please let me know if that is desired to help debug the reason of the 
regression.

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


[clang] [libunwind] [clang-tools-extra] [llvm] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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


@@ -2974,6 +2966,39 @@ bool UnwindCursor::getFunctionName(char *buf, 
size_t bufLen,
  buf, bufLen, offset);
 }
 
+#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+template 
+bool UnwindCursor::isReadableAddr(const pint_t addr) const {
+  // This code is heavily based on Abseil's 'address_is_readable.cc',
+  // which is Copyright Abseil Authors (2017), and provided under
+  // the Apache License 2.0.
+
+  // Align to 8-bytes.
+  const auto alignedAddr = addr & ~pint_t{7};
+  const auto sigsetAddr = reinterpret_cast(alignedAddr);
+  // We have to check that addr is nullptr because sigprocmask allows that
+  // as an argument without failure.
+  if (!sigsetAddr)
+return false;
+
+  // We MUST use the raw sigprocmask syscall here, as wrappers may try to
+  // access sigsetAddr which may cause a SIGSEGV. The raw syscall however is
+  // safe. Additionally, we need to pass the kernel_sigset_size, which is
+  // different from libc sizeof(sigset_t). Some archs have sigset_t
+  // defined as unsigned long, so let's use that.
+  const auto approxKernelSigsetSize = sizeof(unsigned long);
+  [[maybe_unused]] const int Result =
+  syscall(SYS_rt_sigprocmask, /*how=*/~0, sigsetAddr, sigsetAddr,

MaskRay wrote:

`oldsigset` should be nullptr, otherwise also checks that `sigsetAddr` is 
writable

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


[clang-tools-extra] [clang] [llvm] [libc] [flang] [compiler-rt] [libcxx] [IR] Disallow ZeroInit for spirv.Image (PR #73887)

2023-12-18 Thread Wenju He via cfe-commits

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/73887

>From e369b5d62094c9b48f3c33075d764c115a208a74 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Thu, 30 Nov 2023 09:57:06 +0800
Subject: [PATCH] [IR] Disallow ZeroInit for spirv.Image

According to spirv spec, OpConstantNull's result type can't be image
type. So we can't generate zeroinitializer for spirv.Image.
---
 llvm/lib/IR/Type.cpp| 2 ++
 llvm/unittests/Transforms/Utils/ValueMapperTest.cpp | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 3d2e203a20dac7..e3a09018ad8b98 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -841,6 +841,8 @@ struct TargetTypeInfo {
 static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
   LLVMContext  = Ty->getContext();
   StringRef Name = Ty->getName();
+  if (Name.equals("spirv.Image"))
+return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal);
   if (Name.startswith("spirv."))
 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
   TargetExtType::CanBeGlobal);
diff --git a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp 
b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
index 17083b3846430d..c0c9d383ac1816 100644
--- a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
+++ b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
@@ -423,7 +423,7 @@ TEST(ValueMapperTest, mapValuePoisonWithTypeRemap) {
 
 TEST(ValueMapperTest, mapValueConstantTargetNoneToLayoutTypeNullValue) {
   LLVMContext C;
-  auto *OldTy = TargetExtType::get(C, "spirv.Image");
+  auto *OldTy = TargetExtType::get(C, "spirv.Event");
   Type *NewTy = OldTy->getLayoutType();
 
   TestTypeRemapper TM(NewTy);

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-18 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,100 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+#define TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+
+#include 
+#include 
+#include 
+
+#if TEST_STD_VER < 20
+#  error invocable_with_telemetry requires C++20
+#else
+template 
+class invocable_with_telemetry {

cjdb wrote:

I've added `invocable_telemetry` to structure this a bit better.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-18 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 12cbccc3125725fad00022a9b3a52ed9be69c3a3 
141be9754313d239d5a0df61fa18935cd276b0b5 -- libcxx/include/__algorithm/fold.h 
libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp 
libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/requirements.compile.pass.cpp
 libcxx/test/std/algorithms/algorithms.results/in_value_result.pass.cpp 
libcxx/test/support/invocable_with_telemetry.h libcxx/test/support/maths.h 
libcxx/include/algorithm libcxx/modules/std/algorithm.inc 
libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.verify.cpp 
libcxx/test/std/algorithms/algorithms.results/no_unique_address.compile.pass.cpp
 libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp 
libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.input/input_iterator.compile.pass.cpp
 
libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp
 
libcxx/test/std/ranges/range.adaptors/range.all/range.ref.view/borrowing.compile.pass.cpp
 libcxx/test/support/test_range.h
``





View the diff from clang-format here.


``diff
diff --git a/libcxx/test/support/invocable_with_telemetry.h 
b/libcxx/test/support/invocable_with_telemetry.h
index 42c6b31a9b..bf271dbac0 100644
--- a/libcxx/test/support/invocable_with_telemetry.h
+++ b/libcxx/test/support/invocable_with_telemetry.h
@@ -77,7 +77,7 @@ public:
   }
 
 private:
-  F f_  = F();
+  F f_= F();
   invocable_telemetry* telemetry_ = nullptr;
 };
 

``




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


[clang-tools-extra] [libunwind] [llvm] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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


@@ -2974,6 +2966,39 @@ bool UnwindCursor::getFunctionName(char *buf, 
size_t bufLen,
  buf, bufLen, offset);
 }
 
+#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+template 
+bool UnwindCursor::isReadableAddr(const pint_t addr) const {
+  // This code is heavily based on Abseil's 'address_is_readable.cc',
+  // which is Copyright Abseil Authors (2017), and provided under
+  // the Apache License 2.0.
+
+  // Align to 8-bytes.
+  const auto alignedAddr = addr & ~pint_t{7};
+  const auto sigsetAddr = reinterpret_cast(alignedAddr);
+  // We have to check that addr is nullptr because sigprocmask allows that
+  // as an argument without failure.
+  if (!sigsetAddr)
+return false;
+
+  // We MUST use the raw sigprocmask syscall here, as wrappers may try to
+  // access sigsetAddr which may cause a SIGSEGV. The raw syscall however is
+  // safe. Additionally, we need to pass the kernel_sigset_size, which is
+  // different from libc sizeof(sigset_t). Some archs have sigset_t
+  // defined as unsigned long, so let's use that.
+  const auto approxKernelSigsetSize = sizeof(unsigned long);
+  [[maybe_unused]] const int Result =
+  syscall(SYS_rt_sigprocmask, /*how=*/~0, sigsetAddr, sigsetAddr,
+  approxKernelSigsetSize);
+  // Because our "how" is invalid, this syscall should always fail, and our
+  // errno should always be EINVAL or an EFAULT. EFAULT is not guaranteed
+  // by the POSIX standard, so this is (for now) Linux specific.

MaskRay wrote:

rt_sigprocmask is a Linux-specific syscall,and the guard macro 
`_LIBUNWIND_CHECK_LINUX_SIGRETURN` is about Linux, so the "Linux specific" 
comment is unneeded

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


[clang-tools-extra] [libunwind] [llvm] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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


@@ -2974,6 +2966,39 @@ bool UnwindCursor::getFunctionName(char *buf, 
size_t bufLen,
  buf, bufLen, offset);
 }
 
+#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+template 
+bool UnwindCursor::isReadableAddr(const pint_t addr) const {
+  // This code is heavily based on Abseil's 'address_is_readable.cc',

MaskRay wrote:

The code is significantly different so the license (Apache2) comment should not 
be needed.

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


[clang] [llvm] [clang-tools-extra] [libunwind] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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

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


[clang-tools-extra] [libunwind] [llvm] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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


@@ -2974,6 +2966,39 @@ bool UnwindCursor::getFunctionName(char *buf, 
size_t bufLen,
  buf, bufLen, offset);
 }
 
+#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+template 
+bool UnwindCursor::isReadableAddr(const pint_t addr) const {
+  // This code is heavily based on Abseil's 'address_is_readable.cc',
+  // which is Copyright Abseil Authors (2017), and provided under
+  // the Apache License 2.0.
+
+  // Align to 8-bytes.
+  const auto alignedAddr = addr & ~pint_t{7};
+  const auto sigsetAddr = reinterpret_cast(alignedAddr);
+  // We have to check that addr is nullptr because sigprocmask allows that
+  // as an argument without failure.
+  if (!sigsetAddr)
+return false;
+
+  // We MUST use the raw sigprocmask syscall here, as wrappers may try to
+  // access sigsetAddr which may cause a SIGSEGV. The raw syscall however is
+  // safe. Additionally, we need to pass the kernel_sigset_size, which is
+  // different from libc sizeof(sigset_t). Some archs have sigset_t
+  // defined as unsigned long, so let's use that.
+  const auto approxKernelSigsetSize = sizeof(unsigned long);

MaskRay wrote:

`sizeof(unsigned long)` for 32-bit ELF targets. We should use 8 (tested on 
i386).

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


[libcxx] [compiler-rt] [llvm] [flang] [clang-tools-extra] [clang] [libc] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-18 Thread Bill Wendling via cfe-commits

bwendling wrote:

> > #75857 has been merged in. This PR is no longer valid.
> 
> Couldn't you just rebase it like:
> 
> * base: `main`
> * pick revert of [Revert counted_by attribute featureĀ 
> #75857](https://github.com/llvm/llvm-project/pull/75857)
> * all the commits of this PR
> 
> It's a bit of a matter of taste obviously how to deal with such situations. I 
> tend to prefer not to split the context across several PRs...

Since the entire feature has been reverted, I don't think the discussion here 
is particularly useful.

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


[clang] d9d20bd - Honor -fno-sanitize-link-runtime for libclang_rt.asan_static (#66414)

2023-12-18 Thread via cfe-commits

Author: Colin Cross
Date: 2023-12-18T17:15:41-08:00
New Revision: d9d20bd81f2f95c9b7510725fb76975e8123a542

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

LOG: Honor -fno-sanitize-link-runtime for libclang_rt.asan_static (#66414)

https://reviews.llvm.org/D122407 added a static link against
libclang_rt.asan_static whenever ASAN is linked, but ignored the
-fno-sanitize-link-runtime flag. Every other conditional in
collectSanitizerRuntimes is already checking for SanArgs.linkRuntimes(),
move it to the top of the function so that newly added conditionals
don't need to remember to check it.

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 45901ee7157f77..4f4bdac793bea7 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1317,28 +1317,28 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
   const SanitizerArgs  = TC.getSanitizerArgs(Args);
   // Collect shared runtimes.
   if (SanArgs.needsSharedRt()) {
-if (SanArgs.needsAsanRt() && SanArgs.linkRuntimes()) {
+if (SanArgs.needsAsanRt()) {
   SharedRuntimes.push_back("asan");
   if (!Args.hasArg(options::OPT_shared) && !TC.getTriple().isAndroid())
 HelperStaticRuntimes.push_back("asan-preinit");
 }
-if (SanArgs.needsMemProfRt() && SanArgs.linkRuntimes()) {
+if (SanArgs.needsMemProfRt()) {
   SharedRuntimes.push_back("memprof");
   if (!Args.hasArg(options::OPT_shared) && !TC.getTriple().isAndroid())
 HelperStaticRuntimes.push_back("memprof-preinit");
 }
-if (SanArgs.needsUbsanRt() && SanArgs.linkRuntimes()) {
+if (SanArgs.needsUbsanRt()) {
   if (SanArgs.requiresMinimalRuntime())
 SharedRuntimes.push_back("ubsan_minimal");
   else
 SharedRuntimes.push_back("ubsan_standalone");
 }
-if (SanArgs.needsScudoRt() && SanArgs.linkRuntimes()) {
+if (SanArgs.needsScudoRt()) {
   SharedRuntimes.push_back("scudo_standalone");
 }
-if (SanArgs.needsTsanRt() && SanArgs.linkRuntimes())
+if (SanArgs.needsTsanRt())
   SharedRuntimes.push_back("tsan");
-if (SanArgs.needsHwasanRt() && SanArgs.linkRuntimes()) {
+if (SanArgs.needsHwasanRt()) {
   if (SanArgs.needsHwasanAliasesRt())
 SharedRuntimes.push_back("hwasan_aliases");
   else
@@ -1349,7 +1349,7 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
   }
 
   // The stats_client library is also statically linked into DSOs.
-  if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
+  if (SanArgs.needsStatsRt())
 StaticRuntimes.push_back("stats_client");
 
   // Always link the static runtime regardless of DSO or executable.
@@ -1365,20 +1365,19 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
   // Each static runtime that has a DSO counterpart above is excluded below,
   // but runtimes that exist only as static are not affected by needsSharedRt.
 
-  if (!SanArgs.needsSharedRt() && SanArgs.needsAsanRt() && 
SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() && SanArgs.needsAsanRt()) {
 StaticRuntimes.push_back("asan");
 if (SanArgs.linkCXXRuntimes())
   StaticRuntimes.push_back("asan_cxx");
   }
 
-  if (!SanArgs.needsSharedRt() && SanArgs.needsMemProfRt() &&
-  SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() && SanArgs.needsMemProfRt()) {
 StaticRuntimes.push_back("memprof");
 if (SanArgs.linkCXXRuntimes())
   StaticRuntimes.push_back("memprof_cxx");
   }
 
-  if (!SanArgs.needsSharedRt() && SanArgs.needsHwasanRt() && 
SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() && SanArgs.needsHwasanRt()) {
 if (SanArgs.needsHwasanAliasesRt()) {
   StaticRuntimes.push_back("hwasan_aliases");
   if (SanArgs.linkCXXRuntimes())
@@ -1389,22 +1388,21 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
 StaticRuntimes.push_back("hwasan_cxx");
 }
   }
-  if (SanArgs.needsDfsanRt() && SanArgs.linkRuntimes())
+  if (SanArgs.needsDfsanRt())
 StaticRuntimes.push_back("dfsan");
-  if (SanArgs.needsLsanRt() && SanArgs.linkRuntimes())
+  if (SanArgs.needsLsanRt())
 StaticRuntimes.push_back("lsan");
-  if (SanArgs.needsMsanRt() && SanArgs.linkRuntimes()) {
+  if (SanArgs.needsMsanRt()) {
 StaticRuntimes.push_back("msan");
 if (SanArgs.linkCXXRuntimes())
   StaticRuntimes.push_back("msan_cxx");
   }
-  if (!SanArgs.needsSharedRt() && SanArgs.needsTsanRt() &&
-  SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() && SanArgs.needsTsanRt()) {
 StaticRuntimes.push_back("tsan");
 if 

[clang] Honor -fno-sanitize-link-runtime for libclang_rt.asan_static (PR #66414)

2023-12-18 Thread Vitaly Buka via cfe-commits

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


[clang] Honor -fno-sanitize-link-runtime for libclang_rt.asan_static (PR #66414)

2023-12-18 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

Sorry, I guess we need to train our-self to merge patches for non-members.


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


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

2023-12-18 Thread via cfe-commits

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

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

---
 clang/lib/Headers/arm_acle.h | 49 
 1 file changed, 49 insertions(+)

diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 61d80258d166a1..00f4cf00b2642a 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -756,6 +756,55 @@ __arm_st64bv0(void *__addr, data512_t __value) {
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif
 
+/* Coprocessor Intrinsics */
+#if (!__thumb__ || __thumb2__)
+#if __ARM_ARCH >= 4
+#define __arm_cdp(__coproc, __opc1, __CRd, __CRn, __CRm, __opc2)   
\
+  __builtin_arm_cdp(__coproc, __opc1, __CRd, __CRn, __CRm, __opc2)
+#define __arm_ldc(__coproc, __CRd, __p) __builtin_arm_ldc(__coproc, __CRd, __p)
+#define __arm_ldcl(__coproc, __CRd, __p)   
\
+  __builtin_arm_ldcl(__coproc, __CRd, __p)
+#define __arm_stc(__coproc, __CRd, __p) __builtin_arm_stc(__coproc, __CRd, __p)
+#define __arm_stcl(__coproc, __CRd, __p)   
\
+  __builtin_arm_stcl(__coproc, __CRd, __p)
+#define __arm_mcr(__coproc, __opc1, __value, __CRn, __CRm, __opc2) 
\
+  __builtin_arm_mcr(__coproc, __opc1, __value, __CRn, __CRm, __opc2)
+#define __arm_mrc(__coproc, __opc1, __CRn, __CRm, __opc2)  
\
+  __builtin_arm_mrc(__coproc, __opc1, __CRn, __CRm, __opc2)
+
+#if __ARM_ARCH >= 5
+#define __arm_cdp2(__coproc, __opc1, __CRd, __CRn, __CRm, __opc2)  
\
+  __builtin_arm_cdp2(__coproc, __opc1, __CRd, __CRn, __CRm, __opc2)
+#define __arm_ldc2(__coproc, __CRd, __p)   
\
+  __builtin_arm_ldc2(__coproc, __CRd, __p)
+#define __arm_ldc2l(__coproc, __CRd, __p)  
\
+  __builtin_arm_ldc2l(__coproc, __CRd, __p)
+#define __arm_stc2(__coproc, __CRd, __p)   
\
+  __builtin_arm_stc2(__coproc, __CRd, __p)
+#define __arm_stc2l(__coproc, __CRd, __p)  
\
+  __builtin_arm_stc2l(__coproc, __CRd, __p)
+#define __arm_mcr2(__coproc, __opc1, __value, __CRn, __CRm, __opc2)
\
+  __builtin_arm_mcr2(__coproc, __opc1, __value, __CRn, __CRm, __opc2)
+#define __arm_mrc2(__coproc, __opc1, __CRn, __CRm, __opc2) 
\
+  __builtin_arm_mrc2(__coproc, __opc1, __CRn, __CRm, __opc2)
+
+#if __ARM_ARCH >= 6 || defined(__ARM_ARCH_5TE__)
+#define __arm_mcrr(__coproc, __opc1, __value, __CRm)   
\
+  __builtin_arm_mcrr(__coproc, __opc1, __value, __CRm)
+#define __arm_mrrc(__coproc, __opc1, __CRm)
\
+  __builtin_arm_mrrc(__coproc, __opc1, __CRm)
+
+#if __ARM_ARCH >= 6
+#define __arm_mcrr2(__coproc, __opc1, __value, __CRm)  
\
+  __builtin_arm_mcrr2(__coproc, __opc1, __value, __CRm)
+#define __arm_mrrc2(__coproc, __opc1, __CRm)   
\
+  __builtin_arm_mrrc2(__coproc, __opc1, __CRm)
+#endif /* __ARM_ARCH >= 6.  */
+#endif /* __ARM_ARCH >= 6 ||  defined (__ARM_ARCH_5TE__).  */
+#endif /*  __ARM_ARCH >= 5.  */
+#endif /* __ARM_ARCH >=4 */
+#endif /* (!__thumb__ || __thumb2__) */
+
 /* Transactional Memory Extension (TME) Intrinsics */
 #if defined(__ARM_FEATURE_TME) && __ARM_FEATURE_TME
 

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


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

2023-12-18 Thread via cfe-commits

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


[llvm] [lldb] [mlir] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [clang] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-18 Thread Konstantin Varlamov via cfe-commits


@@ -0,0 +1,303 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// 
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200
+
+// template S, class T, class Proj = 
identity>
+// requires indirect_binary_predicate, const T*>
+// constexpr bool ranges::contains(I first, S last, const T& value, Proj 
proj = {});   // since C++23
+
+// template
+// requires indirect_binary_predicate, Proj>, const T*>
+// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); 
// since C++23
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "almost_satisfies_types.h"
+#include "boolean_testable.h"
+#include "test_iterators.h"
+
+struct NotEqualityComparable {};
+
+template 
+concept HasContainsSubrangeIt = requires(Iter1 first1, Sent1 last1, Iter2 
first2, Sent2 last2) {
+  std::ranges::contains_subrange(first1, last1, first2, last2);
+};
+
+static_assert(HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt); // not indirectly 
comparable
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+static_assert(!HasContainsSubrangeIt);
+
+template >
+concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) {
+  std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2)); };
+
+static_assert(HasContainsSubrangeR>);
+static_assert(!HasContainsSubrangeR);
+static_assert(!HasContainsSubrangeR);
+static_assert(!HasContainsSubrangeR);
+static_assert(!HasContainsSubrangeR);
+static_assert(!HasContainsSubrangeR, 
UncheckedRange>); // not indirectly comparable
+static_assert(!HasContainsSubrangeR, 
ForwardRangeNotDerivedFrom>);
+static_assert(!HasContainsSubrangeR, 
ForwardRangeNotIncrementable>);
+static_assert(!HasContainsSubrangeR, 
ForwardRangeNotSentinelSemiregular>);
+static_assert(!HasContainsSubrangeR, 
ForwardRangeNotSentinelEqualityComparableWith>);
+
+template 
+constexpr void test_iterators() {
+  {  // simple tests
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 5};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
+{
+  [[maybe_unused]] std::same_as decltype(auto) ret =
+  std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  assert(ret);
+}
+{
+  [[maybe_unused]] std::same_as decltype(auto) ret = 
std::ranges::contains_subrange(whole, subrange);
+  assert(ret);
+}
+  }
+
+  { // no match
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
+{
+  bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  assert(!ret);
+}
+{
+  bool ret = std::ranges::contains_subrange(whole, subrange);
+  assert(!ret);
+}
+  }
+
+  { // range consists of just one element
+int a[]   = {3};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
+auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
+{
+  bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  assert(!ret);
+}
+{
+  bool ret = std::ranges::contains_subrange(whole, subrange);
+  assert(!ret);
+}
+  }
+
+  { // subrange consists of just one element
+int a[]   = {23, 1, 20, 3, 54, 2};
+int p[]   = {3};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 1)));
+{
+  bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  assert(ret);
+}
+{
+  bool ret = std::ranges::contains_subrange(whole, subrange);
+  assert(ret);
+}
+  }
+
+  { // range has zero length
+int a[]   = {};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
+auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
+{
+  bool ret = std::ranges::contains_subrange(whole.begin(), 

[libunwind] [llvm] [clang-tools-extra] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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


@@ -2822,13 +2816,11 @@ bool UnwindCursor::setInfoForSigReturn(Registers_s390x &) {
   // onto the stack.
   const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
   // The PC might contain an invalid address if the unwind info is bad, so
-  // directly accessing it could cause a segfault. Use process_vm_readv to
-  // read the memory safely instead.
-  uint16_t inst;
-  struct iovec local_iov = {, sizeof inst};
-  struct iovec remote_iov = {reinterpret_cast(pc), sizeof inst};
-  long bytesRead = process_vm_readv(getpid(), _iov, 1, _iov, 1, 
0);
-  if (bytesRead == sizeof inst && (inst == 0x0a77 || inst == 0x0aad)) {
+  // directly accessing it could cause a SIGSEGV.
+  if (!isReadableAddr(pc) || !isReadableAddr(pc + 2))

MaskRay wrote:

Once call suffices as one rt_sigprocmask call checks 8 bytes.

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


[libunwind] [llvm] [clang-tools-extra] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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

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


[libunwind] [llvm] [clang-tools-extra] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

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


@@ -2762,18 +2757,17 @@ int UnwindCursor::stepThroughSigReturn(Registers_arm64 &) {
 template 
 bool UnwindCursor::setInfoForSigReturn(Registers_riscv &) {
   const pint_t pc = static_cast(getReg(UNW_REG_IP));
-  uint32_t instructions[2];
-  struct iovec local_iov = {, sizeof instructions};
-  struct iovec remote_iov = {reinterpret_cast(pc), sizeof 
instructions};
-  long bytesRead =
-  syscall(SYS_process_vm_readv, getpid(), _iov, 1, _iov, 1, 
0);
+  // The PC might contain an invalid address if the unwind info is bad, so
+  // directly accessing it could cause a SIGSEGV.
+  if (!isReadableAddr(pc) || !isReadableAddr(pc + 4))

MaskRay wrote:

It is unfortunate that we have to call `isReadableAddr` twice.

`linux/kernel/signal.c` `rt_sigprocmask` actually supports an unaligned 
address. We can remove the alignment code `const auto alignedAddr = addr & 
~pint_t{7};` and use one `isReadableAddr(pc)`

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


[clang] Warning for unsafe invocation of span::data (PR #75650)

2023-12-18 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak updated 
https://github.com/llvm/llvm-project/pull/75650

>From 809bf6f4237f634feaeb7e5b0b88be3a2e4de455 Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Fri, 15 Dec 2023 11:40:55 -0800
Subject: [PATCH 1/3] While refactoring projects to eradicate unsafe buffer
 accesses using -Wunsafe-buffer-usage, there maybe accidental re-introduction
 of new OutOfBound accesses into the code bases. One such case is invoking
 span::data() method on a span variable to retrieve a pointer, which is then
 cast to a larger type and dereferenced. Such dereferences can introduce
 OutOfBound accesses.

To address this, a new WarningGadget is being introduced to warn against such 
invocations.
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   2 +-
 .../Analyses/UnsafeBufferUsageGadgets.def |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  37 -
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  19 ++-
 ...e-buffer-usage-warning-data-invocation.cpp | 133 ++
 6 files changed, 186 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 8a2d56668e32f9..b28f2c6b99c50e 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -66,7 +66,7 @@ class UnsafeBufferUsageHandler {
 
   /// Invoked when an unsafe operation over raw pointers is found.
   virtual void handleUnsafeOperation(const Stmt *Operation,
- bool IsRelatedToDecl) = 0;
+ bool IsRelatedToDecl, ASTContext ) = 
0;
 
   /// Invoked when a fix is suggested against a variable. This function groups
   /// all variables that must be fixed together (i.e their types must be 
changed
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index 757ee452ced748..c9766168836510 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -30,6 +30,7 @@ WARNING_GADGET(Decrement)
 WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
+WARNING_GADGET(DataInvocation)
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 94e97a891baedc..9038dd879f54ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12058,7 +12058,7 @@ def warn_unsafe_buffer_variable : Warning<
   InGroup, DefaultIgnore;
 def warn_unsafe_buffer_operation : Warning<
   "%select{unsafe pointer operation|unsafe pointer arithmetic|"
-  "unsafe buffer access|function introduces unsafe buffer manipulation}0">,
+  "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe 
invocation of span::data}0">,
   InGroup, DefaultIgnore;
 def note_unsafe_buffer_operation : Note<
   "used%select{| in pointer arithmetic| in buffer access}0 here">;
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 70eec1cee57f8e..e4eca9939b10d5 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget {
   DeclUseList getClaimedVarUseSites() const override { return {}; }
 };
 
+// Warning gadget for unsafe invocation of span::data method.
+// Triggers when the pointer returned by the invocation is immediately
+// cast to a larger type.
+
+class DataInvocationGadget : public WarningGadget {
+  constexpr static const char *const OpTag = "data_invocation_expr";
+  const ExplicitCastExpr *Op;
+
+  public:
+  DataInvocationGadget(const MatchFinder::MatchResult )
+  : WarningGadget(Kind::DataInvocation),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::DataInvocation;
+  }
+ 
+  static Matcher matcher() {
+return stmt(
+explicitCastExpr(has(cxxMemberCallExpr(callee(
+   cxxMethodDecl(hasName("data")).bind(OpTag));
+  }   
+  const Stmt *getBaseStmt() const override { return Op; }
+
+  DeclUseList getClaimedVarUseSites() const override { return {}; }
+};
+
 // Represents expressions of the form `DRE[*]` in the Unspecified Lvalue
 // Context (see `isInUnspecifiedLvalueContext`).
 // Note here `[]` is the built-in subscript operator.
@@ -2657,8 +2684,8 @@ void 

[libcxx] [clang-tools-extra] [llvm] [libc] [clang] [compiler-rt] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-18 Thread via cfe-commits

h-vetinari wrote:

> #75857 has been merged in. This PR is no longer valid.

Couldn't you just rebase it like:
- base: `main`
- pick revert of #75857 
- all the commits of this PR

It's a bit of a matter of taste obviously how to deal with such situations. I 
tend to prefer not to split the context across several PRs...

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


[clang] [llvm] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-18 Thread Eric Biggers via cfe-commits

ebiggers wrote:

Updated to add my Co-authored-by, as the original author is `Brandon Wu 
`.

Someone who has permission to do so will need to approve the GitHub Actions 
workflow, and merge the commit once everything is ready.

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


[clang] [llvm] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-18 Thread Eric Biggers via cfe-commits

ebiggers wrote:

No, I don't have commit access.

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


[clang] [clang-tools-extra] [llvm] [libunwind] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

2023-12-18 Thread Jordan R AW via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [libunwind] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

2023-12-18 Thread Jordan R AW via cfe-commits


@@ -26,7 +26,7 @@
 __attribute__((naked)) void bad_unwind_info() {
 #if defined(__aarch64__)
   __asm__("// not using 0 because unwinder was already resilient to that\n"
-  "mov x8, #4\n"
+  "mov x8, #12\n"

ajordanr-google wrote:

Note: changed this for an 8 byte alignment check, because `0x4 & 0x7` is `0x0`, 
whereas `0xC & 0x7` is `0x8`.

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


[clang] [llvm] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-18 Thread Craig Topper via cfe-commits

topperc wrote:

@ebiggers are you table to commit or do you need someone else to do it? I don't 
recall seeing a commit from you before so I wasn't sure.

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


[clang] [llvm] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-18 Thread Eric Biggers via cfe-commits

ebiggers wrote:

Rebased to resolve conflicts again

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


[clang] Warning for unsafe invocation of span::data (PR #75650)

2023-12-18 Thread Rashmi Mudduluru via cfe-commits

https://github.com/t-rasmud approved this pull request.

LGTM!

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


[llvm] [clang] [libunwind] [clang-tools-extra] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

2023-12-18 Thread Jordan R AW via cfe-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/74791

>From 1f4df1b82970c95684eed93c8f6bcaa6d6507b88 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Fri, 8 Dec 2023 00:09:59 +
Subject: [PATCH 1/8] [libunwind] Replace process_vm_readv with pipe

process_vm_readv is generally considered dangerous from a syscall
perspective, and is frequently blanket banned in seccomp filters such as
those in Chromium and ChromiumOS. We can get the same behaviour during
the invalid PC address case with pipes and write/read.

Testing to ensure that process_vm_readv does not appear, I ran the
output of check-unwind on an ARM64 device under strace. Previously,
bad_unwind_info in particular would use process_vm_readv, but with this
commit, it now uses pipe2:

```
strace test/Output/bad_unwind_info.pass.cpp.dir/t.tmp.exe \
  |& grep process_vm_readv
strace test/Output/bad_unwind_info.pass.cpp.dir/t.tmp.exe \
  |& grep pipe2
```
---
 libunwind/src/UnwindCursor.hpp | 50 --
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 647a5a9c9d92d9..5e4e376220daa0 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -33,6 +33,7 @@
 #if defined(_LIBUNWIND_TARGET_LINUX) &&
\
 (defined(_LIBUNWIND_TARGET_AARCH64) || defined(_LIBUNWIND_TARGET_RISCV) || 
\
  defined(_LIBUNWIND_TARGET_S390X))
+#include 
 #include 
 #include 
 #include 
@@ -2700,19 +2701,18 @@ bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) {
   // [1] 
https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/vdso/sigreturn.S
   const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
   // The PC might contain an invalid address if the unwind info is bad, so
-  // directly accessing it could cause a segfault. Use process_vm_readv to read
-  // the memory safely instead. process_vm_readv was added in Linux 3.2, and
-  // AArch64 supported was added in Linux 3.7, so the syscall is guaranteed to
-  // be present. Unfortunately, there are Linux AArch64 environments where the
-  // libc wrapper for the syscall might not be present (e.g. Android 5), so 
call
-  // the syscall directly instead.
+  // directly accessing it could cause a segfault. Use pipe/write/read to read
+  // the memory safely instead.
+  int pipefd[2];
+  if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) == -1)
+return false;
   uint32_t instructions[2];
-  struct iovec local_iov = {, sizeof instructions};
-  struct iovec remote_iov = {reinterpret_cast(pc), sizeof 
instructions};
-  long bytesRead =
-  syscall(SYS_process_vm_readv, getpid(), _iov, 1, _iov, 1, 
0);
+  const auto bufferSize = sizeof instructions;
+  if (write(pipefd[1], reinterpret_cast(pc), bufferSize) != bufferSize)
+return false;
+  const auto bytesRead = read(pipefd[0], instructions, bufferSize);
   // Look for instructions: mov x8, #0x8b; svc #0x0
-  if (bytesRead != sizeof instructions || instructions[0] != 0xd2801168 ||
+  if (bytesRead != bufferSize || instructions[0] != 0xd2801168 ||
   instructions[1] != 0xd401)
 return false;
 
@@ -2762,17 +2762,20 @@ int UnwindCursor::stepThroughSigReturn(Registers_arm64 &) {
 template 
 bool UnwindCursor::setInfoForSigReturn(Registers_riscv &) {
   const pint_t pc = static_cast(getReg(UNW_REG_IP));
+  int pipefd[2];
+  if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) == -1)
+return false;
   uint32_t instructions[2];
-  struct iovec local_iov = {, sizeof instructions};
-  struct iovec remote_iov = {reinterpret_cast(pc), sizeof 
instructions};
-  long bytesRead =
-  syscall(SYS_process_vm_readv, getpid(), _iov, 1, _iov, 1, 
0);
+  const auto bufferSize = sizeof instructions;
+  if (write(pipefd[1], reinterpret_cast(pc), bufferSize) != bufferSize)
+return false;
+  const auto bytesRead = read(pipefd[0], instructions, bufferSize);
   // Look for the two instructions used in the sigreturn trampoline
   // __vdso_rt_sigreturn:
   //
   // 0x08b00893 li a7,0x8b
   // 0x0073 ecall
-  if (bytesRead != sizeof instructions || instructions[0] != 0x08b00893 ||
+  if (bytesRead != bufferSize || instructions[0] != 0x08b00893 ||
   instructions[1] != 0x0073)
 return false;
 
@@ -2822,13 +2825,18 @@ bool UnwindCursor::setInfoForSigReturn(Registers_s390x &) {
   // onto the stack.
   const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
   // The PC might contain an invalid address if the unwind info is bad, so
-  // directly accessing it could cause a segfault. Use process_vm_readv to
+  // directly accessing it could cause a segfault. Use pipe/write/read to
   // read the memory safely instead.
   uint16_t inst;
-  struct iovec local_iov = {, sizeof inst};
-  struct iovec remote_iov = {reinterpret_cast(pc), sizeof inst};
-  long bytesRead = process_vm_readv(getpid(), _iov, 1, _iov, 1, 
0);
-  if (bytesRead == 

[clang] Warning for unsafe invocation of span::data (PR #75650)

2023-12-18 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak updated 
https://github.com/llvm/llvm-project/pull/75650

>From 809bf6f4237f634feaeb7e5b0b88be3a2e4de455 Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Fri, 15 Dec 2023 11:40:55 -0800
Subject: [PATCH 1/2] While refactoring projects to eradicate unsafe buffer
 accesses using -Wunsafe-buffer-usage, there maybe accidental re-introduction
 of new OutOfBound accesses into the code bases. One such case is invoking
 span::data() method on a span variable to retrieve a pointer, which is then
 cast to a larger type and dereferenced. Such dereferences can introduce
 OutOfBound accesses.

To address this, a new WarningGadget is being introduced to warn against such 
invocations.
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   2 +-
 .../Analyses/UnsafeBufferUsageGadgets.def |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  37 -
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  19 ++-
 ...e-buffer-usage-warning-data-invocation.cpp | 133 ++
 6 files changed, 186 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 8a2d56668e32f9..b28f2c6b99c50e 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -66,7 +66,7 @@ class UnsafeBufferUsageHandler {
 
   /// Invoked when an unsafe operation over raw pointers is found.
   virtual void handleUnsafeOperation(const Stmt *Operation,
- bool IsRelatedToDecl) = 0;
+ bool IsRelatedToDecl, ASTContext ) = 
0;
 
   /// Invoked when a fix is suggested against a variable. This function groups
   /// all variables that must be fixed together (i.e their types must be 
changed
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index 757ee452ced748..c9766168836510 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -30,6 +30,7 @@ WARNING_GADGET(Decrement)
 WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
+WARNING_GADGET(DataInvocation)
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 94e97a891baedc..9038dd879f54ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12058,7 +12058,7 @@ def warn_unsafe_buffer_variable : Warning<
   InGroup, DefaultIgnore;
 def warn_unsafe_buffer_operation : Warning<
   "%select{unsafe pointer operation|unsafe pointer arithmetic|"
-  "unsafe buffer access|function introduces unsafe buffer manipulation}0">,
+  "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe 
invocation of span::data}0">,
   InGroup, DefaultIgnore;
 def note_unsafe_buffer_operation : Note<
   "used%select{| in pointer arithmetic| in buffer access}0 here">;
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 70eec1cee57f8e..e4eca9939b10d5 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget {
   DeclUseList getClaimedVarUseSites() const override { return {}; }
 };
 
+// Warning gadget for unsafe invocation of span::data method.
+// Triggers when the pointer returned by the invocation is immediately
+// cast to a larger type.
+
+class DataInvocationGadget : public WarningGadget {
+  constexpr static const char *const OpTag = "data_invocation_expr";
+  const ExplicitCastExpr *Op;
+
+  public:
+  DataInvocationGadget(const MatchFinder::MatchResult )
+  : WarningGadget(Kind::DataInvocation),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::DataInvocation;
+  }
+ 
+  static Matcher matcher() {
+return stmt(
+explicitCastExpr(has(cxxMemberCallExpr(callee(
+   cxxMethodDecl(hasName("data")).bind(OpTag));
+  }   
+  const Stmt *getBaseStmt() const override { return Op; }
+
+  DeclUseList getClaimedVarUseSites() const override { return {}; }
+};
+
 // Represents expressions of the form `DRE[*]` in the Unspecified Lvalue
 // Context (see `isInUnspecifiedLvalueContext`).
 // Note here `[]` is the built-in subscript operator.
@@ -2657,8 +2684,8 @@ void 

  1   2   3   4   5   >