[clang-tools-extra] [clang] [llvm] [IR] Disallow ZeroInit for spirv.Image (PR #73887)

2023-12-17 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 &C = 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


[compiler-rt] [libcxx] [llvm] [libc] [clang-tools-extra] [clang] [flang] [AMDGPU] Produce better memoperand for LDS DMA (PR #75247)

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

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


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


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

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

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


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

2023-12-17 Thread via cfe-commits

Author: Brandon Wu
Date: 2023-12-18T15:52:14+08:00
New Revision: 111a2290650743b27f70f9b24618411e54493b59

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

LOG: [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.

Added: 
clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 835215a83c4037..02228e19dcf2ea 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 &D, const 
llvm::Triple &TargetTriple,
 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 &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVectorImpl &SelectedMultilibs) {
+  // 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 &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-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 &M : 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 &MLConfigISAInfo = *MLConfigParseResult;
+
+  const llvm::RISCVISAInfo::OrderedExtensionMap &MLConfigArchExts =
+  MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if 

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

2023-12-17 Thread Yeoul Na via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

rapidsna wrote:

@rjmccall @bwendling I have documentation clarifying what are the restrictions 
for __counted_by 
https://github.com/rapidsna/llvm-project/pull/1/commits/4a6a041267b3399eab46c3bb88e3d023d4050836.
 I was planning to land it after my initial documentation lands 
https://github.com/llvm/llvm-project/pull/70749.

@bwendling In general, the same name/expression rules should apply to 
`__counted_by` used in pointers and arrays. I clarified that in 
https://github.com/rapidsna/llvm-project/pull/1/commits/4a6a041267b3399eab46c3bb88e3d023d4050836.
 I synched with GCC folks and they agreed that the syntax and semantics should 
not diverge between the full `-fbounds-safety` mode and the mode only using the 
annotations for `__bdos` and sanitizers.



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


[llvm] [clang] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #75647)

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

https://github.com/arsenm commented:

What kind of optimizations does this enable? Would this be better expressed as 
a maximum dispatch size, per dimension?

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


[llvm] [clang] Recommit [RISCV] Update the interface of sifive vqmaccqoq (#74284) (PR #75768)

2023-12-17 Thread via cfe-commits

llvmbot wrote:




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

Author: Brandon Wu (4vtomat)


Changes

The
spec(https://sifive.cdn.prismic.io/sifive/60d5a660-3af0-49a3-a904-d2bbb1a21517_int8-matmul-spec.pdf)
is updated.


---

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


23 Files Affected:

- (modified) clang/include/clang/Basic/riscv_sifive_vector.td (+17-9) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) clang/test/Sema/rvv-required-features.c (+2-16) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td (+38-23) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmacc_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccsu_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccu_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccus_4x8x4.ll (+28-30) 


``diff
diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index bb54e266418614..e19a34f7632fdc 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -112,7 +112,7 @@ multiclass RVVVFWMACCBuiltinSet> 
suffixes_prototypes> {
 defm NAME : RVVOutOp1Op2BuiltinSet;
 }
 
-multiclass RVVVQMACCBuiltinSet> suffixes_prototypes> {
+multiclass RVVVQMACCDODBuiltinSet> suffixes_prototypes> {
   let OverloadedName = NAME,
   Name = NAME,
   HasMasked = false,
@@ -120,6 +120,14 @@ multiclass RVVVQMACCBuiltinSet> 
suffixes_prototypes> {
 defm NAME : RVVOutOp1Op2BuiltinSet;
 }
 
+multiclass RVVVQMACCQOQBuiltinSet> suffixes_prototypes> {
+   let OverloadedName = NAME,
+   Name = NAME,
+   HasMasked = false,
+   Log2LMUL = [-1, 0, 1, 2] in
+ defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
 multiclass RVVVFNRCLIPBuiltinSet {
   let Log2LMUL = [-3, -2, -1, 0, 1, 2],
   Name = NAME,
@@ -130,18 +138,18 @@ multiclass RVVVFNRCLIPBuiltinSet;
-defm sf_vqmacc_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
-defm sf_vqmaccus_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
-defm sf_vqmaccsu_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
+defm sf_vqmaccu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
+defm sf_vqmacc_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
+defm sf_vqmaccus_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
+defm sf_vqmaccsu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
   }
 
 let UnMaskedPolicyScheme = HasPolicyOperand in
   let RequiredFeatures = ["Xsfvqmaccqoq"] in {
-defm sf_vqmaccu_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
-defm sf_vqmacc_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
-defm sf_vqmaccus_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
-defm sf_vqmaccsu_4x8x4 : RVVVQMA

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

2023-12-17 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen approved this pull request.

LGTM

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


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-17 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/75580

>From e16afbdc9f0c04bad0e8f80f90c0eb26c13d3326 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 15 Dec 2023 16:50:23 +0800
Subject: [PATCH 1/4] [X86] Emit Warnings for frontend options to enable
 knl/knm.

Since Knight Landing and Knight Mill microarchitectures are EOL, we
would like to remove its support in LLVM 19. In LLVM 18, we will first
emit a warning for the usage.
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Basic/Targets/X86.cpp|  3 +++
 clang/test/CodeGen/X86/avx512er-builtins.c |  2 +-
 clang/test/CodeGen/X86/avx512pf-builtins.c |  2 +-
 clang/test/Driver/cl-x86-flags.c   | 10 --
 clang/test/Frontend/x86-target-cpu.c   | 10 --
 clang/test/Misc/warning-flags.c|  3 ++-
 7 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..40841e9df547bc 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<
+  "KNL/KNM's feature support will be removed in LLVM 19.">;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..dc56524d378104 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -295,11 +295,13 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasAVX512BF16 = true;
 } else if (Feature == "+avx512er") {
   HasAVX512ER = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
   HasLegalHalfType = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512dq") {
   HasAVX512DQ = true;
 } else if (Feature == "+avx512bitalg") {
@@ -358,6 +360,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasPREFETCHI = true;
 } else if (Feature == "+prefetchwt1") {
   HasPREFETCHWT1 = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
 } else if (Feature == "+cldemote") {
diff --git a/clang/test/CodeGen/X86/avx512er-builtins.c 
b/clang/test/CodeGen/X86/avx512er-builtins.c
index ee31236a3c01aa..11ec6aabec1e3f 100644
--- a/clang/test/CodeGen/X86/avx512er-builtins.c
+++ b/clang/test/CodeGen/X86/avx512er-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall | FileCheck %s
 
 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512pf-builtins.c 
b/clang/test/CodeGen/X86/avx512pf-builtins.c
index 4ca70f5787968b..3a117ed6a9460e 100644
--- a/clang/test/CodeGen/X86/avx512pf-builtins.c
+++ b/clang/test/CodeGen/X86/avx512pf-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall 
-Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall | 
FileCheck %s
 
 
 #include 
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce35463..ae35a312fe8a4b 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
 #if defined(TEST_32_ARCH_AVX512F)
 #if _M_IX86_FP !=

[clang] [Clang][CodeGen] Fix crash when using bool vector in compound assignment (PR #75435)

2023-12-17 Thread Chenyang Gao via cfe-commits

cygao90 wrote:

Ping

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


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-17 Thread Freddy Ye via cfe-commits


@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<

FreddyLeaf wrote:

Thanks review, addressed in 3eb6b009b14202d4c14bdc691d80550bac4c9aa7

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


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-17 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/75580

>From e16afbdc9f0c04bad0e8f80f90c0eb26c13d3326 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 15 Dec 2023 16:50:23 +0800
Subject: [PATCH 1/3] [X86] Emit Warnings for frontend options to enable
 knl/knm.

Since Knight Landing and Knight Mill microarchitectures are EOL, we
would like to remove its support in LLVM 19. In LLVM 18, we will first
emit a warning for the usage.
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Basic/Targets/X86.cpp|  3 +++
 clang/test/CodeGen/X86/avx512er-builtins.c |  2 +-
 clang/test/CodeGen/X86/avx512pf-builtins.c |  2 +-
 clang/test/Driver/cl-x86-flags.c   | 10 --
 clang/test/Frontend/x86-target-cpu.c   | 10 --
 clang/test/Misc/warning-flags.c|  3 ++-
 7 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..40841e9df547bc 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<
+  "KNL/KNM's feature support will be removed in LLVM 19.">;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..dc56524d378104 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -295,11 +295,13 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasAVX512BF16 = true;
 } else if (Feature == "+avx512er") {
   HasAVX512ER = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
   HasLegalHalfType = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512dq") {
   HasAVX512DQ = true;
 } else if (Feature == "+avx512bitalg") {
@@ -358,6 +360,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasPREFETCHI = true;
 } else if (Feature == "+prefetchwt1") {
   HasPREFETCHWT1 = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
 } else if (Feature == "+cldemote") {
diff --git a/clang/test/CodeGen/X86/avx512er-builtins.c 
b/clang/test/CodeGen/X86/avx512er-builtins.c
index ee31236a3c01aa..11ec6aabec1e3f 100644
--- a/clang/test/CodeGen/X86/avx512er-builtins.c
+++ b/clang/test/CodeGen/X86/avx512er-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall | FileCheck %s
 
 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512pf-builtins.c 
b/clang/test/CodeGen/X86/avx512pf-builtins.c
index 4ca70f5787968b..3a117ed6a9460e 100644
--- a/clang/test/CodeGen/X86/avx512pf-builtins.c
+++ b/clang/test/CodeGen/X86/avx512pf-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall 
-Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall | 
FileCheck %s
 
 
 #include 
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce35463..ae35a312fe8a4b 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
 #if defined(TEST_32_ARCH_AVX512F)
 #if _M_IX86_FP !=

[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

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


@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<

topperc wrote:

supports -> support remove->removed to match the string

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


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

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

MaskRay wrote:

> `MachO/lto-module-asm-err.ll` needs update?

Thanks for the reminder. Updated in 09f2f27972d75886085bdd790533d154c01984d4

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] [lld] [clang] [LTO] Improve diagnostics handling when parsing module-level inline assembly (PR #75726)

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

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/75726

>From 4e5fb8b8c7f39935dce2a11bd90fc27f65cd2d76 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 10 Dec 2023 10:13:59 -0800
Subject: [PATCH 1/2] [LTO] Improve diagnostics handling when parsing
 module-level inline assembly

Non-LTO compiles set the buffer name to ""
(`AsmPrinter::addInlineAsmDiagBuffer`) and pass diagnostics to
`ClangDiagnosticHandler` (through the `MCContext` handler in
`MachineModuleInfoWrapperPass::doInitialization`) to ensure that
the exit code is 1 in the presence of errors. In contrast, LTO compiles
spuriously succeed even if error messages are printed.

```
% cat a.c
void _start() {}
asm("unknown instruction");
% clang -c a.c
:1:1: error: invalid instruction mnemonic 'unknown'
1 | unknown instruction
  | ^
1 error generated.
% clang -c -flto a.c; echo $?  # -flto=thin is the same
error: invalid instruction mnemonic 'unknown'
unknown instruction
^~~
error: invalid instruction mnemonic 'unknown'
unknown instruction
^~~
0
```

`CollectAsmSymbols` parses inline assembly and is transitively called by
both `ModuleSummaryIndexAnalysis::run` and `WriteBitcodeToFile`, leading
to duplicate diagnostics.

This patch updates `CollectAsmSymbols` to be similar to non-LTO
compiles.
```
% clang -c -flto=thin a.c; echo $?
:1:1: error: invalid instruction mnemonic 'unknown'
1 | unknown instruction
  | ^
1 errors generated.
1
```

The `HasErrors` check does not prevent duplicate warnings but assembler
warnings are very uncommon.
---
 clang/lib/CodeGen/CodeGenAction.cpp  |  2 ++
 clang/test/CodeGen/invalid_global_asm.c  |  5 +
 llvm/include/llvm/IR/DiagnosticHandler.h |  1 +
 llvm/lib/Object/ModuleSymbolTable.cpp| 16 +++-
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 753a8fd74fa696..4121a3709bc3af 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -418,6 +418,8 @@ void BackendConsumer::anchor() { }
 } // namespace clang
 
 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) {
+  if (DI.getSeverity() == DS_Error)
+HasErrors = true;
   BackendCon->DiagnosticHandlerImpl(DI);
   return true;
 }
diff --git a/clang/test/CodeGen/invalid_global_asm.c 
b/clang/test/CodeGen/invalid_global_asm.c
index 5b7e8b43d752d8..d5645f7fc92bf4 100644
--- a/clang/test/CodeGen/invalid_global_asm.c
+++ b/clang/test/CodeGen/invalid_global_asm.c
@@ -1,5 +1,10 @@
 // REQUIRES: arm-registered-target
 // RUN: not %clang_cc1 -emit-obj -triple armv6-unknown-unknown -o %t %s 2>&1 | 
FileCheck %s
+// RUN: not %clang_cc1 -emit-obj -triple armv6-unknown-unknown -flto -o %t %s 
2>&1 | FileCheck %s
+
+/// Test the diagnostic behavior considering the whole system including the 
driver.
+// RUN: not %clang --target=armv6-unknown-unknown -c -flto=thin -o %t %s 2>&1 
| FileCheck %s
 #pragma clang diagnostic ignored "-Wmissing-noreturn"
 __asm__(".Lfoo: movw r2, #:lower16:.Lbar - .Lfoo");
 // CHECK: :1:8: error: instruction requires: armv6t2
+// CHECK-NOT: error:
diff --git a/llvm/include/llvm/IR/DiagnosticHandler.h 
b/llvm/include/llvm/IR/DiagnosticHandler.h
index 55e5e5975808d9..db7d7444f75f05 100644
--- a/llvm/include/llvm/IR/DiagnosticHandler.h
+++ b/llvm/include/llvm/IR/DiagnosticHandler.h
@@ -23,6 +23,7 @@ class DiagnosticInfo;
 /// which remarks are enabled.
 struct DiagnosticHandler {
   void *DiagnosticContext = nullptr;
+  bool HasErrors = false;
   DiagnosticHandler(void *DiagContext = nullptr)
   : DiagnosticContext(DiagContext) {}
   virtual ~DiagnosticHandler() = default;
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp 
b/llvm/lib/Object/ModuleSymbolTable.cpp
index ab073e18cb4668..07f76688fa43e7 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -16,6 +16,7 @@
 #include "RecordStreamer.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalAlias.h"
 #include "llvm/IR/GlobalValue.h"
@@ -68,6 +69,11 @@ void ModuleSymbolTable::addModule(Module *M) {
 static void
 initializeRecordStreamer(const Module &M,
  function_ref Init) {
+  // This function may be called twice, once for ModuleSummaryIndexAnalysis and
+  // the other when writing the IR symbol table. If parsing inline assembly has
+  // caused errors in the first run, suppress the second run.
+  if (M.getContext().getDiagHandlerPtr()->HasErrors)
+return;
   StringRef InlineAsm = M.getModuleInlineAsm();
   if (InlineAsm.empty())
 return;
@@ -95,7 +101,8 @@ initializeRecordStreamer(const Module &M,
   if (!MCII)
 return;
 
-  std::unique_ptr Buffer(MemoryBuffer::getMemBuffer(InlineAsm));
+  std::unique_ptr Buffer(
+  MemoryBuffer::getMemBuffer(InlineAsm, ""));
   SourceMgr SrcMgr;
   

[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-17 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/75580

>From e16afbdc9f0c04bad0e8f80f90c0eb26c13d3326 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 15 Dec 2023 16:50:23 +0800
Subject: [PATCH 1/2] [X86] Emit Warnings for frontend options to enable
 knl/knm.

Since Knight Landing and Knight Mill microarchitectures are EOL, we
would like to remove its support in LLVM 19. In LLVM 18, we will first
emit a warning for the usage.
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Basic/Targets/X86.cpp|  3 +++
 clang/test/CodeGen/X86/avx512er-builtins.c |  2 +-
 clang/test/CodeGen/X86/avx512pf-builtins.c |  2 +-
 clang/test/Driver/cl-x86-flags.c   | 10 --
 clang/test/Frontend/x86-target-cpu.c   | 10 --
 clang/test/Misc/warning-flags.c|  3 ++-
 7 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..40841e9df547bc 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<
+  "KNL/KNM's feature support will be removed in LLVM 19.">;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..dc56524d378104 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -295,11 +295,13 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasAVX512BF16 = true;
 } else if (Feature == "+avx512er") {
   HasAVX512ER = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
   HasLegalHalfType = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512dq") {
   HasAVX512DQ = true;
 } else if (Feature == "+avx512bitalg") {
@@ -358,6 +360,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasPREFETCHI = true;
 } else if (Feature == "+prefetchwt1") {
   HasPREFETCHWT1 = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
 } else if (Feature == "+cldemote") {
diff --git a/clang/test/CodeGen/X86/avx512er-builtins.c 
b/clang/test/CodeGen/X86/avx512er-builtins.c
index ee31236a3c01aa..11ec6aabec1e3f 100644
--- a/clang/test/CodeGen/X86/avx512er-builtins.c
+++ b/clang/test/CodeGen/X86/avx512er-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall | FileCheck %s
 
 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512pf-builtins.c 
b/clang/test/CodeGen/X86/avx512pf-builtins.c
index 4ca70f5787968b..3a117ed6a9460e 100644
--- a/clang/test/CodeGen/X86/avx512pf-builtins.c
+++ b/clang/test/CodeGen/X86/avx512pf-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall 
-Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall | 
FileCheck %s
 
 
 #include 
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce35463..ae35a312fe8a4b 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
 #if defined(TEST_32_ARCH_AVX512F)
 #if _M_IX86_FP !=

[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-17 Thread Shengchen Kan via cfe-commits

KanRobert wrote:

One more justification...
https://www.felixcloutier.com/x86/vscatterpf0dps:vscatterpf0qps:vscatterpf0dpd:vscatterpf0qpd

The assembler support for some KNL instructions is buggy

https://github.com/llvm/llvm-project/blob/31429e7a89590f88034920edd3e997aeabff8124/llvm/test/MC/X86/apx/evex-format-intel.s#L46

If we deprecate KNL, the bug can go away.

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


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

2023-12-17 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)


Changes

This is an out of order core with no vector unit. More information: 
https://www.sifive.com/cores/performance-p450-470

Scheduler model and other tuning will come in separate patches.

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


2 Files Affected:

- (modified) clang/test/Misc/target-invalid-cpu-note.c (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+19) 


``diff
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index e840a9208f5a45..48e9f05d9b03de 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -85,7 +85,7 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, 
sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
 
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
@@ -93,4 +93,4 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu, generic, rocket, 
sifive-7-series{{$}}
+// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-p450, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu, generic, 
rocket, sifive-7-series{{$}}
diff --git a/llvm/lib/Target/RISCV/RISCVProcessors.td 
b/llvm/lib/Target/RISCV/RISCVProcessors.td
index 58989fd716fa0e..16c79519fcacc1 100644
--- a/llvm/lib/Target/RISCV/RISCVProcessors.td
+++ b/llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -216,6 +216,25 @@ def SIFIVE_X280 : RISCVProcessorModel<"sifive-x280", 
SiFive7Model,
   [TuneSiFive7,
TuneDLenFactor2]>;
 
+def SIFIVE_P450 : RISCVProcessorModel<"sifive-p450", NoSchedModel,
+  [Feature64Bit,
+   FeatureStdExtZifencei,
+   FeatureStdExtM,
+   FeatureStdExtA,
+   FeatureStdExtF,
+   FeatureStdExtD,
+   FeatureStdExtC,
+   FeatureStdExtZicbop,
+   FeatureStdExtZicbom,
+   FeatureStdExtZicboz,
+   FeatureStdExtZihintntl,
+   FeatureStdExtZihintpause,
+   FeatureStdExtZihpm,
+   FeatureStdExtZba,
+   FeatureStdExtZbb,
+   FeatureStdExtZbs,
+   FeatureStdExtZfhmin]>;
+
 def SYNTACORE_SCR1_BASE : RISCVProcessorModel<"syntacore-scr1-base",
   SyntacoreSCR1Model,
   [Feature32Bit,

``




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] [llvm] [RISCV] Add sifive-p450 CPU. (PR #75760)

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

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/75760

This is an out of order core with no vector unit. More information: 
https://www.sifive.com/cores/performance-p450-470

Scheduler model and other tuning will come in separate patches.

>From 22fd20164e9d061a451555c5158f0a8ecb73f77e Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Sun, 17 Dec 2023 18:18:43 -0800
Subject: [PATCH] [RISCV] Add sifive-p450 CPU.

This is an out of order core with no vector unit. More information:
https://www.sifive.com/cores/performance-p450-470

Scheduler model and other tuning will come in separate patches.
---
 clang/test/Misc/target-invalid-cpu-note.c |  4 ++--
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 19 +++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index e840a9208f5a45..48e9f05d9b03de 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -85,7 +85,7 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, 
sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
 
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
@@ -93,4 +93,4 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu, generic, rocket, 
sifive-7-series{{$}}
+// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-p450, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu, generic, 
rocket, sifive-7-series{{$}}
diff --git a/llvm/lib/Target/RISCV/RISCVProcessors.td 
b/llvm/lib/Target/RISCV/RISCVProcessors.td
index 58989fd716fa0e..16c79519fcacc1 100644
--- a/llvm/lib/Target/RISCV/RISCVProcessors.td
+++ b/llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -216,6 +216,25 @@ def SIFIVE_X280 : RISCVProcessorModel<"sifive-x280", 
SiFive7Model,
   [TuneSiFive7,
TuneDLenFactor2]>;
 
+def SIFIVE_P450 : RISCVProcessorModel<"sifive-p450", NoSchedModel,
+  [Feature64Bit,
+   FeatureStdExtZifencei,
+   FeatureStdExtM,
+   FeatureStdExtA,
+   FeatureStdExtF,
+   FeatureStdExtD,
+   FeatureStdExtC,
+   FeatureStdExtZicbop,
+   FeatureStdExtZicbom,
+   FeatureStdExtZicboz,
+   FeatureStdExtZihintntl,
+   FeatureStdExtZihintpause,
+   FeatureStdExtZihpm,
+   FeatureStdExtZba,
+   FeatureStdExtZbb,
+   FeatureStdExtZbs,
+   FeatureStdExtZfhmin]>;
+
 def SYNTACORE_SCR1_BASE : RISCVProcessorModel<"syntacore-scr1-base",
   SyntacoreSCR1Model,
   [Feature32Bit,

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


[clang] [CodeGen] Emit a more accurate alignment for non-temporal loads/stores (PR #75675)

2023-12-17 Thread Akira Hatanaka via cfe-commits

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


[clang] 31429e7 - [CodeGen] Emit a more accurate alignment for non-temporal loads/stores (#75675)

2023-12-17 Thread via cfe-commits

Author: Akira Hatanaka
Date: 2023-12-17T18:22:44-08:00
New Revision: 31429e7a89590f88034920edd3e997aeabff8124

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

LOG: [CodeGen] Emit a more accurate alignment for non-temporal loads/stores 
(#75675)

Call EmitPointerWithAlignment to compute the alignment based on the
underlying lvalue's alignment when it's available.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/Nontemporal.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3327866d2b9623..c96f86a823a461 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -232,19 +232,19 @@ static Value *MakeBinaryAtomicValue(
 
 static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) {
   Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  Value *Address = CGF.EmitScalarExpr(E->getArg(1));
+  Address Addr = CGF.EmitPointerWithAlignment(E->getArg(1));
 
   Val = CGF.EmitToMemory(Val, E->getArg(0)->getType());
-  LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType());
+  LValue LV = CGF.MakeAddrLValue(Addr, E->getArg(0)->getType());
   LV.setNontemporal(true);
   CGF.EmitStoreOfScalar(Val, LV, false);
   return nullptr;
 }
 
 static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) {
-  Value *Address = CGF.EmitScalarExpr(E->getArg(0));
+  Address Addr = CGF.EmitPointerWithAlignment(E->getArg(0));
 
-  LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType());
+  LValue LV = CGF.MakeAddrLValue(Addr, E->getType());
   LV.setNontemporal(true);
   return CGF.EmitLoadOfScalar(LV, E->getExprLoc());
 }

diff  --git a/clang/test/CodeGen/Nontemporal.cpp 
b/clang/test/CodeGen/Nontemporal.cpp
index e14ca18717928d..5052cb225d4111 100644
--- a/clang/test/CodeGen/Nontemporal.cpp
+++ b/clang/test/CodeGen/Nontemporal.cpp
@@ -46,3 +46,17 @@ void test_all_sizes(void) // CHECK-LABEL: 
test_all_sizes
   vf2 = __builtin_nontemporal_load(&vf1); // CHECK: load <4 x 
float>{{.*}}align 16, !nontemporal
   vc2 = __builtin_nontemporal_load(&vc1); // CHECK: load <8 x i8>{{.*}}align 
8, !nontemporal
 }
+
+struct S { char c[16]; };
+S x;
+
+typedef int v4si __attribute__ ((vector_size(16)));
+
+// CHECK-LABEL: define void @_Z14test_alignmentv()
+// CHECK: load <4 x i32>, ptr @x, align 1, !nontemporal
+// CHECK: store <4 x i32> %1, ptr @x, align 1, !nontemporal
+
+void test_alignment() {
+ auto t =  __builtin_nontemporal_load((v4si*)x.c);
+ __builtin_nontemporal_store(t, (v4si*)x.c);
+}



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


[clang] [LinkerWrapper] Forward more arguments to the CPU offloading linker (PR #75757)

2023-12-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
The CPU target currently inherits all the libraries from the normal link
job to ensure that it has access to the same envrionment that the host
does. However, this previously was not respecting argument libraries
that are passed by name rather than `-l` as well as the whole archive
flags. This patch fixes this to allow the CPU linker to correctly pick
up the libraries associated with things like address sanitizers.

Fixes: https://github.com/llvm/llvm-project/issues/75651


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


2 Files Affected:

- (modified) clang/test/Driver/linker-wrapper.c (+4-2) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+25-5) 


``diff
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index b763a003452ba7..e51c5ea381d31a 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -49,10 +49,12 @@
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o 
-fembed-offload-object=%t.out
+// RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
-// RUN:   --linker-path=/usr/bin/ld.lld -- %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=CPU-LINK
+// RUN:   --linker-path=/usr/bin/ld.lld -- --whole-archive %t.a 
--no-whole-archive \
+// RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
-// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared
+// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared 
-Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
 
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
 // RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu 
-mllvm -openmp-opt-disable \
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index bebe76355eb46f..122ba1998eb83f 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -396,11 +396,31 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 CmdArgs.push_back("-Wl,-Bsymbolic");
 CmdArgs.push_back("-shared");
 ArgStringList LinkerArgs;
-for (const opt::Arg *Arg : Args.filtered(OPT_library, OPT_library_path))
-  Arg->render(Args, LinkerArgs);
-for (const opt::Arg *Arg : Args.filtered(OPT_rpath))
-  LinkerArgs.push_back(
-  Args.MakeArgString("-Wl,-rpath," + StringRef(Arg->getValue(;
+for (const opt::Arg *Arg :
+ Args.filtered(OPT_INPUT, OPT_library, OPT_library_path, OPT_rpath,
+   OPT_whole_archive, OPT_no_whole_archive)) {
+  // Sometimes needed libraries are passed by name, such as when using
+  // sanitizers. We need to check the file magic for any libraries.
+  if (Arg->getOption().matches(OPT_INPUT)) {
+if (!sys::fs::exists(Arg->getValue()) ||
+sys::fs::is_directory(Arg->getValue()))
+  continue;
+
+file_magic Magic;
+if (auto EC = identify_magic(Arg->getValue(), Magic))
+  return createStringError(inconvertibleErrorCode(),
+   "Failed to open %s", Arg->getValue());
+if (Magic != file_magic::archive &&
+Magic != file_magic::elf_shared_object)
+  continue;
+  }
+  if (Arg->getOption().matches(OPT_whole_archive))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
+  else if (Arg->getOption().matches(OPT_no_whole_archive))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+  else
+Arg->render(Args, LinkerArgs);
+}
 llvm::copy(LinkerArgs, std::back_inserter(CmdArgs));
   }
 

``




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


[clang] [LinkerWrapper] Forward more arguments to the CPU offloading linker (PR #75757)

2023-12-17 Thread Joseph Huber via cfe-commits

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

Summary:
The CPU target currently inherits all the libraries from the normal link
job to ensure that it has access to the same envrionment that the host
does. However, this previously was not respecting argument libraries
that are passed by name rather than `-l` as well as the whole archive
flags. This patch fixes this to allow the CPU linker to correctly pick
up the libraries associated with things like address sanitizers.

Fixes: https://github.com/llvm/llvm-project/issues/75651


>From 0ba0fa00af551bf8d9f69bec5742bbe4e12a4b58 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Sun, 17 Dec 2023 18:24:46 -0600
Subject: [PATCH] [LinkerWrapper] Forward more arguments to the CPU offloading
 linker

Summary:
The CPU target currently inherits all the libraries from the normal link
job to ensure that it has access to the same envrionment that the host
does. However, this previously was not respecting argument libraries
that are passed by name rather than `-l` as well as the whole archive
flags. This patch fixes this to allow the CPU linker to correctly pick
up the libraries associated with things like address sanitizers.

Fixes: https://github.com/llvm/llvm-project/issues/75651
---
 clang/test/Driver/linker-wrapper.c|  6 ++--
 .../ClangLinkerWrapper.cpp| 30 +++
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index b763a003452ba7..e51c5ea381d31a 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -49,10 +49,12 @@
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o 
-fembed-offload-object=%t.out
+// RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
-// RUN:   --linker-path=/usr/bin/ld.lld -- %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=CPU-LINK
+// RUN:   --linker-path=/usr/bin/ld.lld -- --whole-archive %t.a 
--no-whole-archive \
+// RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
-// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared
+// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared 
-Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
 
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
 // RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu 
-mllvm -openmp-opt-disable \
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index bebe76355eb46f..122ba1998eb83f 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -396,11 +396,31 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 CmdArgs.push_back("-Wl,-Bsymbolic");
 CmdArgs.push_back("-shared");
 ArgStringList LinkerArgs;
-for (const opt::Arg *Arg : Args.filtered(OPT_library, OPT_library_path))
-  Arg->render(Args, LinkerArgs);
-for (const opt::Arg *Arg : Args.filtered(OPT_rpath))
-  LinkerArgs.push_back(
-  Args.MakeArgString("-Wl,-rpath," + StringRef(Arg->getValue(;
+for (const opt::Arg *Arg :
+ Args.filtered(OPT_INPUT, OPT_library, OPT_library_path, OPT_rpath,
+   OPT_whole_archive, OPT_no_whole_archive)) {
+  // Sometimes needed libraries are passed by name, such as when using
+  // sanitizers. We need to check the file magic for any libraries.
+  if (Arg->getOption().matches(OPT_INPUT)) {
+if (!sys::fs::exists(Arg->getValue()) ||
+sys::fs::is_directory(Arg->getValue()))
+  continue;
+
+file_magic Magic;
+if (auto EC = identify_magic(Arg->getValue(), Magic))
+  return createStringError(inconvertibleErrorCode(),
+   "Failed to open %s", Arg->getValue());
+if (Magic != file_magic::archive &&
+Magic != file_magic::elf_shared_object)
+  continue;
+  }
+  if (Arg->getOption().matches(OPT_whole_archive))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
+  else if (Arg->getOption().matches(OPT_no_whole_archive))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+  else
+Arg->render(Args, LinkerArgs);
+}
 llvm::copy(LinkerArgs, std::back_inserter(CmdArgs));
   }
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https:/

[clang] [clang-format] Fix a bug in `IndentExternBlock: NoIndent` (PR #75731)

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

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


[clang] 401f039 - [clang-format] Fix a bug in `IndentExternBlock: NoIndent` (#75731)

2023-12-17 Thread via cfe-commits

Author: Owen Pan
Date: 2023-12-17T15:07:11-08:00
New Revision: 401f0396c3070567ce1ad0b12be7e48713ec0c65

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

LOG: [clang-format] Fix a bug in `IndentExternBlock: NoIndent` (#75731)

Fixes #36620.
Fixes #75719.

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 668e959a9416ba..28271181e07d0c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1315,7 +1315,6 @@ static void expandPresetsBraceWrapping(FormatStyle 
&Expanded) {
 Expanded.BraceWrapping.AfterStruct = true;
 Expanded.BraceWrapping.AfterUnion = true;
 Expanded.BraceWrapping.AfterExternBlock = true;
-Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping.SplitEmptyFunction = true;
 Expanded.BraceWrapping.SplitEmptyRecord = false;
 break;
@@ -1335,7 +1334,6 @@ static void expandPresetsBraceWrapping(FormatStyle 
&Expanded) {
 Expanded.BraceWrapping.AfterStruct = true;
 Expanded.BraceWrapping.AfterUnion = true;
 Expanded.BraceWrapping.AfterExternBlock = true;
-Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping.BeforeCatch = true;
 Expanded.BraceWrapping.BeforeElse = true;
 Expanded.BraceWrapping.BeforeLambdaBody = true;
@@ -1350,7 +1348,6 @@ static void expandPresetsBraceWrapping(FormatStyle 
&Expanded) {
 Expanded.BraceWrapping.AfterObjCDeclaration = true;
 Expanded.BraceWrapping.AfterStruct = true;
 Expanded.BraceWrapping.AfterExternBlock = true;
-Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping.BeforeCatch = true;
 Expanded.BraceWrapping.BeforeElse = true;
 Expanded.BraceWrapping.BeforeLambdaBody = true;
@@ -1375,7 +1372,6 @@ static void expandPresetsBraceWrapping(FormatStyle 
&Expanded) {
 /*SplitEmptyFunction=*/true,
 /*SplitEmptyRecord=*/true,
 /*SplitEmptyNamespace=*/true};
-Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 break;
   case FormatStyle::BS_WebKit:
 Expanded.BraceWrapping.AfterFunction = true;
@@ -1909,7 +1905,6 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind 
Language) {
   Style.BraceWrapping.AfterObjCDeclaration = true;
   Style.BraceWrapping.AfterStruct = true;
   Style.BraceWrapping.AfterExternBlock = true;
-  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
   Style.BraceWrapping.BeforeCatch = true;
   Style.BraceWrapping.BeforeElse = true;
   Style.BraceWrapping.BeforeWhile = false;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 24b2fd599dc397..0e08723aa9e947 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4571,6 +4571,13 @@ TEST_F(FormatTest, IndentExternBlockStyle) {
"}",
Style);
 
+  Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+  verifyFormat("extern \"C\"\n"
+   "{\n"
+   "int i;\n"
+   "}",
+   Style);
+
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterExternBlock = true;
   Style.IndentExternBlock = FormatStyle::IEBS_Indent;



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


[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-17 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 a418be96de7872f6058207c695ef4698cb1dbb93 
957951483dab19b0982a5dbe7d5370bd9061d931 -- 
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 03ac1aa132..658efb619d 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -249,11 +249,11 @@ parseJSON(PathRef Path, llvm::StringRef Data, std::string 
&Error) {
 // thread-safety guarantees, as the access to FS is not locked!
 // For now, use the real FS, which is known to be threadsafe (if we don't
 // use/change working directory, which ExpandResponseFilesDatabase 
doesn't).
-// NOTE: response files have to be expanded before inference because 
inference
-// needs full command line to check/fix driver mode and file type.
+// NOTE: response files have to be expanded before inference because
+// inference needs full command line to check/fix driver mode and file 
type.
 auto FS = llvm::vfs::getRealFileSystem();
 return tooling::inferMissingCompileCommands(
-expandResponseFiles(std::move(CDB), std::move(FS)));
+expandResponseFiles(std::move(CDB), std::move(FS)));
   }
   return nullptr;
 }

``




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


[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Dmitry Polukhin (dmpolukhin)


Changes

Summary:

After https://reviews.llvm.org/D143436 response files stopped working with CDB 
interpolation. It has happened because interpolation removes all unknwn flags 
and extra input files. Response file is treated as an extra input because it is 
not a flag. Moreover inference needs full command line for driver mode and file 
type detection so all response files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file 
expansion before inference. Response file expansion in CommandMangler keep 
working for CDB pushed via LSP and will do nothing if all response files are 
already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/GlobalCompilationDatabase.cpp (+10-1) 


``diff
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d1833759917a30..03ac1aa132d0bf 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -244,7 +244,16 @@ static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string &Error) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
   Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
-return tooling::inferMissingCompileCommands(std::move(CDB));
+// FS used for expanding response files.
+// FIXME: ExpandResponseFilesDatabase appears not to provide the usual
+// thread-safety guarantees, as the access to FS is not locked!
+// For now, use the real FS, which is known to be threadsafe (if we don't
+// use/change working directory, which ExpandResponseFilesDatabase 
doesn't).
+// NOTE: response files have to be expanded before inference because 
inference
+// needs full command line to check/fix driver mode and file type.
+auto FS = llvm::vfs::getRealFileSystem();
+return tooling::inferMissingCompileCommands(
+expandResponseFiles(std::move(CDB), std::move(FS)));
   }
   return nullptr;
 }

``




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


[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-17 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/75753

Summary:

After https://reviews.llvm.org/D143436 response files stopped working with CDB 
interpolation. It has happened because interpolation removes all unknwn flags 
and extra input files. Response file is treated as an extra input because it is 
not a flag. Moreover inference needs full command line for driver mode and file 
type detection so all response files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file 
expansion before inference. Response file expansion in CommandMangler keep 
working for CDB pushed via LSP and will do nothing if all response files are 
already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:

>From 957951483dab19b0982a5dbe7d5370bd9061d931 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Sun, 17 Dec 2023 14:11:11 -0800
Subject: [PATCH] [clangd] Expand response files before CDB interpolation

Summary:

After https://reviews.llvm.org/D143436 response files stopped working
with CDB interpolation. It has happened because interpolation removes
all unknwn flags and extra input files. Response file is treated as an
extra input because it is not a flag. Moreover inference needs full
command line for driver mode and file type detection so all response
files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file
expansion before inference. Response file expansion in CommandMangler
keep working for CDB pushed via LSP and will do nothing if all response
files are already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:
---
 .../clangd/GlobalCompilationDatabase.cpp  | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d1833759917a30..03ac1aa132d0bf 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -244,7 +244,16 @@ static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string &Error) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
   Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
-return tooling::inferMissingCompileCommands(std::move(CDB));
+// FS used for expanding response files.
+// FIXME: ExpandResponseFilesDatabase appears not to provide the usual
+// thread-safety guarantees, as the access to FS is not locked!
+// For now, use the real FS, which is known to be threadsafe (if we don't
+// use/change working directory, which ExpandResponseFilesDatabase 
doesn't).
+// NOTE: response files have to be expanded before inference because 
inference
+// needs full command line to check/fix driver mode and file type.
+auto FS = llvm::vfs::getRealFileSystem();
+return tooling::inferMissingCompileCommands(
+expandResponseFiles(std::move(CDB), std::move(FS)));
   }
   return nullptr;
 }

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


[clang] [clang-format] Fix a bug in `IndentExternBlock: NoIndent` (PR #75731)

2023-12-17 Thread Björn Schäpers via cfe-commits

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


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


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

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

H-G-Hristov wrote:

> Thanks for the fixes, LGTM!

Thank you!

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


[clang] [flang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

2023-12-17 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

Hi @ergawy , thanks for this contribution! Could you add a test that would 
demonstrate compilation failing without `-pthread`?

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


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

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

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

Thanks for the fixes, LGTM!

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


[llvm] [clang-tools-extra] [clang] Add out-of-line-atomics support to GlobalISel (PR #74588)

2023-12-17 Thread Amara Emerson via cfe-commits

https://github.com/aemerson commented:

Not an expert on atomics, but why would we have a libcall for -O0 but not for 
O1 in the tests?

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


[clang] [clang-tools-extra] [llvm] Add out-of-line-atomics support to GlobalISel (PR #74588)

2023-12-17 Thread Amara Emerson via cfe-commits

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


[clang-tools-extra] [llvm] [clang] Add out-of-line-atomics support to GlobalISel (PR #74588)

2023-12-17 Thread Amara Emerson via cfe-commits


@@ -765,6 +766,138 @@ llvm::createMemLibcall(MachineIRBuilder &MIRBuilder, 
MachineRegisterInfo &MRI,
   return LegalizerHelper::Legalized;
 }
 
+static RTLIB::Libcall getOutlineAtomicLibcall(MachineInstr &MI) {
+  unsigned Opc = MI.getOpcode();
+  auto &AtomicMI = cast(MI);
+  auto &MMO = AtomicMI.getMMO();
+  auto Ordering = MMO.getMergedOrdering();
+  LLT MemType = MMO.getMemoryType();
+  uint64_t MemSize = MemType.getSizeInBytes();
+  if (!MemType.isScalar())
+return RTLIB::UNKNOWN_LIBCALL;
+
+#define LCALLS(A, B)   
\
+  { A##B##_RELAX, A##B##_ACQ, A##B##_REL, A##B##_ACQ_REL }
+#define LCALL5(A)  
\
+  LCALLS(A, 1), LCALLS(A, 2), LCALLS(A, 4), LCALLS(A, 8), LCALLS(A, 16)
+  switch (Opc) {
+  case TargetOpcode::G_ATOMIC_CMPXCHG:
+  case TargetOpcode::G_ATOMIC_CMPXCHG_WITH_SUCCESS: {
+const RTLIB::Libcall LC[5][4] = {LCALL5(RTLIB::OUTLINE_ATOMIC_CAS)};
+return getOutlineAtomicHelper(LC, Ordering, MemSize);
+  }
+  case TargetOpcode::G_ATOMICRMW_XCHG: {
+const RTLIB::Libcall LC[5][4] = {LCALL5(RTLIB::OUTLINE_ATOMIC_SWP)};
+return getOutlineAtomicHelper(LC, Ordering, MemSize);
+  }
+  case TargetOpcode::G_ATOMICRMW_ADD:
+  case TargetOpcode::G_ATOMICRMW_SUB: {
+const RTLIB::Libcall LC[5][4] = {LCALL5(RTLIB::OUTLINE_ATOMIC_LDADD)};
+return getOutlineAtomicHelper(LC, Ordering, MemSize);
+  }
+  case TargetOpcode::G_ATOMICRMW_AND: {
+const RTLIB::Libcall LC[5][4] = {LCALL5(RTLIB::OUTLINE_ATOMIC_LDCLR)};
+return getOutlineAtomicHelper(LC, Ordering, MemSize);
+  }
+  case TargetOpcode::G_ATOMICRMW_OR: {
+const RTLIB::Libcall LC[5][4] = {LCALL5(RTLIB::OUTLINE_ATOMIC_LDSET)};
+return getOutlineAtomicHelper(LC, Ordering, MemSize);
+  }
+  case TargetOpcode::G_ATOMICRMW_XOR: {
+const RTLIB::Libcall LC[5][4] = {LCALL5(RTLIB::OUTLINE_ATOMIC_LDEOR)};
+return getOutlineAtomicHelper(LC, Ordering, MemSize);
+  }
+  default:
+return RTLIB::UNKNOWN_LIBCALL;
+  }
+#undef LCALLS
+#undef LCALL5
+}
+
+static LegalizerHelper::LegalizeResult
+createAtomicLibcall(MachineIRBuilder &MIRBuilder, MachineInstr &MI) {
+  auto &Ctx = MIRBuilder.getMF().getFunction().getContext();
+  MachineRegisterInfo &MRI = *MIRBuilder.getMRI();
+
+  // Add all the args, except for the last which is an imm denoting 'tail'.
+  // const CallLowering::ArgInfo &Result,

aemerson wrote:

stray comment

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-17 Thread via cfe-commits

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


[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-17 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 18959c46e3ced1f7ad12a82e9f30bafe9d1f1733 
b4113714159824b517779a3635f4d24d21dd338f -- 
clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp 
b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
index d6d8973e44..0ebb48b609 100644
--- a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
+++ b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
@@ -109,8 +109,7 @@ int main(int argc, const char **argv) {
   callee(memberExpr().bind("member")),
   callee(cxxMethodDecl(
   ofClass(hasName(target_type)),
-  hasAnyName("cast", "dyn_cast", "dyn_cast_or_null", "isa")
-  )))
+  hasAnyName("cast", "dyn_cast", "dyn_cast_or_null", "isa"
   .bind("memberCall");
 
   MemberFunctionCallMatcher memCallExpr;

``




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


[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-17 Thread via cfe-commits

https://github.com/lipracer updated 
https://github.com/llvm/llvm-project/pull/75279

>From b4113714159824b517779a3635f4d24d21dd338f Mon Sep 17 00:00:00 2001
From: lipracer 
Date: Wed, 13 Dec 2023 11:37:12 +0800
Subject: [PATCH] [NFC][clang] add a clang tool for mlir refactor

---
 clang-tools-extra/CMakeLists.txt  |   1 +
 .../mlir-cast-refactor/CMakeLists.txt |  18 ++
 .../mlir-cast-refactor/MlirCastRefactor.cpp   | 173 ++
 3 files changed, 192 insertions(+)
 create mode 100644 clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
 create mode 100644 clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp

diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index 6a3f741721ee6c..44e4f02dca3326 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -27,6 +27,7 @@ add_subdirectory(include-cleaner)
 add_subdirectory(pp-trace)
 add_subdirectory(pseudo)
 add_subdirectory(tool-template)
+add_subdirectory(mlir-cast-refactor)
 
 option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang 
Extra Tools docs."
   ${LLVM_INCLUDE_DOCS})
diff --git a/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt 
b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
new file mode 100644
index 00..ebdabf23fc53c3
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_executable(mlirCastRefactor
+  MlirCastRefactor.cpp
+  )
+target_link_libraries(mlirCastRefactor
+  PRIVATE
+clangAST
+clangBasic
+clangFormat
+clangFrontend
+clangLex
+clangRewrite
+clangSerialization
+clangTooling
+clangToolingCore
+clangToolingRefactoring
+  )
\ No newline at end of file
diff --git a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp 
b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
new file mode 100644
index 00..d6d8973e44a6b5
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
@@ -0,0 +1,173 @@
+//===-- MlirCastRefactor.cpp - mlir refactor implementation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace clang::tooling;
+using namespace llvm;
+
+// Apply a custom category to all command-line options so that they are the
+// only ones displayed.
+static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+static cl::opt target_type("target-type",
+cl::desc("refactoring type name"),
+cl::value_desc("type name"),
+cl::ValueRequired, cl::NotHidden,
+cl::cat(MyToolCategory));
+
+// CommonOptionsParser declares HelpMessage with a description of the common
+// command-line options related to the compilation database and input files.
+// It's nice to have this help message in all tools.
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+
+// A help message for this specific tool can be added afterwards.
+static cl::extrahelp MoreHelp("\nMore help text...\n");
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+class MemberFunctionCallMatcher : public MatchFinder::MatchCallback {
+public:
+  void run(const MatchFinder::MatchResult &Result) override {
+if (const CXXMemberCallExpr *MemberCall =
+Result.Nodes.getNodeAs("memberCall")) {
+  auto objExpr = MemberCall->getImplicitObjectArgument();
+  auto endLoc = MemberCall->getExprLoc();
+
+  auto exprRange = objExpr->getSourceRange();
+
+  SourceLocation StartLoc = objExpr->getBeginLoc();
+
+  const SourceManager &SM = *Result.SourceManager;
+  const char *StartPtr = SM.getCharacterData(StartLoc);
+  const char *EndPtr = SM.getCharacterData(endLoc);
+
+  tooling::AtomicChange change(*Result.SourceManager,
+   MemberCall->getExprLoc());
+  const auto *ME = Result.Nodes.getNodeAs("member");
+  size_t dropbackCount = ME->isArrow() ? 2 : 1;
+
+  {
+auto length = EndPtr - StartPtr;
+objExprStrings.emplace_back(StartPtr, length);
+change.replace(*Result.SourceManager, StartLoc, EndPtr - StartPtr, "");
+  }
+
+  {
+// remove keyword template e.g. obj->tem

[flang] [clang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

2023-12-17 Thread Kareem Ergawy via cfe-commits

https://github.com/ergawy updated 
https://github.com/llvm/llvm-project/pull/75739

>From 395b56fa481e0cd90adf98534f3b60a3cfc8f52b Mon Sep 17 00:00:00 2001
From: ergawy 
Date: Sun, 17 Dec 2023 06:29:49 -0600
Subject: [PATCH] [flang][Driver] Support `-pthread` to the frontend.

Adds `-pthread` option to flang. Since the GNU toolchain already adds
the required linker flag, we only need to declare `FlangOption` as one
of the supported options for `-pthread`.
---
 clang/include/clang/Driver/Options.td| 2 +-
 flang/test/Driver/driver-help-hidden.f90 | 1 +
 flang/test/Driver/driver-help.f90| 1 +
 flang/test/Driver/dynamic-linker.f90 | 3 ++-
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b02087425b751..b8b8d476413982 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5297,7 +5297,7 @@ def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+  NegFlag, BothFlags<[], [ClangOption, CC1Option, FlangOption]>>;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 9a11a7a571ffcc..39c607b80ddb98 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -134,6 +134,7 @@
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
+! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
 ! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index e0e74dc56f331e..51c59694f1570a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -pedantic   Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
+! HELP-NEXT: -pthreadSupport POSIX threads in generated code
 ! HELP-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/dynamic-linker.f90 
b/flang/test/Driver/dynamic-linker.f90
index df119c22a2ea51..57a2af01aadff7 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -1,7 +1,7 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
+! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared 
-pthread \
 ! RUN: -static %s 2>&1 | FileCheck \
 ! RUN: --check-prefixes=GNU-LINKER-OPTIONS %s
 ! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
@@ -13,6 +13,7 @@
 ! GNU-LINKER-OPTIONS-SAME: "-shared"
 ! GNU-LINKER-OPTIONS-SAME: "-static"
 ! GNU-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"
+! GNU-LINKER-OPTIONS-SAME: "-lpthread"
 
 ! For MSVC, adding -static does not add any additional linker options.
 ! MSVC-LINKER-OPTIONS: "{{.*}}link{{(.exe)?}}"

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


[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)

2023-12-17 Thread Qizhi Hu via cfe-commits


@@ -9284,6 +9284,26 @@ TEST_P(ASTImporterOptionSpecificTestBase,
   // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportFunctionAutoType) {

jcsxky wrote:

Code has been fixed.

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


[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)

2023-12-17 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/74991

>From 6bb37862cb6b09fd252d991d5f3ce0d2208bedac Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 10 Dec 2023 21:01:49 +0800
Subject: [PATCH] [clang][ASTImporter] add processing of
 SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf

---
 clang/lib/AST/ASTImporter.cpp   |  8 +++-
 clang/unittests/AST/ASTImporterTest.cpp | 20 
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f1f335118f37a4..e0eed03ce22b51 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3418,10 +3418,16 @@ static bool isAncestorDeclContextOf(const DeclContext 
*DC, const Stmt *S) {
   while (!ToProcess.empty()) {
 const Stmt *CurrentS = ToProcess.pop_back_val();
 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
-if (const auto *DeclRef = dyn_cast(CurrentS))
+if (const auto *DeclRef = dyn_cast(CurrentS)) {
   if (const Decl *D = DeclRef->getDecl())
 if (isAncestorDeclContextOf(DC, D))
   return true;
+} else if (const auto *E =
+   dyn_cast_or_null(CurrentS)) {
+  if (const Decl *D = E->getAssociatedDecl())
+if (isAncestorDeclContextOf(DC, D))
+  return true;
+}
   }
   return false;
 }
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 4dd7510bf8ddf8..4c06152d3eb563 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -7250,6 +7250,26 @@ TEST_P(ImportAutoFunctions, ReturnWithAutoTemplateType) {
   Lang_CXX14, /*FindLast=*/true);
 }
 
+TEST_P(ImportAutoFunctions, ReturnWithSubstNonTypeTemplateParmExpr) {
+  const char *Code =
+  R"(
+  template
+  struct array {};
+
+  template 
+  auto foo() { return array(); }
+
+  void bar() { foo<0>(); }
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX17);
+
+  auto *FromBar = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("bar")));
+
+  auto *ToBar = Import(FromBar, Lang_CXX17);
+  EXPECT_TRUE(ToBar);
+}
+
 struct ImportSourceLocations : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ImportSourceLocations, PreserveFileIDTreeStructure) {

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


[flang] [clang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

2023-12-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-flang-driver

Author: Kareem Ergawy (ergawy)


Changes

Adds `-pthread` option to flang. Since the GNU toolchain already adds the 
required linker flag, we only need to declare `FlangOption` as one of the 
supported options for `-pthread`.

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) flang/test/Driver/dynamic-linker.f90 (+2-1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b02087425b751..b8b8d476413982 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5297,7 +5297,7 @@ def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+  NegFlag, BothFlags<[], [ClangOption, CC1Option, FlangOption]>>;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/dynamic-linker.f90 
b/flang/test/Driver/dynamic-linker.f90
index df119c22a2ea51..57a2af01aadff7 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -1,7 +1,7 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
+! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared 
-pthread \
 ! RUN: -static %s 2>&1 | FileCheck \
 ! RUN: --check-prefixes=GNU-LINKER-OPTIONS %s
 ! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
@@ -13,6 +13,7 @@
 ! GNU-LINKER-OPTIONS-SAME: "-shared"
 ! GNU-LINKER-OPTIONS-SAME: "-static"
 ! GNU-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"
+! GNU-LINKER-OPTIONS-SAME: "-lpthread"
 
 ! For MSVC, adding -static does not add any additional linker options.
 ! MSVC-LINKER-OPTIONS: "{{.*}}link{{(.exe)?}}"

``




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


[flang] [clang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

2023-12-17 Thread Kareem Ergawy via cfe-commits

https://github.com/ergawy created 
https://github.com/llvm/llvm-project/pull/75739

Adds `-pthread` option to flang. Since the GNU toolchain already adds the 
required linker flag, we only need to declare `FlangOption` as one of the 
supported options for `-pthread`.

>From 2880ebc7f3eec9f0c03747c7a2d92e608b111f3c Mon Sep 17 00:00:00 2001
From: ergawy 
Date: Sun, 17 Dec 2023 06:29:49 -0600
Subject: [PATCH] [flang][Driver] Support `-pthread` to the frontend.

Adds `-pthread` option to flang. Since the GNU toolchain already adds
the required linker flag, we only need to declare `FlangOption` as one
of the supported options for `-pthread`.
---
 clang/include/clang/Driver/Options.td | 2 +-
 flang/test/Driver/dynamic-linker.f90  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b02087425b751..b8b8d476413982 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5297,7 +5297,7 @@ def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+  NegFlag, BothFlags<[], [ClangOption, CC1Option, FlangOption]>>;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/dynamic-linker.f90 
b/flang/test/Driver/dynamic-linker.f90
index df119c22a2ea51..57a2af01aadff7 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -1,7 +1,7 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
+! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared 
-pthread \
 ! RUN: -static %s 2>&1 | FileCheck \
 ! RUN: --check-prefixes=GNU-LINKER-OPTIONS %s
 ! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
@@ -13,6 +13,7 @@
 ! GNU-LINKER-OPTIONS-SAME: "-shared"
 ! GNU-LINKER-OPTIONS-SAME: "-static"
 ! GNU-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"
+! GNU-LINKER-OPTIONS-SAME: "-lpthread"
 
 ! For MSVC, adding -static does not add any additional linker options.
 ! MSVC-LINKER-OPTIONS: "{{.*}}link{{(.exe)?}}"

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


[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)

2023-12-17 Thread Qizhi Hu via cfe-commits


@@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase,
   // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1);
 }
 
+const internal::VariadicDynCastAllOfMatcher
+builtinBitCastExpr;
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) {
+  const char *CodeFrom =
+  R"(
+  void foo(int T) { (void)__builtin_bit_cast(float, T); }
+  )";
+  Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20);
+  auto *FromFoo = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+  auto *ToFoo = Import(FromFoo, Lang_CXX20);
+  EXPECT_TRUE(ToFoo);
+  auto *ToBuiltinBitCastExpr =
+  FirstDeclMatcher().match(ToFoo, 
builtinBitCastExpr());
+  EXPECT_TRUE(ToBuiltinBitCastExpr);
+}

jcsxky wrote:

Another testcase has been added to `ImportExpr`

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


[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)

2023-12-17 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/74813

>From 4e2ac40eece61343b5947ae906e5a4be8a82c823 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 8 Dec 2023 15:26:01 +0800
Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr

---
 clang/lib/AST/ASTImporter.cpp   | 12 
 clang/unittests/AST/ASTImporterTest.cpp | 24 
 2 files changed, 36 insertions(+)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f1f335118f37a4..0edb6930ed0a00 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -7820,6 +7820,18 @@ ExpectedStmt 
ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
   }
+  case Stmt::BuiltinBitCastExprClass: {
+auto *BBC = cast(E);
+ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
+if (!ToKWLocOrErr)
+  return ToKWLocOrErr.takeError();
+ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
+if (!ToRParenLocOrErr)
+  return ToRParenLocOrErr.takeError();
+return new (Importer.getToContext()) BuiltinBitCastExpr(
+ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
+ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
+  }
   default:
 llvm_unreachable("Cast expression of unsupported type!");
 return make_error(ASTImportError::UnsupportedConstruct);
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 4dd7510bf8ddf8..82174ddc07de22 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -3220,6 +3220,12 @@ TEST_P(ImportExpr, UnresolvedMemberExpr) {
  compoundStmt(has(callExpr(has(unresolvedMemberExpr());
 }
 
+TEST_P(ImportExpr, BuiltinBitCastExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport(int T) { (void)__builtin_bit_cast(float, T); 
}",
+ Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl());
+}
+
 class ImportImplicitMethods : public ASTImporterOptionSpecificTestBase {
 public:
   static constexpr auto DefaultCode = R"(
@@ -9284,6 +9290,24 @@ TEST_P(ASTImporterOptionSpecificTestBase,
   // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1);
 }
 
+const internal::VariadicDynCastAllOfMatcher
+builtinBitCastExpr;
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) {
+  const char *CodeFrom =
+  R"(
+  void foo(int T) { (void)__builtin_bit_cast(float, T); }
+  )";
+  Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20);
+  auto *FromFoo = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+  auto *ToFoo = Import(FromFoo, Lang_CXX20);
+  EXPECT_TRUE(ToFoo);
+  auto *ToBuiltinBitCastExpr =
+  FirstDeclMatcher().match(ToFoo, 
builtinBitCastExpr());
+  EXPECT_TRUE(ToBuiltinBitCastExpr);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

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


[clang-tools-extra] [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (PR #75061)

2023-12-17 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

+- fine, fix pointed out nits and could land

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


[clang-tools-extra] [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (PR #75061)

2023-12-17 Thread Piotr Zegar via cfe-commits


@@ -51,8 +52,22 @@ void MisleadingIndentationCheck::danglingElseCheck(const 
SourceManager &SM,
 diag(ElseLoc, "different indentation for 'if' and corresponding 'else'");
 }
 
-void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
-const CompoundStmt *CStmt) 
{
+static bool isAtStartOfLineIncludingEmptyMacro(SourceLocation NextLoc,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  NextLoc.dump(SM);
+  const SourceLocation BeforeLoc =

PiotrZSL wrote:

verify that source locations are valid

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


[clang-tools-extra] [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (PR #75061)

2023-12-17 Thread Piotr Zegar via cfe-commits


@@ -51,8 +52,22 @@ void MisleadingIndentationCheck::danglingElseCheck(const 
SourceManager &SM,
 diag(ElseLoc, "different indentation for 'if' and corresponding 'else'");
 }
 
-void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
-const CompoundStmt *CStmt) 
{
+static bool isAtStartOfLineIncludingEmptyMacro(SourceLocation NextLoc,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  NextLoc.dump(SM);

PiotrZSL wrote:

remove debug

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


[clang-tools-extra] [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (PR #75061)

2023-12-17 Thread Piotr Zegar via cfe-commits


@@ -51,8 +52,22 @@ void MisleadingIndentationCheck::danglingElseCheck(const 
SourceManager &SM,
 diag(ElseLoc, "different indentation for 'if' and corresponding 'else'");
 }
 
-void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
-const CompoundStmt *CStmt) 
{
+static bool isAtStartOfLineIncludingEmptyMacro(SourceLocation NextLoc,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  NextLoc.dump(SM);
+  const SourceLocation BeforeLoc =
+  utils::lexer::getPreviousTokenAndStart(NextLoc, SM, LangOpts).second;
+  if (SM.getExpansionLineNumber(BeforeLoc) ==

PiotrZSL wrote:

return X != Y;

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


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

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


@@ -0,0 +1,168 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (...) {

mordante wrote:

please apply this change to similar places too,

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


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

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


@@ -0,0 +1,168 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (...) {
+  assert(false);
+}
+  }
+
+  {
+std::array arr{};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(0);
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);

mordante wrote:

```suggestion
  LIBCPP_ASSERT(e.what() == "span"s);
```
This assert should only be tested for libc++. This means on other 
implementations the `e` is unused.

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


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

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

https://github.com/mordante commented:

A few more comments, I overlooked parts of them yesterday.

Please make sure to apply the suggestions to all similar places in the code.

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


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

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

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


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

2023-12-17 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

`MachO/lto-module-asm-err.ll` needs update?

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-tools-extra] [clang] [OpenMP] atomic compare fail : Codegen support (PR #75709)

2023-12-17 Thread via cfe-commits

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


[clang] [AArch64][SME2] Add builtins for FDOT, BFDOT, SUDOT, USDOT, SDOT, UDOT. (PR #75737)

2023-12-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Dinar Temirbulatov (dtemirbulatov)


Changes

Add SME2 DOT builtins.

---

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


5 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+66) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+22) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_fp_dots.c (+297) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_int_dots.c 
(+1103) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vdot.c (+222) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index fcff6fe35b7ba3..a67540d243cde7 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -313,6 +313,72 @@ let TargetGuard = "sme2" in {
   def SVBMOPA : Inst<"svbmopa_za32[_{d}]_m", "viPPdd", "iUi", MergeNone, 
"aarch64_sme_bmopa_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
 
   def SVBMOPS : Inst<"svbmops_za32[_{d}]_m", "viPPdd", "iUi", MergeNone, 
"aarch64_sme_bmops_za32", [IsSharedZA, IsStreaming], [ImmCheck<0, 
ImmCheck0_3>]>;
+
+  // VERTICAL DOT-PRODUCT
+  def SVVDOT_LANE_ZA32_VG1x2_S : Inst<"svvdot_lane_za32[_{d}]_vg1x2", "vm2di", 
"s", MergeNone, "aarch64_sme_svdot_lane_za32_vg1x2", [IsStreaming, IsSharedZA], 
[ImmCheck<3, ImmCheck0_3>]>;
+  def SVVDOT_LANE_ZA32_VG1x4_S : Inst<"svvdot_lane_za32[_{d}]_vg1x4", "vm4di", 
"c", MergeNone, "aarch64_sme_svdot_lane_za32_vg1x4", [IsStreaming, IsSharedZA], 
[ImmCheck<3, ImmCheck0_3>]>;
+  def SVVDOT_LANE_ZA32_VG1x2_U : Inst<"svvdot_lane_za32[_{d}]_vg1x2", "vm2di", 
"Us", MergeNone, "aarch64_sme_uvdot_lane_za32_vg1x2", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+  def SVVDOT_LANE_ZA32_VG1x4_U : Inst<"svvdot_lane_za32[_{d}]_vg1x4", "vm4di", 
"Uc", MergeNone, "aarch64_sme_uvdot_lane_za32_vg1x4", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+  def SVVDOT_LANE_ZA32_VG1x2_F : Inst<"svvdot_lane_za32[_{d}]_vg1x2", "vm2di", 
"hb", MergeNone, "aarch64_sme_fvdot_lane_za32_vg1x2", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+  def SVSUVDOT_LANE_ZA32_VG1x4 : Inst<"svsuvdot_lane_za32[_{d}]_vg1x4", 
"vm4di", "c", MergeNone, "aarch64_sme_suvdot_lane_za32_vg1x4", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+  def SVUSVDOT_LANE_ZA32_VG1x4 : Inst<"svusvdot_lane_za32[_{d}]_vg1x4", 
"vm4di", "Uc", MergeNone, "aarch64_sme_usvdot_lane_za32_vg1x4", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+
+  // Multi-vector signed & unsigned integer dot-product
+  def SVDOT_SINGLE_ZA32_VG1x2_S : Inst<"svdot[_single]_za32[_{d}]_vg1x2", 
"vm2d", "cs", MergeNone, "aarch64_sme_sdot_single_za32_vg1x2", [IsStreaming, 
IsSharedZA], []>;
+  def SVDOT_SINGLE_ZA32_VG1x4_S : Inst<"svdot[_single]_za32[_{d}]_vg1x4", 
"vm4d", "cs", MergeNone, "aarch64_sme_sdot_single_za32_vg1x4", [IsStreaming, 
IsSharedZA], []>;
+  def SVDOT_SINGLE_ZA32_VG1x2_U : Inst<"svdot[_single]_za32[_{d}]_vg1x2", 
"vm2d", "UcUs", MergeNone, "aarch64_sme_udot_single_za32_vg1x2", [IsStreaming, 
IsSharedZA], []>;
+  def SVDOT_SINGLE_ZA32_VG1x4_U : Inst<"svdot[_single]_za32[_{d}]_vg1x4", 
"vm4d", "UcUs", MergeNone, "aarch64_sme_udot_single_za32_vg1x4", [IsStreaming, 
IsSharedZA], []>;
+  def SVDOT_MULTI_ZA32_VG1x2_S  : Inst<"svdot_za32[_{d}]_vg1x2", "vm22", "cs", 
MergeNone, "aarch64_sme_sdot_za32_vg1x2", [IsStreaming, IsSharedZA], []>;
+  def SVDOT_MULTI_ZA32_VG1x4_S  : Inst<"svdot_za32[_{d}]_vg1x4", "vm44", "cs", 
MergeNone, "aarch64_sme_sdot_za32_vg1x4", [IsStreaming, IsSharedZA], []>;
+  def SVDOT_MULTI_ZA32_VG1x2_U  : Inst<"svdot_za32[_{d}]_vg1x2", "vm22", 
"UcUs", MergeNone, "aarch64_sme_udot_za32_vg1x2", [IsStreaming, IsSharedZA], 
[]>;
+  def SVDOT_MULTI_ZA32_VG1x4_U  : Inst<"svdot_za32[_{d}]_vg1x4", "vm44", 
"UcUs", MergeNone, "aarch64_sme_udot_za32_vg1x4", [IsStreaming, IsSharedZA], 
[]>;
+  def SVDOT_LANE_ZA32_VG1x2_S   : Inst<"svdot_lane_za32[_{d}]_vg1x2", "vm2di", 
"cs", MergeNone, "aarch64_sme_sdot_lane_za32_vg1x2", [IsStreaming, IsSharedZA], 
[ImmCheck<3, ImmCheck0_3>]>;
+  def SVDOT_LANE_ZA32_VG1x4_S   : Inst<"svdot_lane_za32[_{d}]_vg1x4", "vm4di", 
"cs", MergeNone, "aarch64_sme_sdot_lane_za32_vg1x4", [IsStreaming, IsSharedZA], 
[ImmCheck<3, ImmCheck0_3>]>;
+  def SVDOT_LANE_ZA32_VG1x2_U   : Inst<"svdot_lane_za32[_{d}]_vg1x2", "vm2di", 
"UcUs", MergeNone, "aarch64_sme_udot_lane_za32_vg1x2", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+  def SVDOT_LANE_ZA32_VG1x4_U   : Inst<"svdot_lane_za32[_{d}]_vg1x4", "vm4di", 
"UcUs", MergeNone, "aarch64_sme_udot_lane_za32_vg1x4", [IsStreaming, 
IsSharedZA], [ImmCheck<3, ImmCheck0_3>]>;
+
+  def SVUSDOT_SINGLE_ZA32_VG1x2 : Inst<"svusdot[_single]_za32[_{d}]_vg1x2", 
"vm2.dx", "Uc", MergeNone, "aarch64_sme_usdot_single_za32_vg1x2", [IsStreaming, 
IsSharedZA], []>;
+  def SVUSDOT_SINGLE_ZA32_VG1x4 : 

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

2023-12-17 Thread via cfe-commits

ChipsSpectre wrote:

The changes are squashed into one commit now.

Sorry for the force push, it was needed to rebase on main.

Do you think it can be merged now?

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-17 Thread via cfe-commits

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

>From f5029be3d1dc8714cd4ccb42efe4c1f07c1c7dd0 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 17 Dec 2023 10:09:16 +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..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
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 &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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


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

2023-12-17 Thread via cfe-commits

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

>From 8a3e710de9122ac74ab886f8878e01893c19ee87 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 17 Dec 2023 10:01:39 +0100
Subject: [PATCH 1/4] [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 ++
 .../Vector/Transforms/VectorTransforms.h  | 10 --
 .../Transforms/LowerVectorTranspose.cpp   | 34 +--
 6 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
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 &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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 '('}}
diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h 
b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
index 41ffc929946027..08d3bb157a0e39 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
@@ -59,16 +59,6 @@ struct VectorTransformsOptions {
 vectorTransferSplit = opt;
 return *this;
   }
-
-  /// Option to control if vector.transpose can lower to a vector.shape_cast.
-  /// TODO: ATM it's not possible to lower `vector.shape_cast` to SPIR-V
-  /// and hence the need for this opt-out. Once the missing support has been
-  /// added, this option can be removed.
-  bool useShapeCast = true;
-  VectorTransformsOptions &setUseShapeCast(bool opt = true) {
-useShapeCast = opt;
-return *this;
-  }
 };
 
 
//===--===//
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp 
b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
index 4d43a76c4a4efc..97f6caca1b25cc 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
@@ -334,24 +334,22 @@ class TransposeOpLowering : public 
OpRewritePattern {
   return rewriter.notifyMatchFailure(
   op, "Options specifies lowering to shuffle");
 
-if (vectorTransformOptions.useShapeCast) {
-  // Replace:
-  //   vector.transpose %0, [1, 0] : vector> to
-  // vector<1xnxelty>
-  // with:
-  //   vector.shape_cast %0 : vector> to vector

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

2023-12-17 Thread via cfe-commits

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

>From 8a3e710de9122ac74ab886f8878e01893c19ee87 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 17 Dec 2023 10:01:39 +0100
Subject: [PATCH 1/3] [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 ++
 .../Vector/Transforms/VectorTransforms.h  | 10 --
 .../Transforms/LowerVectorTranspose.cpp   | 34 +--
 6 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
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 &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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 '('}}
diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h 
b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
index 41ffc929946027..08d3bb157a0e39 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
@@ -59,16 +59,6 @@ struct VectorTransformsOptions {
 vectorTransferSplit = opt;
 return *this;
   }
-
-  /// Option to control if vector.transpose can lower to a vector.shape_cast.
-  /// TODO: ATM it's not possible to lower `vector.shape_cast` to SPIR-V
-  /// and hence the need for this opt-out. Once the missing support has been
-  /// added, this option can be removed.
-  bool useShapeCast = true;
-  VectorTransformsOptions &setUseShapeCast(bool opt = true) {
-useShapeCast = opt;
-return *this;
-  }
 };
 
 
//===--===//
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp 
b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
index 4d43a76c4a4efc..97f6caca1b25cc 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
@@ -334,24 +334,22 @@ class TransposeOpLowering : public 
OpRewritePattern {
   return rewriter.notifyMatchFailure(
   op, "Options specifies lowering to shuffle");
 
-if (vectorTransformOptions.useShapeCast) {
-  // Replace:
-  //   vector.transpose %0, [1, 0] : vector> to
-  // vector<1xnxelty>
-  // with:
-  //   vector.shape_cast %0 : vector> to vector

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

2023-12-17 Thread via cfe-commits

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

>From 8a3e710de9122ac74ab886f8878e01893c19ee87 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 17 Dec 2023 10:01:39 +0100
Subject: [PATCH 1/2] [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 ++
 .../Vector/Transforms/VectorTransforms.h  | 10 --
 .../Transforms/LowerVectorTranspose.cpp   | 34 +--
 6 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
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 &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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 '('}}
diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h 
b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
index 41ffc929946027..08d3bb157a0e39 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
@@ -59,16 +59,6 @@ struct VectorTransformsOptions {
 vectorTransferSplit = opt;
 return *this;
   }
-
-  /// Option to control if vector.transpose can lower to a vector.shape_cast.
-  /// TODO: ATM it's not possible to lower `vector.shape_cast` to SPIR-V
-  /// and hence the need for this opt-out. Once the missing support has been
-  /// added, this option can be removed.
-  bool useShapeCast = true;
-  VectorTransformsOptions &setUseShapeCast(bool opt = true) {
-useShapeCast = opt;
-return *this;
-  }
 };
 
 
//===--===//
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp 
b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
index 4d43a76c4a4efc..97f6caca1b25cc 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
@@ -334,24 +334,22 @@ class TransposeOpLowering : public 
OpRewritePattern {
   return rewriter.notifyMatchFailure(
   op, "Options specifies lowering to shuffle");
 
-if (vectorTransformOptions.useShapeCast) {
-  // Replace:
-  //   vector.transpose %0, [1, 0] : vector> to
-  // vector<1xnxelty>
-  // with:
-  //   vector.shape_cast %0 : vector> to vector

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

2023-12-17 Thread via cfe-commits

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

>From 8a3e710de9122ac74ab886f8878e01893c19ee87 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 17 Dec 2023 10:01:39 +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 ++
 .../Vector/Transforms/VectorTransforms.h  | 10 --
 .../Transforms/LowerVectorTranspose.cpp   | 34 +--
 6 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
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 &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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 '('}}
diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h 
b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
index 41ffc929946027..08d3bb157a0e39 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
@@ -59,16 +59,6 @@ struct VectorTransformsOptions {
 vectorTransferSplit = opt;
 return *this;
   }
-
-  /// Option to control if vector.transpose can lower to a vector.shape_cast.
-  /// TODO: ATM it's not possible to lower `vector.shape_cast` to SPIR-V
-  /// and hence the need for this opt-out. Once the missing support has been
-  /// added, this option can be removed.
-  bool useShapeCast = true;
-  VectorTransformsOptions &setUseShapeCast(bool opt = true) {
-useShapeCast = opt;
-return *this;
-  }
 };
 
 
//===--===//
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp 
b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
index 4d43a76c4a4efc..97f6caca1b25cc 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
@@ -334,24 +334,22 @@ class TransposeOpLowering : public 
OpRewritePattern {
   return rewriter.notifyMatchFailure(
   op, "Options specifies lowering to shuffle");
 
-if (vectorTransformOptions.useShapeCast) {
-  // Replace:
-  //   vector.transpose %0, [1, 0] : vector> to
-  // vector<1xnxelty>
-  // with:
-  //   vector.shape_cast %0 : vector> to vector<1xn

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

2023-12-17 Thread via cfe-commits

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

>From dad78484118bbd0a662915df0b4ce50c24d3bf42 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sat, 9 Dec 2023 12:07:02 +0100
Subject: [PATCH 1/2] fix issue 73559.

---
 clang/lib/Parse/ParseDecl.cpp| 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

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..eba7ea65beee94 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (TryAnnotateCXXScopeToken())
+if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
   MalformedTypeSpec = true;
 
 bool isAccessDecl;

>From 84b14beea4c2a106c656058efc72aec6afb36853 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 17 Dec 2023 10:00:31 +0100
Subject: [PATCH 2/2] [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/ParseDeclCXX.cpp  |  4 ++-
 clang/test/Parser/cxx-in-c.c  |  3 ++
 .../Vector/Transforms/VectorTransforms.h  | 10 --
 .../Transforms/LowerVectorTranspose.cpp   | 34 +--
 5 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index eba7ea65beee94..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2679,6 +2679,8 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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);
@@ -2702,7 +2704,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
+if (TryAnnotateCXXScopeToken())
   MalformedTypeSpec = true;
 
 bool isAccessDecl;
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 '('}}
diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h 
b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
index 41ffc929946027..08d3bb157a0e39 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
@@ -59,16 +59,6 @@ struct VectorTransformsOptions {
 vectorTransferSplit = opt;
 return *this;
   }
-
-  /// Option to control if v

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

2023-12-17 Thread via cfe-commits
Andrzej =?utf-8?q?Warzyński?= ,ChipsSpectre
 
Message-ID:
In-Reply-To: 


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

>From dad78484118bbd0a662915df0b4ce50c24d3bf42 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sat, 9 Dec 2023 12:07:02 +0100
Subject: [PATCH 1/5] fix issue 73559.

---
 clang/lib/Parse/ParseDecl.cpp| 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

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..eba7ea65beee94 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (TryAnnotateCXXScopeToken())
+if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
   MalformedTypeSpec = true;
 
 bool isAccessDecl;

>From a1985517ddca97dd5779014690d80caaa31f8cb4 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Mon, 11 Dec 2023 22:31:10 +0100
Subject: [PATCH 2/5] address review comments.

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Parse/ParseDeclCXX.cpp | 6 --
 clang/test/Parser/cxx-in-c.c | 1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..59f131ea79465f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index eba7ea65beee94..89a97cc96111d8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,7 +2678,9 @@ Parser::DeclGroupPtrTy
 Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
-   ParsingDeclRAIIObject *TemplateDiags) {
+   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);
@@ -2702,7 +2704,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
+if (TryAnnotateCXXScopeToken())
   MalformedTypeSpec = true;
 
 bool isAccessDecl;
diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index f5fa39bd0cb99b..bd304260571c4d 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,3 +3,4 @@
 // 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}}
+::; // expected-error{{expected that double colon marker does not appear in c}}

>From d2de13285fdf460bd049ab7ec3bbdf5c595bb1ad Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Mon, 11 Dec 2023 22:35:17 +0100
Subject: [PATCH 3/5] enforce coding style

---
 clang/lib/Parse/ParseDeclCXX.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 89a97cc96111d8..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,9 +2678,9 @@ Parser::DeclGroupPtrTy
 Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,

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

2023-12-17 Thread via cfe-commits
Andrzej =?utf-8?q?Warzyński?= ,ChipsSpectre
 ,ChipsSpectre 
Message-ID:
In-Reply-To: 


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

>From dad78484118bbd0a662915df0b4ce50c24d3bf42 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sat, 9 Dec 2023 12:07:02 +0100
Subject: [PATCH 1/6] fix issue 73559.

---
 clang/lib/Parse/ParseDecl.cpp| 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

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..eba7ea65beee94 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (TryAnnotateCXXScopeToken())
+if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
   MalformedTypeSpec = true;
 
 bool isAccessDecl;

>From a1985517ddca97dd5779014690d80caaa31f8cb4 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Mon, 11 Dec 2023 22:31:10 +0100
Subject: [PATCH 2/6] address review comments.

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Parse/ParseDeclCXX.cpp | 6 --
 clang/test/Parser/cxx-in-c.c | 1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..59f131ea79465f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index eba7ea65beee94..89a97cc96111d8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,7 +2678,9 @@ Parser::DeclGroupPtrTy
 Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
-   ParsingDeclRAIIObject *TemplateDiags) {
+   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);
@@ -2702,7 +2704,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
+if (TryAnnotateCXXScopeToken())
   MalformedTypeSpec = true;
 
 bool isAccessDecl;
diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index f5fa39bd0cb99b..bd304260571c4d 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,3 +3,4 @@
 // 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}}
+::; // expected-error{{expected that double colon marker does not appear in c}}

>From d2de13285fdf460bd049ab7ec3bbdf5c595bb1ad Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Mon, 11 Dec 2023 22:35:17 +0100
Subject: [PATCH 3/6] enforce coding style

---
 clang/lib/Parse/ParseDeclCXX.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 89a97cc96111d8..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,9 +2678,9 @@ Parser::DeclGroupPtrTy
 Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
  

[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-17 Thread via cfe-commits

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


[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-17 Thread via cfe-commits

https://github.com/lipracer updated 
https://github.com/llvm/llvm-project/pull/75279

>From 2f54363dbb45b538bde09252a602ad911c3c8751 Mon Sep 17 00:00:00 2001
From: lipracer 
Date: Wed, 13 Dec 2023 11:37:12 +0800
Subject: [PATCH] [NFC][clang] add a clang tool for mlir refactor

---
 clang-tools-extra/CMakeLists.txt  |   1 +
 .../mlir-cast-refactor/CMakeLists.txt |  18 ++
 .../mlir-cast-refactor/MlirCastRefactor.cpp   | 174 ++
 3 files changed, 193 insertions(+)
 create mode 100644 clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
 create mode 100644 clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp

diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index 6a3f741721ee6c..44e4f02dca3326 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -27,6 +27,7 @@ add_subdirectory(include-cleaner)
 add_subdirectory(pp-trace)
 add_subdirectory(pseudo)
 add_subdirectory(tool-template)
+add_subdirectory(mlir-cast-refactor)
 
 option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang 
Extra Tools docs."
   ${LLVM_INCLUDE_DOCS})
diff --git a/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt 
b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
new file mode 100644
index 00..ebdabf23fc53c3
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_executable(mlirCastRefactor
+  MlirCastRefactor.cpp
+  )
+target_link_libraries(mlirCastRefactor
+  PRIVATE
+clangAST
+clangBasic
+clangFormat
+clangFrontend
+clangLex
+clangRewrite
+clangSerialization
+clangTooling
+clangToolingCore
+clangToolingRefactoring
+  )
\ No newline at end of file
diff --git a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp 
b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
new file mode 100644
index 00..e665bed3391586
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
@@ -0,0 +1,174 @@
+//===-- MlirCastRefactor.cpp - mlir refactor implementation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace clang::tooling;
+using namespace llvm;
+
+// Apply a custom category to all command-line options so that they are the
+// only ones displayed.
+static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+static cl::opt target_type("target-type",
+cl::desc("refactoring type name"),
+cl::value_desc("type name"),
+cl::ValueRequired, cl::NotHidden,
+cl::cat(MyToolCategory));
+
+// CommonOptionsParser declares HelpMessage with a description of the common
+// command-line options related to the compilation database and input files.
+// It's nice to have this help message in all tools.
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+
+// A help message for this specific tool can be added afterwards.
+static cl::extrahelp MoreHelp("\nMore help text...\n");
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+class MemberFunctionCallMatcher : public MatchFinder::MatchCallback {
+public:
+  void run(const MatchFinder::MatchResult &Result) override {
+if (const CXXMemberCallExpr *MemberCall =
+Result.Nodes.getNodeAs("memberCall")) {
+  auto objExpr = MemberCall->getImplicitObjectArgument();
+  auto endLoc = MemberCall->getExprLoc();
+
+  auto exprRange = objExpr->getSourceRange();
+
+  SourceLocation StartLoc = objExpr->getBeginLoc();
+
+  const SourceManager &SM = *Result.SourceManager;
+  const char *StartPtr = SM.getCharacterData(StartLoc);
+  const char *EndPtr = SM.getCharacterData(endLoc);
+
+  tooling::AtomicChange change(*Result.SourceManager,
+   MemberCall->getExprLoc());
+  const auto *ME = Result.Nodes.getNodeAs("member");
+  size_t dropbackCount = ME->isArrow() ? 2 : 1;
+
+  {
+auto length = EndPtr - StartPtr;
+objExprStrings.emplace_back(StartPtr, length);
+change.replace(*Result.SourceManager, StartLoc, EndPtr - StartPtr, "");
+  }
+
+  {
+// remove keyword template e.g. obj->tem

[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-17 Thread via cfe-commits

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