[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/68521

>From 65db5951e3c30b6c2a112b590839fad6b8ec2944 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Sun, 8 Oct 2023 07:12:45 -0400
Subject: [PATCH] MIPS/libunwind: Use -mfp64 if compiler is FPXX

Libunwind supports FP64 and FP32 modes, but not FPXX.
The reason is that, FP64 and FP32 have different way to save/restore
FPRs. If libunwind is built as FPXX, we have no idea which one should
we use.

If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are FP32.

So if the compiler is FPXX, which is the default value of most toolchain,
let's switch it to FP64.
---
 libunwind/CMakeLists.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index bb1b052f61d87..806d5a783ec39 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH 
"${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
 "Specify path to libc++ source.")
 
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 
#===
 # Setup CMake Options
@@ -96,6 +97,20 @@ endif()
 option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." 
${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
 
+# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
+# 
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
+check_symbol_exists(__mips_hard_float "" __MIPSHF)
+check_symbol_exists(_ABIO32 "" __MIPS_O32)
+if (__MIPSHF AND __MIPS_O32)
+  file(WRITE 
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+"#if __mips_fpr != 0\n"
+"# error\n"
+"#endif\n")
+  try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
+${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
+endif()
+
 
#===
 # Configure System
 
#===
@@ -179,6 +194,10 @@ if (WIN32)
   add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
 endif()
 
+if (MIPS_FPABI_FPXX)
+  add_compile_flags(-mfp64)
+endif()
+
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C

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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-02 Thread via cfe-commits

https://github.com/joyhou-hw updated 
https://github.com/llvm/llvm-project/pull/80401

>From 2ecfbf64322a34276a5821b6b24c2e0d62797aeb Mon Sep 17 00:00:00 2001
From: houzhenyu 
Date: Fri, 2 Feb 2024 11:21:50 +0800
Subject: [PATCH] [X86] [iamcu] Fix wrong alignment value for attr (aligned)
 with -miamcu

attribute ((aligned)) should be 4 for -miamcu.
---
 clang/lib/Basic/Targets/X86.h  |  1 +
 clang/test/Sema/attr-aligned.c | 10 --
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0026d8781c8fa 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -672,6 +672,7 @@ class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public 
X86_32TargetInfo {
   MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
+DefaultAlignForAttributeAligned = 32;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
 resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-"
 "f64:32-f128:32-n8:16:32-a:0:32-S32");
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..97edfe6ac1644 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,10 +1,9 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is 
not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested 
alignment must be 4294967296 bytes or smaller}}
 int y __attribute__((aligned(1ull << 32)));
-// GH50534
-int z __attribute__((aligned((__int128_t)0x1234567890abcde0ULL << 64))); // 
expected-error {{requested alignment must be 4294967296 bytes or smaller}}
 
 // PR26444
 int y __attribute__((aligned(1 << 29)));
@@ -12,8 +11,15 @@ int y __attribute__((aligned(1 << 28)));
 
 // PR3254
 short g0[3] __attribute__((aligned));
+#ifdef __iamcu
+short g0_chk[__alignof__(g0) == 4 ? 1 : -1];
+#else
 short g0_chk[__alignof__(g0) == 16 ? 1 : -1];
 
+// GH50534
+int z __attribute__((aligned((__int128_t)0x1234567890abcde0ULL << 64))); // 
expected-error {{requested alignment must be 4294967296 bytes or smaller}}
+#endif
+
 typedef char ueber_aligned_char __attribute__((aligned(8)));
 
 struct struct_with_ueber_char {

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


[polly] [clang] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-02-02 Thread Owen Pan via cfe-commits

owenca wrote:

I don't think the buildkite failure is related to this PR, but I like to wait 
for a couple of days before merging in case others have any comments.

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


[llvm] [clang] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

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


[llvm] [clang] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From af69ccc8182f8a1e86637b75a8fb1e717b157354 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 +++
 .../CodeGen/Mips/inline-asm-constraints.c | 18 +
 clang/test/Sema/inline-asm-validate-mips.c|  8 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +---
 .../Mips/inlineasm-constraints-softfloat.ll   | 25 +++
 5 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/inline-asm-constraints.c
 create mode 100644 clang/test/Sema/inline-asm-validate-mips.c
 create mode 100644 llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/CodeGen/Mips/inline-asm-constraints.c 
b/clang/test/CodeGen/Mips/inline-asm-constraints.c
new file mode 100644
index 0..0a4cb0b34570e
--- /dev/null
+++ b/clang/test/CodeGen/Mips/inline-asm-constraints.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=float -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_SINGLE
+
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=double -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_DOUBLE
+
+#ifdef SOFT_FLOAT_CONSTRAINT_R
+// SOFT_FLOAT_CONSTRAINT_R_SINGLE: call void asm sideeffect "", 
"r,~{$1}"(float %2) #1, !srcloc !2
+// SOFT_FLOAT_CONSTRAINT_R_DOUBLE: call void asm sideeffect "", 
"r,~{$1}"(double %2) #1, !srcloc !2
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_CONSTRAINT_R
diff --git a/clang/test/Sema/inline-asm-validate-mips.c 
b/clang/test/Sema/inline-asm-validate-mips.c
new file mode 100644
index 0..a56c75f0859a6
--- /dev/null
+++ b/clang/test/Sema/inline-asm-validate-mips.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mips -target-feature +soft-float 
-DSOFT_FLOAT_NO_CONSTRAINT_F -fsyntax-only -verify %s
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result)); // expected-error{{invalid input constraint 'f' 
in asm}}
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df..97e830cec27ca 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, &Mips::CPU16RegsRegClass);
 return std::make_pair(0U, &Mips::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, &Mips::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return std::make_pair(0U, &Mips::GPR64RegClass);
   // This will generate an error message
   return std::make_pair(0U, nullptr);
diff --git a/llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll 
b/llvm/test/CodeGen/Mips/inlinea

[polly] [clang] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-02-02 Thread via cfe-commits

rmarker wrote:

Thanks, @owenca.
Don't know if you want to wait for any others to look it over.
I had a look at the buildkite check failure. Not sure if it is related to the 
changes in the PR?
In any case, I'll need someone to merge for me when the time is right.

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


[llvm] [clang] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread Fangrui Song via cfe-commits

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


[llvm] [clang] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread Fangrui Song via cfe-commits


@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+

MaskRay wrote:

test/Driver should only test how the driver passes options to cc1.

For inline assembly, you usually test that clangCodeGen correctly generates 
LLVM IR and the backend can lower asm. See `#77886` (x86 "Ws") for a good 
example (I carefully add tests. Many early-day asm patches might not add 
appropriate tests.)

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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-02 Thread via cfe-commits

https://github.com/joyhou-hw updated 
https://github.com/llvm/llvm-project/pull/80401

>From 834e55dbf7ac54ad7d006866ae4da3190f2197aa Mon Sep 17 00:00:00 2001
From: houzhenyu 
Date: Fri, 2 Feb 2024 11:21:50 +0800
Subject: [PATCH] [X86] [iamcu] Fix wrong alignment value for attr (aligned)
 with -miamcu

attribute ((aligned)) should be 4 for -miamcu.
---
 clang/lib/Basic/Targets/X86.h  | 1 +
 clang/test/Sema/attr-aligned.c | 5 +
 2 files changed, 6 insertions(+)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0026d8781c8fa 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -672,6 +672,7 @@ class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public 
X86_32TargetInfo {
   MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
+DefaultAlignForAttributeAligned = 32;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
 resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-"
 "f64:32-f128:32-n8:16:32-a:0:32-S32");
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..bdd48e7268285 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is 
not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested 
alignment must be 4294967296 bytes or smaller}}
@@ -12,7 +13,11 @@ int y __attribute__((aligned(1 << 28)));
 
 // PR3254
 short g0[3] __attribute__((aligned));
+#ifdef __iamcu
+short g0_chk[__alignof__(g0) == 4 ? 1 : -1];
+#else
 short g0_chk[__alignof__(g0) == 16 ? 1 : -1];
+#endif
 
 typedef char ueber_aligned_char __attribute__((aligned(8)));
 

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


[lldb] [libcxx] [clang] [libc] [libcxxabi] [flang] [llvm] [lld] [msan] Unpoison indirect outputs for userspace using memset for large operands (PR #79924)

2024-02-02 Thread Fangrui Song via cfe-commits

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


[lldb] [libcxx] [clang] [libc] [libcxxabi] [flang] [llvm] [lld] [msan] Unpoison indirect outputs for userspace using memset for large operands (PR #79924)

2024-02-02 Thread Fangrui Song via cfe-commits


@@ -4552,16 +4552,22 @@ struct MemorySanitizerVisitor : public 
InstVisitor {
 }
 if (!ElemTy->isSized())
   return;
-Value *SizeVal =
-  IRB.CreateTypeSize(MS.IntptrTy, DL.getTypeStoreSize(ElemTy));
+auto Size = DL.getTypeStoreSize(ElemTy);
+Value *SizeVal = IRB.CreateTypeSize(MS.IntptrTy, Size);
 if (MS.CompileKernel) {
   IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Operand, SizeVal});
 } else {
   // ElemTy, derived from elementtype(), does not encode the alignment of
   // the pointer. Conservatively assume that the shadow memory is 
unaligned.
+  // When Size is large, avoid StoreInst as it would expand to many
+  // instructions.
   auto [ShadowPtr, _] =
   getShadowOriginPtrUserspace(Operand, IRB, IRB.getInt8Ty(), Align(1));
-  IRB.CreateAlignedStore(getCleanShadow(ElemTy), ShadowPtr, Align(1));
+  if (Size <= 32)

MaskRay wrote:

Thanks for your previous comment about the interceptor. The committed patch 
does contain this description:
"The intrinsic, if lowered to libcall, will use the msan interceptor."

Inline asm isn't commonly used:) This patch is for `=m` in extended asm, which 
I believe is typically used with small objects. I guess 32 and 64 won't make a 
difference.

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


[clang] [polly] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-02-02 Thread Owen Pan via cfe-commits

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


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


[clang] [Driver] Unify InstalledDir and Dir (PR #80527)

2024-02-02 Thread Fangrui Song via cfe-commits

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


[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)

2024-02-02 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> > changing the structure of the symlinks is not possible, it is done 
> > automatically by a tool.
> 
> To be fair: tools can be changed, and in fact you're proposing to change one 
> ;)
> 
> But that said, now I see what you're up against.

I am more convinced that we should unify `InstalledDir` and `Dir`.
Right now include and library paths are partially derived from 
`Dir`/`ResourceDir` (derived from `ClangExecutable`) and partially derived from 
`InstalledDir`.

I believe that `InstalledDir` (2010 88979914d7e1666c4f32d41223cb614cdedf1f41) 
was a partial solution when `-no-canonical-prefixes` (2009) did not work well. 
`InstalledDir` should eventually be removed.

Created #80527

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


[clang] [Driver] Unify InstalledDir and Dir (PR #80527)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

`Driver::ClangExecutable` is derived from:

* (-canonical-prefixes default): `realpath` on the executable path
* (-no-canonical-prefixes) argv[0] (consult PATH if argv[0] is a word)

`Dir` and `ResourceDir` are derived from `ClangExecutable`. Both
variables are used to derive certain include and library paths.

`InstalledDir` is a related concept used to derive certain other paths.
`InstalledDir` is weird in the -canonical-prefixes mode: Clang
calls `make_absolute` but does not follow symlinks
(FIXME from 9ade6a9a747c49383ac747bd8ffaa6a0beaef71c).
This causes some search and library paths to be mix-and-matched.

I believe `InstalledDir` was a partial solution to
`-no-canonical-prefixes` and should be eventually removed.

This patch removes `SetInstallDir` and relies on Driver::Driver to set
`InstalledDir` to `Dir`. The behavior for regular file `clang` or
`-no-canonical-prefixes` is unchanged.

If a user creates a symlink to the regular file `clang` and uses the
default `-canonical-prefixes`, they now consistently get search and
library paths relative to the regular file `clang`, not mix-and-match
paths.

If a user creates a symlink to the regular file `clang` and replaces
some directorys from the actual installation, they should change the
symlink to a wrapper that calls the underlying clang with
`-no-canonical-prefixes`.


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


7 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+1-2) 
- (modified) clang/test/Driver/darwin-header-search-libcxx.cpp (+1-1) 
- (modified) clang/test/Driver/mingw-sysroot.cpp (+7-5) 
- (modified) clang/test/Driver/no-canonical-prefixes.c (+1-1) 
- (modified) clang/test/Driver/program-path-priority.c (+8-5) 
- (modified) clang/test/Driver/rocm-detect.hip (+2-2) 
- (modified) clang/tools/driver/driver.cpp (-23) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9..afd388dfaf017 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -160,7 +160,7 @@ class Driver {
   /// Target and driver mode components extracted from clang executable name.
   ParsedClangName ClangNameParts;
 
-  /// The path to the installed clang directory, if any.
+  /// TODO: Remove this in favor of Dir.
   std::string InstalledDir;
 
   /// The path to the compiler resource directory.
@@ -419,7 +419,6 @@ class Driver {
   return InstalledDir.c_str();
 return Dir.c_str();
   }
-  void setInstalledDir(StringRef Value) { InstalledDir = std::string(Value); }
 
   bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
   bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
diff --git a/clang/test/Driver/darwin-header-search-libcxx.cpp 
b/clang/test/Driver/darwin-header-search-libcxx.cpp
index 70cc06090a993..5695f53683bab 100644
--- a/clang/test/Driver/darwin-header-search-libcxx.cpp
+++ b/clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -193,7 +193,7 @@
 // RUN: ln -sf %t/install/bin/clang %t/symlinked1/bin/clang
 // RUN: mkdir -p %t/symlinked1/include/c++/v1
 
-// RUN: %t/symlinked1/bin/clang -### %s -fsyntax-only 2>&1 \
+// RUN: %t/symlinked1/bin/clang -### %s -no-canonical-prefixes -fsyntax-only 
2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
diff --git a/clang/test/Driver/mingw-sysroot.cpp 
b/clang/test/Driver/mingw-sysroot.cpp
index 50152b2ca210d..5d512e6669709 100644
--- a/clang/test/Driver/mingw-sysroot.cpp
+++ b/clang/test/Driver/mingw-sysroot.cpp
@@ -50,10 +50,12 @@
 // CHECK_TESTROOT_GCC_EXPLICIT: "-internal-isystem" 
"{{[^"]+}}/testroot-gcc{{/|}}include"
 
 
-// If there's a matching sysroot next to the clang binary itself, prefer that
+// If -no-canonical-prefixes and there's a matching sysroot next to the clang 
binary itself, prefer that
 // over a gcc in the path:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_GCC2 %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 
-no-canonical-prefixes 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG %s
+// CHECK_TESTROOT_GCC2: 
"{{[^"]+}}/testroot-gcc{{/|}}x86_64-w64-mingw32{{/|}}include"
 // CHECK_TESTROOT_CLANG: 
"{{[^"]+}}/testroot-clang{{/|}}x86_64-w64-mingw32{{/|}}i

[clang] [Driver] Unify InstalledDir and Dir (PR #80527)

2024-02-02 Thread Fangrui Song via cfe-commits

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

`Driver::ClangExecutable` is derived from:

* (-canonical-prefixes default): `realpath` on the executable path
* (-no-canonical-prefixes) argv[0] (consult PATH if argv[0] is a word)

`Dir` and `ResourceDir` are derived from `ClangExecutable`. Both
variables are used to derive certain include and library paths.

`InstalledDir` is a related concept used to derive certain other paths.
`InstalledDir` is weird in the -canonical-prefixes mode: Clang
calls `make_absolute` but does not follow symlinks
(FIXME from 9ade6a9a747c49383ac747bd8ffaa6a0beaef71c).
This causes some search and library paths to be mix-and-matched.

I believe `InstalledDir` was a partial solution to
`-no-canonical-prefixes` and should be eventually removed.

This patch removes `SetInstallDir` and relies on Driver::Driver to set
`InstalledDir` to `Dir`. The behavior for regular file `clang` or
`-no-canonical-prefixes` is unchanged.

If a user creates a symlink to the regular file `clang` and uses the
default `-canonical-prefixes`, they now consistently get search and
library paths relative to the regular file `clang`, not mix-and-match
paths.

If a user creates a symlink to the regular file `clang` and replaces
some directorys from the actual installation, they should change the
symlink to a wrapper that calls the underlying clang with
`-no-canonical-prefixes`.


>From 0d249fb7ee4c53922d2a620822feb550f477e9b9 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Fri, 2 Feb 2024 20:38:17 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Driver/Driver.h   |  3 +--
 .../Driver/darwin-header-search-libcxx.cpp|  2 +-
 clang/test/Driver/mingw-sysroot.cpp   | 12 ++
 clang/test/Driver/no-canonical-prefixes.c |  2 +-
 clang/test/Driver/program-path-priority.c | 13 +++
 clang/test/Driver/rocm-detect.hip |  4 ++--
 clang/tools/driver/driver.cpp | 23 ---
 7 files changed, 20 insertions(+), 39 deletions(-)

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9..afd388dfaf017 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -160,7 +160,7 @@ class Driver {
   /// Target and driver mode components extracted from clang executable name.
   ParsedClangName ClangNameParts;
 
-  /// The path to the installed clang directory, if any.
+  /// TODO: Remove this in favor of Dir.
   std::string InstalledDir;
 
   /// The path to the compiler resource directory.
@@ -419,7 +419,6 @@ class Driver {
   return InstalledDir.c_str();
 return Dir.c_str();
   }
-  void setInstalledDir(StringRef Value) { InstalledDir = std::string(Value); }
 
   bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
   bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
diff --git a/clang/test/Driver/darwin-header-search-libcxx.cpp 
b/clang/test/Driver/darwin-header-search-libcxx.cpp
index 70cc06090a993..5695f53683bab 100644
--- a/clang/test/Driver/darwin-header-search-libcxx.cpp
+++ b/clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -193,7 +193,7 @@
 // RUN: ln -sf %t/install/bin/clang %t/symlinked1/bin/clang
 // RUN: mkdir -p %t/symlinked1/include/c++/v1
 
-// RUN: %t/symlinked1/bin/clang -### %s -fsyntax-only 2>&1 \
+// RUN: %t/symlinked1/bin/clang -### %s -no-canonical-prefixes -fsyntax-only 
2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
diff --git a/clang/test/Driver/mingw-sysroot.cpp 
b/clang/test/Driver/mingw-sysroot.cpp
index 50152b2ca210d..5d512e6669709 100644
--- a/clang/test/Driver/mingw-sysroot.cpp
+++ b/clang/test/Driver/mingw-sysroot.cpp
@@ -50,10 +50,12 @@
 // CHECK_TESTROOT_GCC_EXPLICIT: "-internal-isystem" 
"{{[^"]+}}/testroot-gcc{{/|}}include"
 
 
-// If there's a matching sysroot next to the clang binary itself, prefer that
+// If -no-canonical-prefixes and there's a matching sysroot next to the clang 
binary itself, prefer that
 // over a gcc in the path:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_GCC2 %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=l

[clang] 82a3214 - [Clang][Sema] Fix crash with const qualified member operator new (#80327)

2024-02-02 Thread via cfe-commits

Author: Shafik Yaghmour
Date: 2024-02-02T20:26:54-08:00
New Revision: 82a32140acb52472241f04644cdcf88a4cf4bee8

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

LOG: [Clang][Sema] Fix crash with const qualified member operator new (#80327)

We should diagnose a const qualified member operator new but we fail to
do so and this leads to crash during debug info generation.

The fix is to diagnose this as ill-formed in the front-end.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/function-type-qual.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52..7ed1dff17f397 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,8 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix crash and diagnostic with const qualified member operator new.
+  Fixes (`#79748 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 7cee73d5d6bae..aee2c9c4a7ded 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5907,6 +5907,11 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //  - the type-id in the default argument of a type-parameter, or
 //  - the type-id of a template-argument for a type-parameter
 //
+// C++23 [dcl.fct]p6 (P0847R7)
+// ... A member-declarator with an explicit-object-parameter-declaration
+// shall not include a ref-qualifier or a cv-qualifier-seq and shall not be
+// declared static or virtual ...
+//
 // FIXME: Checking this here is insufficient. We accept-invalid on:
 //
 //   template struct S { void f(T); };
@@ -5914,8 +5919,12 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //
 // ... for instance.
 if (IsQualifiedFunction &&
-!(Kind == Member && !D.isExplicitObjectMemberFunction() &&
-  D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
+// Check for non-static member function and not and
+// explicit-object-parameter-declaration
+(Kind != Member || D.isExplicitObjectMemberFunction() ||
+ D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+ (D.getContext() == clang::DeclaratorContext::Member &&
+  D.isStaticMember())) &&
 !IsTypedefName && D.getContext() != DeclaratorContext::TemplateArg &&
 D.getContext() != DeclaratorContext::TemplateTypeArg) {
   SourceLocation Loc = D.getBeginLoc();

diff  --git a/clang/test/SemaCXX/function-type-qual.cpp 
b/clang/test/SemaCXX/function-type-qual.cpp
index bb25c17e83bdf..f4906f58abbae 100644
--- a/clang/test/SemaCXX/function-type-qual.cpp
+++ b/clang/test/SemaCXX/function-type-qual.cpp
@@ -37,3 +37,21 @@ void instantiateArrayDecay() {
   int a[1];
   arrayDecay(a);
 }
+
+namespace GH79748 {
+typedef decltype(sizeof(0)) size_t;
+struct A {
+  void* operator new(size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+  void* operator new[](size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+
+  void operator delete(void*) const; //expected-error {{static member function 
cannot have 'const' qualifier}}
+  void operator delete[](void*) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+};
+struct B {
+  void* operator new(size_t bytes) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+  void* operator new[](size_t bytes) volatile; //expected-error {{static 
member function cannot have 'volatile' qualifier}}
+
+  void operator delete(void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+  void operator delete[](void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+};
+}



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


[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread Shafik Yaghmour via cfe-commits

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Also in the issue: https://github.com/llvm/llvm-project/issues/80510 you 
pointed out a crash bug. We should have the bug covered in the test case as 
well.

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-02 Thread Shafik Yaghmour via cfe-commits


@@ -108,3 +109,22 @@ int computed_with_lambda = [] {
   return result;
 }();
 #endif
+
+#if __cplusplus >= 201703L
+namespace DynamicFileScopeLiteral {
+// This covers the case where we have a file-scope compound literal with a
+// non-constant initializer in C++. Previously, we had a bug where Clang forgot
+// to consider initializer list elements for bases.
+struct Empty {};
+struct Foo : Empty {
+  int x;
+  int y;
+};
+int f();
+Foo o = (Foo){
+  {},
+  1,
+  f() // expected-error {{initializer element is not a compile-time constant}}

shafik wrote:

gcc accepts this: https://godbolt.org/z/enWrG56je

Why do we believe this should be rejected?

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-02 Thread Shafik Yaghmour via cfe-commits


@@ -3342,6 +3342,18 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool 
IsForRef,
 if (ILE->getType()->isRecordType()) {
   unsigned ElementNo = 0;
   RecordDecl *RD = ILE->getType()->castAs()->getDecl();
+
+  // Check bases for C++17 aggregate initializers.

shafik wrote:

Should we be checking `CPlusPlus17` here? 

Also I would like to see a standard quote in the comments. I know we are not 
doing this locally but these are really helpful and we should be doing this 
more consistently.

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


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-02 Thread Daniel Rodríguez Troitiño via cfe-commits

drodriguez wrote:

@ilg-ul: you might be interested in reviewing this changes, since they change 
the behaviour you introduced in #70817 when `-isysroot` is provided.

If some folks at Apple reads this: it would be preferable to have the actual 
code instead of trying to guess which is the internal behaviour of Apple Clang. 
I will be happy to close this PR if the original code (or a "censored" version 
of it) can be upstreamed. Thanks!

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


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Daniel Rodríguez Troitiño (drodriguez)


Changes

The current Apple Clang behaviour is to prefer `-isysroot` vs libc++ headers 
side-by-side the compiler. This has been like that for several Xcode versions, 
at least since Xcode 14.

The code was originally written in D89001 chosing the order that was correct at 
the time for Apple Clang. In 2023 D157283 tried to flip the order to match the 
current Apple Clang, but was reverted in 
3197357b7e39a58bc7eb0600eb337ac2a1c8c225 because it brokes two tests. The code 
was further changed in #70817 to add a third option.

The changes in this commit try to match Apple Clang, and incorporate the 
changes in #70817, as well as fixing the tests that broke when D157283 
was applied.

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


4 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+16-16) 
- (modified) clang/test/Driver/darwin-header-search-libcxx.cpp (+21-20) 
- (modified) clang/test/Tooling/clang-check-mac-libcxx-abspath.cpp (+2-1) 
- (modified) clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp (+2-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fae8ad1a958ad..004a19284ee4a 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2515,20 +2515,31 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
 // On Darwin, libc++ can be installed in one of the following places:
-// 1. Alongside the compiler in /include/c++/v1
-// 2. Alongside the compiler in /../include/c++/v1
-// 3. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 1. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 2. Alongside the compiler in /include/c++/v1
+// 3. Alongside the compiler in /../include/c++/v1
 //
 // The precedence of paths is as listed above, i.e. we take the first path
 // that exists. Note that we never include libc++ twice -- we take the 
first
 // path that exists and don't send the other paths to CC1 (otherwise
 // include_next could break).
 //
-// Also note that in most cases, (1) and (2) are exactly the same path.
+// Also note that in most cases, (2) and (3) are exactly the same path.
 // Those two paths will differ only when the `clang` program being run
 // is actually a symlink to the real executable.
 
 // Check for (1)
+llvm::SmallString<128> SysrootUsr = Sysroot;
+llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
+if (getVFS().exists(SysrootUsr)) {
+  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
+  return;
+} else if (DriverArgs.hasArg(options::OPT_v)) {
+  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
+   << "\"\n";
+}
+
+// Check for (2)
 // Get from '/bin' to '/include/c++/v1'.
 // Note that InstallBin can be relative, so we use '..' instead of
 // parent_path.
@@ -2543,7 +2554,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
<< "\"\n";
 }
 
-// (2) Check for the folder where the executable is located, if different.
+// (3) Check for the folder where the executable is located, if different.
 if (getDriver().getInstalledDir() != getDriver().Dir) {
   InstallBin = llvm::StringRef(getDriver().Dir);
   llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
@@ -2556,17 +2567,6 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   }
 }
 
-// Otherwise, check for (3)
-llvm::SmallString<128> SysrootUsr = Sysroot;
-llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
-if (getVFS().exists(SysrootUsr)) {
-  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
-  return;
-} else if (DriverArgs.hasArg(options::OPT_v)) {
-  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
-   << "\"\n";
-}
-
 // Otherwise, don't add any path.
 break;
   }
diff --git a/clang/test/Driver/darwin-header-search-libcxx.cpp 
b/clang/test/Driver/darwin-header-search-libcxx.cpp
index 70cc06090a993..82f2616a87dd1 100644
--- a/clang/test/Driver/darwin-header-search-libcxx.cpp
+++ b/clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -23,8 +23,8 @@
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
 // RUN:   --check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s
 // CHECK-LIBCXX-TOOLCHAIN-1: "-cc1"
-// CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 // CHECK-LIBCXX-TOOLCHAIN-1-NOT: "-internal-isystem" "/usr/include/c++/v1"
+// CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 //
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --targe

[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-02 Thread Daniel Rodríguez Troitiño via cfe-commits

https://github.com/drodriguez created 
https://github.com/llvm/llvm-project/pull/80524

The current Apple Clang behaviour is to prefer `-isysroot` vs libc++ headers 
side-by-side the compiler. This has been like that for several Xcode versions, 
at least since Xcode 14.

The code was originally written in D89001 chosing the order that was correct at 
the time for Apple Clang. In 2023 D157283 tried to flip the order to match the 
current Apple Clang, but was reverted in 
3197357b7e39a58bc7eb0600eb337ac2a1c8c225 because it brokes two tests. The code 
was further changed in #70817 to add a third option.

The changes in this commit try to match Apple Clang, and incorporate the 
changes in #70817, as well as fixing the tests that broke when D157283 was 
applied.

From 32310bb312432bc215bec823c26f6194b0dcd447 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Rodri=CC=81guez=20Troitin=CC=83o?=
 
Date: Fri, 2 Feb 2024 17:26:39 -0800
Subject: [PATCH] [clang] Match -isysroot behaviour with system compiler on
 Darwin

The current Apple Clang behaviour is to prefer `-isysroot` vs libc++
headers side-by-side the compiler. This has been like that for several
Xcode versions, at least since Xcode 14.

The code was originally written in D89001 chosing the order that was
correct at the time for Apple Clang. In 2023 D157283 tried to flip the
order to match the current Apple Clang, but was reverted in
3197357b7e39a58bc7eb0600eb337ac2a1c8c225 because it brokes two tests.
The code was further changed in #70817 to add a third option.

The changes in this commit try to match Apple Clang, and incorporate the
changes in #70817, as well as fixing the tests that broke when D157283
was applied.
---
 clang/lib/Driver/ToolChains/Darwin.cpp| 32 +++
 .../Driver/darwin-header-search-libcxx.cpp| 41 ++-
 .../clang-check-mac-libcxx-abspath.cpp|  3 +-
 .../clang-check-mac-libcxx-relpath.cpp|  3 +-
 4 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fae8ad1a958ad..004a19284ee4a 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2515,20 +2515,31 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
 // On Darwin, libc++ can be installed in one of the following places:
-// 1. Alongside the compiler in /include/c++/v1
-// 2. Alongside the compiler in /../include/c++/v1
-// 3. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 1. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 2. Alongside the compiler in /include/c++/v1
+// 3. Alongside the compiler in /../include/c++/v1
 //
 // The precedence of paths is as listed above, i.e. we take the first path
 // that exists. Note that we never include libc++ twice -- we take the 
first
 // path that exists and don't send the other paths to CC1 (otherwise
 // include_next could break).
 //
-// Also note that in most cases, (1) and (2) are exactly the same path.
+// Also note that in most cases, (2) and (3) are exactly the same path.
 // Those two paths will differ only when the `clang` program being run
 // is actually a symlink to the real executable.
 
 // Check for (1)
+llvm::SmallString<128> SysrootUsr = Sysroot;
+llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
+if (getVFS().exists(SysrootUsr)) {
+  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
+  return;
+} else if (DriverArgs.hasArg(options::OPT_v)) {
+  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
+   << "\"\n";
+}
+
+// Check for (2)
 // Get from '/bin' to '/include/c++/v1'.
 // Note that InstallBin can be relative, so we use '..' instead of
 // parent_path.
@@ -2543,7 +2554,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
<< "\"\n";
 }
 
-// (2) Check for the folder where the executable is located, if different.
+// (3) Check for the folder where the executable is located, if different.
 if (getDriver().getInstalledDir() != getDriver().Dir) {
   InstallBin = llvm::StringRef(getDriver().Dir);
   llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
@@ -2556,17 +2567,6 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   }
 }
 
-// Otherwise, check for (3)
-llvm::SmallString<128> SysrootUsr = Sysroot;
-llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
-if (getVFS().exists(SysrootUsr)) {
-  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
-  return;
-} else if (DriverArgs.hasArg(options::OPT_v)) {
-  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
-   << "\"\n";
-}
-
 // Otherwise, don't add any path.
 break;
   }
d

[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/80327

>From b04701226cf9d867b64266a93bf13599b84494ba Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Thu, 1 Feb 2024 11:19:14 -0800
Subject: [PATCH] [Clang][Sema] Fix crash with const qualified member operator
 new

We should diagnose a const qualified member operator new but we fail to do so
and this leads to crash during debug info generation.

The fix is to diagnose this as ill-formed in the front-end.

Fixes: https://github.com/llvm/llvm-project/issues/79748
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaType.cpp   | 13 +++--
 clang/test/SemaCXX/function-type-qual.cpp | 18 ++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53040aa0f9074..21d72d188d7a0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -188,6 +188,8 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix crash and diagnostic with const qualified member operator new.
+  Fixes (`#79748 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 7cee73d5d6bae..aee2c9c4a7ded 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5907,6 +5907,11 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //  - the type-id in the default argument of a type-parameter, or
 //  - the type-id of a template-argument for a type-parameter
 //
+// C++23 [dcl.fct]p6 (P0847R7)
+// ... A member-declarator with an explicit-object-parameter-declaration
+// shall not include a ref-qualifier or a cv-qualifier-seq and shall not be
+// declared static or virtual ...
+//
 // FIXME: Checking this here is insufficient. We accept-invalid on:
 //
 //   template struct S { void f(T); };
@@ -5914,8 +5919,12 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //
 // ... for instance.
 if (IsQualifiedFunction &&
-!(Kind == Member && !D.isExplicitObjectMemberFunction() &&
-  D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
+// Check for non-static member function and not and
+// explicit-object-parameter-declaration
+(Kind != Member || D.isExplicitObjectMemberFunction() ||
+ D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+ (D.getContext() == clang::DeclaratorContext::Member &&
+  D.isStaticMember())) &&
 !IsTypedefName && D.getContext() != DeclaratorContext::TemplateArg &&
 D.getContext() != DeclaratorContext::TemplateTypeArg) {
   SourceLocation Loc = D.getBeginLoc();
diff --git a/clang/test/SemaCXX/function-type-qual.cpp 
b/clang/test/SemaCXX/function-type-qual.cpp
index bb25c17e83bdf..f4906f58abbae 100644
--- a/clang/test/SemaCXX/function-type-qual.cpp
+++ b/clang/test/SemaCXX/function-type-qual.cpp
@@ -37,3 +37,21 @@ void instantiateArrayDecay() {
   int a[1];
   arrayDecay(a);
 }
+
+namespace GH79748 {
+typedef decltype(sizeof(0)) size_t;
+struct A {
+  void* operator new(size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+  void* operator new[](size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+
+  void operator delete(void*) const; //expected-error {{static member function 
cannot have 'const' qualifier}}
+  void operator delete[](void*) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+};
+struct B {
+  void* operator new(size_t bytes) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+  void* operator new[](size_t bytes) volatile; //expected-error {{static 
member function cannot have 'volatile' qualifier}}
+
+  void operator delete(void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+  void operator delete[](void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+};
+}

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


[clang] [-Wunsafe-buffer-usage] Introduce std::array fixits (PR #80084)

2024-02-02 Thread via cfe-commits


@@ -0,0 +1,164 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+typedef int * Int_ptr_t;
+typedef int Int_t;
+
+void simple(unsigned idx) {
+  int buffer[10];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::array 
buffer"
+  buffer[idx] = 0;
+}
+
+void whitespace_in_declaration(unsigned idx) {
+  int  buffer_w   [   10 ];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:35}:"std::array 
buffer_w"
+  buffer_w[idx] = 0;
+}
+
+void comments_in_declaration(unsigned idx) {
+  int   /* [A] */   buffer_w  /* [B] */ [  /* [C] */ 10 /* [D] */  ] ;
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:69}:"std::array buffer_w"
+  buffer_w[idx] = 0;
+}
+
+void initializer(unsigned idx) {
+  int buffer[3] = {0};
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:16}:"std::array 
buffer"
+
+  int buffer2[3] = {0, 1, 2};
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::array 
buffer2"
+
+  buffer[idx] = 0;
+  buffer2[idx] = 0;
+}
+
+void auto_size(unsigned idx) {
+  int buffer[] = {0, 1, 2};
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+// FIXME: implement support
+
+  buffer[idx] = 0;
+}
+
+void universal_initialization(unsigned idx) {
+  int buffer[] {0, 1, 2};
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+// FIXME: implement support
+
+  buffer[idx] = 0;
+}
+
+void multi_decl1(unsigned idx) {
+  int a, buffer[10];
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+// FIXME: implement support
+
+  buffer[idx] = 0;
+}
+
+void multi_decl2(unsigned idx) {
+  int buffer[10], b;
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+// FIXME: implement support
+
+  buffer[idx] = 0;
+}
+
+void local_array_ptr_to_const(unsigned idx, const int*& a) {
+  const int * buffer[10] = {a};
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:25}:"std::array buffer"
+  a = buffer[idx];
+}
+
+void local_array_const_ptr(unsigned idx, int*& a) {
+  int * const buffer[10] = {a};
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:25}:"std::array buffer"
+
+  a = buffer[idx];
+}
+
+void local_array_const_ptr_via_typedef(unsigned idx, int*& a) {
+  typedef int * const my_const_ptr;
+  my_const_ptr buffer[10] = {a};
+// CHECK: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:26}:"std::array 
buffer"
+
+  a = buffer[idx];
+}
+
+void local_array_const_ptr_to_const(unsigned idx, const int*& a) {
+  const int * const buffer[10] = {a};
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:31}:"std::array buffer"
+
+  a = buffer[idx];
+
+}
+
+template
+void unsupported_local_array_in_template(unsigned idx) {
+  T buffer[10];
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
+  buffer[idx] = 0;
+}
+// Instantiate the template function to force its analysis.
+template void unsupported_local_array_in_template(unsigned);
+
+typedef unsigned int my_uint;
+void typedef_as_elem_type(unsigned idx) {
+  my_uint buffer[10];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:21}:"std::array buffer"
+  buffer[idx] = 0;
+}
+
+void macro_as_elem_type(unsigned idx) {
+#define MY_INT int
+  MY_INT buffer[10];
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
+// FIXME: implement support
+
+  buffer[idx] = 0;
+#undef MY_INT
+}
+
+void macro_as_identifier(unsigned idx) {
+#define MY_BUFFER buffer
+  int MY_BUFFER[10];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:20}:"std::array 
MY_BUFFER"
+  MY_BUFFER[idx] = 0;
+#undef MY_BUFFER
+}
+
+void macro_as_size(unsigned idx) {
+#define MY_TEN 10
+  int buffer[MY_TEN];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:21}:"std::array buffer"
+  buffer[idx] = 0;
+#undef MY_TEN
+}
+
+void constant_as_size(unsigned idx) {
+  const unsigned my_const = 10;
+  int buffer[my_const];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:23}:"std::array buffer"
+  buffer[idx] = 0;
+}
+
+void subscript_negative() {
+  int buffer[10];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::array 
buffer"
+
+  // For constant-size arrays any negative index will lead to buffer underflow.
+  // std::array::operator[] has unsigned parameter so the value will be casted 
to unsigned.
+  // This will very likely be buffer overflow but hardened std::array catch 
these at runtime.
+  buffer[-5] = 0;
+}
+
+void subscript_signed(int signed_idx) {
+  int buffer[10];
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::array 
buffer"
+
+  // For constant-size arrays any negative index will lead to buffer underflow.
+  // std::array::operator[] has unsigned parameter so the value will be casted 
to unsigned.
+  // This will very likely be buffer overflow but hardened std::array catches 
these at runtime.
+  buffer[signed_idx] = 0;
+}

jkorous-apple wrote:

Excellent point!

https://github.com/llvm/llvm-project/pull/80084
___
cfe-commits mailing lis

[clang] [-Wunsafe-buffer-usage] Introduce std::array fixits (PR #80084)

2024-02-02 Thread via cfe-commits


@@ -61,6 +61,7 @@ void testArraySubscripts(int *p, int **pp) {
   );
 
 int a[10];  // expected-warning{{'a' is an unsafe buffer that does 
not perform bounds checks}}
+// expected-note@-1{{change type of 'a' to 
'std::array' to harden it}}

jkorous-apple wrote:

I guess what we really want to say is "change the type of 'foo' to std::array 
so when you build the code with hardened libc++ all subscript operations on 
'foo' will be automatically bounds-safe" but that is too long and too complex 
for this particular communication channel.

How about:
"to enable hardening"
"to get it hardened"
"to designate it for hardening"
"to register it for hardening"

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


[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2024-02-02 Thread Ben Barham via cfe-commits

https://github.com/bnbarham commented:

Cool stuff @DavidGoldman! Nice to see ObjC getting some love. It's a bummer we 
duplicated here, but seems like both you and @ahoppen took fairly similar 
approaches. The main difference looks to be the use of `SymbolName` in the 
other PR.

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Reid Kleckner (rnk)


Changes

This code was correct as written prior to C++17, which allowed bases to appear 
in the initializer list.

Clang currently requires compound literal initializers at file scope to be 
constants, which is how I tested this behavior change, but I am open to other 
testing ideas.

This fixes at least one part of issue #80510 .

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


2 Files Affected:

- (modified) clang/lib/AST/Expr.cpp (+12) 
- (modified) clang/test/SemaCXX/compound-literal.cpp (+20) 


``diff
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index d665a08deb47e..8852fadf79b9a 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3342,6 +3342,18 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool 
IsForRef,
 if (ILE->getType()->isRecordType()) {
   unsigned ElementNo = 0;
   RecordDecl *RD = ILE->getType()->castAs()->getDecl();
+
+  // Check bases for C++17 aggregate initializers.
+  if (const auto *CXXRD = dyn_cast(RD)) {
+for (unsigned i = 0, e = CXXRD->getNumBases(); i < e; i++) {
+  if (ElementNo < ILE->getNumInits()) {
+const Expr *Elt = ILE->getInit(ElementNo++);
+if (!Elt->isConstantInitializer(Ctx, false, Culprit))
+  return false;
+  }
+}
+  }
+
   for (const auto *Field : RD->fields()) {
 // If this is a union, skip all the fields that aren't being 
initialized.
 if (RD->isUnion() && ILE->getInitializedFieldInUnion() != Field)
diff --git a/clang/test/SemaCXX/compound-literal.cpp 
b/clang/test/SemaCXX/compound-literal.cpp
index 5957099de53af..81f8b41ff0313 100644
--- a/clang/test/SemaCXX/compound-literal.cpp
+++ b/clang/test/SemaCXX/compound-literal.cpp
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -ast-dump %s > %t-11
 // RUN: FileCheck --input-file=%t-11 %s
 // RUN: FileCheck --input-file=%t-11 %s --check-prefix=CHECK-CXX11
+// RUN: %clang_cc1 -verify -std=c++17 %s
 
 // http://llvm.org/PR7905
 namespace PR7905 {
@@ -108,3 +109,22 @@ int computed_with_lambda = [] {
   return result;
 }();
 #endif
+
+#if __cplusplus >= 201703L
+namespace DynamicFileScopeLiteral {
+// This covers the case where we have a file-scope compound literal with a
+// non-constant initializer in C++. Previously, we had a bug where Clang forgot
+// to consider initializer list elements for bases.
+struct Empty {};
+struct Foo : Empty {
+  int x;
+  int y;
+};
+int f();
+Foo o = (Foo){
+  {},
+  1,
+  f() // expected-error {{initializer element is not a compile-time constant}}
+};
+}
+#endif

``




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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-02 Thread Reid Kleckner via cfe-commits

https://github.com/rnk created https://github.com/llvm/llvm-project/pull/80519

This code was correct as written prior to C++17, which allowed bases to appear 
in the initializer list.

Clang currently requires compound literal initializers at file scope to be 
constants, which is how I tested this behavior change, but I am open to other 
testing ideas.

This fixes at least one part of issue #80510 .

>From 6ab5ba3f970eaaea542fbed09cae17d3666df6b3 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Sat, 3 Feb 2024 00:18:42 +
Subject: [PATCH] wip

---
 clang/lib/AST/Expr.cpp  | 12 
 clang/test/SemaCXX/compound-literal.cpp | 20 
 2 files changed, 32 insertions(+)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index d665a08deb47e..8852fadf79b9a 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3342,6 +3342,18 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool 
IsForRef,
 if (ILE->getType()->isRecordType()) {
   unsigned ElementNo = 0;
   RecordDecl *RD = ILE->getType()->castAs()->getDecl();
+
+  // Check bases for C++17 aggregate initializers.
+  if (const auto *CXXRD = dyn_cast(RD)) {
+for (unsigned i = 0, e = CXXRD->getNumBases(); i < e; i++) {
+  if (ElementNo < ILE->getNumInits()) {
+const Expr *Elt = ILE->getInit(ElementNo++);
+if (!Elt->isConstantInitializer(Ctx, false, Culprit))
+  return false;
+  }
+}
+  }
+
   for (const auto *Field : RD->fields()) {
 // If this is a union, skip all the fields that aren't being 
initialized.
 if (RD->isUnion() && ILE->getInitializedFieldInUnion() != Field)
diff --git a/clang/test/SemaCXX/compound-literal.cpp 
b/clang/test/SemaCXX/compound-literal.cpp
index 5957099de53af..81f8b41ff0313 100644
--- a/clang/test/SemaCXX/compound-literal.cpp
+++ b/clang/test/SemaCXX/compound-literal.cpp
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -ast-dump %s > %t-11
 // RUN: FileCheck --input-file=%t-11 %s
 // RUN: FileCheck --input-file=%t-11 %s --check-prefix=CHECK-CXX11
+// RUN: %clang_cc1 -verify -std=c++17 %s
 
 // http://llvm.org/PR7905
 namespace PR7905 {
@@ -108,3 +109,22 @@ int computed_with_lambda = [] {
   return result;
 }();
 #endif
+
+#if __cplusplus >= 201703L
+namespace DynamicFileScopeLiteral {
+// This covers the case where we have a file-scope compound literal with a
+// non-constant initializer in C++. Previously, we had a bug where Clang forgot
+// to consider initializer list elements for bases.
+struct Empty {};
+struct Foo : Empty {
+  int x;
+  int y;
+};
+int f();
+Foo o = (Foo){
+  {},
+  1,
+  f() // expected-error {{initializer element is not a compile-time constant}}
+};
+}
+#endif

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


[clang] Fix clang crash when printing highlighted code in diagnostic (after #66514) (PR #80442)

2024-02-02 Thread via cfe-commits


@@ -1349,7 +1349,7 @@ void TextDiagnostic::emitSnippetAndCaret(
   // Prepare source highlighting information for the lines we're about to
   // emit, starting from the first line.
   std::unique_ptr[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

That's about as much as we can help with further debugging. As I said, I don't 
see how to create a reliable test case here.

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


[clang] Fix clang crash when printing highlighted code in diagnostic (after #66514) (PR #80442)

2024-02-02 Thread via cfe-commits


@@ -1349,7 +1349,7 @@ void TextDiagnostic::emitSnippetAndCaret(
   // Prepare source highlighting information for the lines we're about to
   // emit, starting from the first line.
   std::unique_ptr[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

Some debugging.

Backtrace:
```
frame #7: 0x754b2ee6 clang`__assert_fail(assertion="CheckPoint >= 
Buff->getBufferStart() && CheckPoint <= Buff->getBufferEnd()", 
file="llvm-project/clang/lib/Frontend/TextDiagnostic.cpp", line=1157, 
function="std::unique_ptr[]> 
highlightLines(StringRef, unsigned int, unsigned int, const Preprocessor *, 
const LangOptions &, bool, FileID, const SourceManager &)") at logging.cc:57:3
frame #8: 0x67bfc020 clang`highlightLines(FileData=(Data = "\n 
clang diagnostic ignored \"-Wdeprecated-declarations\"\n", Length = 55), 
StartLineNumber=40, EndLineNumber=40, PP=0x25c8bf806018, 
LangOpts=0x25c8bf848918, ShowColors=true, FID=(ID = 23810), 
SM=0x25c8bf892000) at TextDiagnostic.cpp:1156:5
frame #9: 0x67bfabcc 
clang`clang::TextDiagnostic::emitSnippetAndCaret(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff3b68, Level=Note, Ranges=0x7fff3c80, 
Hints=ArrayRef @ 0x7fff3b90) at TextDiagnostic.cpp:1352:7
frame #10: 0x67c021a7 
clang`clang::TextDiagnostic::emitCodeContext(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff3c00, Level=Note, Ranges=0x7fff3c80, 
Hints=ArrayRef @ 0x7fff3c20) at TextDiagnostic.h:97:5
frame #11: 0x67bc1a9d 
clang`clang::DiagnosticRenderer::emitCaret(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff3ce0, Level=Note, Ranges=ArrayRef @ 
0x7fff3cd0, Hints=ArrayRef @ 0x7fff3d00) at 
DiagnosticRenderer.cpp:429:3
frame #12: 0x67bc1112 
clang`clang::DiagnosticRenderer::emitDiagnostic(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff4270, Level=Note, Message=(Data = "expanded 
from hereo '_GLIB_GNUC_DO_PRAGMA'_FOR'_48_FOR'", Length = 18), Ranges=ArrayRef 
@ 0x7fff42a0, FixItHints=ArrayRef @ 0x7fff42b0, 
D=clang::DiagOrStoredDiag @ 0x7fff4258) at DiagnosticRenderer.cpp:127:5
frame #13: 0x67bc3549 
clang`clang::DiagnosticRenderer::emitSingleMacroExpansion(this=0x25c8bfc62f00,
 Loc=FullSourceLoc @ 0x7fff44c8, Level=Warning, Ranges=ArrayRef @ 
0x7fff44b8) at DiagnosticRenderer.cpp:454:3
frame #14: 0x67bc1f4b 
clang`clang::DiagnosticRenderer::emitMacroExpansions(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff4840, Level=Warning, Ranges=ArrayRef @ 
0x7fff4830, Hints=ArrayRef @ 0x7fff4860) at 
DiagnosticRenderer.cpp:569:7
frame #15: 0x67bc11dc 
clang`clang::DiagnosticRenderer::emitDiagnostic(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff4dd0, Level=Warning, Message=(Data = 
"Deprecated pre-processor symbol: replace with \"static inline\" 
[-W#pragma-messages]\xff\xff\xff\U007f", Length = 82), Ranges=ArrayRef @ 
0x7fff4e00, FixItHints=ArrayRef @ 0x7fff4e10, 
D=clang::DiagOrStoredDiag @ 0x7fff4db8) at DiagnosticRenderer.cpp:132:7
frame #16: 0x67bf73b6 
clang`clang::TextDiagnosticPrinter::HandleDiagnostic(this=0x25c8bfc16630, 
Level=Warning, Info=0x7fff50c8) at TextDiagnosticPrinter.cpp:151:13
frame #17: 0x6c6a0148 
clang`clang::DiagnosticIDs::EmitDiag(this=0x25c8bfc04840, 
Diag=0x25c8bf85c900, DiagLevel=Warning) const at DiagnosticIDs.cpp:823:16
frame #18: 0x6c69fef0 
clang`clang::DiagnosticIDs::ProcessDiag(this=0x25c8bfc04840, 
Diag=0x25c8bf85c900) const at DiagnosticIDs.cpp:815:3
frame #19: 0x6c69437a 
clang`clang::DiagnosticsEngine::ProcessDiag(this=0x25c8bf85c900) at 
Diagnostic.h:1042:19
frame #20: 0x6c68ef05 
clang`clang::DiagnosticsEngine::EmitCurrentDiagnostic(this=0x25c8bf85c900, 
Force=false) at Diagnostic.cpp:545:15
frame #21: 0x62f61b4d 
clang`clang::DiagnosticBuilder::Emit(this=0x7fff5420) at 
Diagnostic.h:1325:28
frame #22: 0x62f5fb6c 
clang`clang::DiagnosticBuilder::~DiagnosticBuilder(this=0x7fff5420) at 
Diagnostic.h:1366:26
frame #23: 0x6c5db9c0 clang`(anonymous 
namespace)::PragmaMessageHandler::HandlePragma(this=0x25c8bfc62c40, 
PP=0x25c8bf806018, Introducer=PragmaIntroducer @ 0x7fff54f8, 
Tok=0x7fff5720) at Pragma.cpp:1675:5
frame #24: 0x6c5d33fb 
clang`clang::PragmaNamespace::HandlePragma(this=0x25c8bfc636c0, 
PP=0x25c8bf806018, Introducer=PragmaIntroducer @ 0x7fff55c8, 
Tok=0x7fff5720) at Pragma.cpp:124:12
frame #25: 0x6c5d33fb 
clang`clang::PragmaNamespace::HandlePragma(this=0x25c8bfc63600, 
PP=0x25c8bf80

[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-02 Thread Adam Magier via cfe-commits

AdamMagierFOSS wrote:

One thing I'll preemptively address is I didn't know where to put the new unit 
testing - creating a separate file seems a little heavy handed but I see that 
there's a test for UBSan shift generation (`clang/test/CodeGen/ubsan-shift.c`) 
and one for UBSan + _BitInt (`clang/test/CodeGen/ext-int-sanitizer.cpp`). Both 
seem equally "valid" but neither seem to test in the same way that I'm trying 
to test these changes. Advice on this would be appreciated.

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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Adam Magier (AdamMagierFOSS)


Changes

Testing the shift-exponent check with small width _BitInt values exposed a bug 
in ScalarExprEmitter::GetWidthMinusOneValue when using the result to determine 
valid exponent sizes. False positives were reported for some left shifts when 
width(LHS)-1 > range(RHS) and false negatives were reported for right shifts 
when value(RHS) > range(LHS). This patch caps the maximum value of 
GetWidthMinusOneValue to fit within range(RHS) to fix the issue with left 
shifts and fixes a code generation in EmitShr to fix the issue with right 
shifts.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+8-1) 
- (added) clang/test/CodeGen/ubsan-shift-bitint.c (+36) 


``diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 5502f685f6474..e2e3ed839714a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4121,6 +4121,13 @@ Value *ScalarExprEmitter::GetWidthMinusOneValue(Value* 
LHS,Value* RHS) {
 Ty = cast(VT->getElementType());
   else
 Ty = cast(LHS->getType());
+  // Testing with small _BitInt types has shown that Ty->getBitwidth() - 1
+  // can sometimes overflow the capacity of RHS->getType(), cap the value
+  // to be the largest RHS->getType() can hold
+  llvm::APInt RHSMax =
+  llvm::APInt::getMaxValue(RHS->getType()->getScalarSizeInBits());
+  if (RHSMax.ult(Ty->getBitWidth()))
+return llvm::ConstantInt::get(RHS->getType(), RHSMax);
   return llvm::ConstantInt::get(RHS->getType(), Ty->getBitWidth() - 1);
 }
 
@@ -4235,7 +4242,7 @@ Value *ScalarExprEmitter::EmitShr(const BinOpInfo &Ops) {
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 llvm::Value *Valid =
-Builder.CreateICmpULE(RHS, GetWidthMinusOneValue(Ops.LHS, RHS));
+Builder.CreateICmpULE(Ops.RHS, GetWidthMinusOneValue(Ops.LHS, 
Ops.RHS));
 EmitBinOpCheck(std::make_pair(Valid, SanitizerKind::ShiftExponent), Ops);
   }
 
diff --git a/clang/test/CodeGen/ubsan-shift-bitint.c 
b/clang/test/CodeGen/ubsan-shift-bitint.c
new file mode 100644
index 0..8ca94b7de5a42
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-shift-bitint.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -O0 -fsanitize=shift-exponent -emit-llvm -o - | 
FileCheck %s
+
+// Checking that the code generation is using the unextended/untruncated
+// exponent values and capping the values accordingly
+
+// CHECK-LABEL: define{{.*}} i32 @test_left_variable
+int test_left_variable(unsigned _BitInt(5) b, unsigned _BitInt(2) e) {
+  // CHECK: [[E_REG:%.+]] = load [[E_SIZE:i2]]
+  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], -1
+  return b << e;
+}
+
+// CHECK-LABEL: define{{.*}} i32 @test_right_variable
+int test_right_variable(unsigned _BitInt(2) b, unsigned _BitInt(3) e) {
+  // CHECK: [[E_REG:%.+]] = load [[E_SIZE:i3]]
+  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 1
+  return b >> e;
+}
+
+// Old code generation would give false positives on left shifts when:
+//   value(e) > (width(b) - 1 % 2 ** width(e))
+// CHECK-LABEL: define{{.*}} i32 @test_left_literal
+int test_left_literal(unsigned _BitInt(5) b) {
+  // CHECK-NOT: br i1 false, label %cont, label %handler.shift_out_of_bounds
+  // CHECK: br i1 true, label %cont, label %handler.shift_out_of_bounds
+  return b << 3uwb;
+}
+
+// Old code generation would give false positives on right shifts when:
+//   (value(e) % 2 ** width(b)) < width(b)
+// CHECK-LABEL: define{{.*}} i32 @test_right_literal
+int test_right_literal(unsigned _BitInt(2) b) {
+  // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds
+  // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds
+  return b >> 4uwb;
+}

``




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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-02 Thread Adam Magier via cfe-commits

https://github.com/AdamMagierFOSS created 
https://github.com/llvm/llvm-project/pull/80515

Testing the shift-exponent check with small width _BitInt values exposed a bug 
in ScalarExprEmitter::GetWidthMinusOneValue when using the result to determine 
valid exponent sizes. False positives were reported for some left shifts when 
width(LHS)-1 > range(RHS) and false negatives were reported for right shifts 
when value(RHS) > range(LHS). This patch caps the maximum value of 
GetWidthMinusOneValue to fit within range(RHS) to fix the issue with left 
shifts and fixes a code generation in EmitShr to fix the issue with right 
shifts.

>From 4e1c37ae83dec050fc9b7aa172db01fa0b2b6d68 Mon Sep 17 00:00:00 2001
From: Adam Magier 
Date: Sat, 3 Feb 2024 00:38:54 +0100
Subject: [PATCH] [clang][CodeGen][UBSan] Fixing shift-exponent generation for
 _BitInt

Testing the shift-exponent check with small width _BitInt values exposed
a bug in ScalarExprEmitter::GetWidthMinusOneValue when using the result
to determine valid exponent sizes. False positives were reported for
some left shifts when width(LHS)-1 > range(RHS) and false negatives were
reported for right shifts when value(RHS) > range(LHS). This patch caps
the maximum value of GetWidthMinusOneValue to fit within range(RHS) to
fix the issue with left shifts and fixes a code generation in EmitShr to
fix the issue with right shifts.
---
 clang/lib/CodeGen/CGExprScalar.cpp  |  9 ++-
 clang/test/CodeGen/ubsan-shift-bitint.c | 36 +
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/ubsan-shift-bitint.c

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 5502f685f6474..e2e3ed839714a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4121,6 +4121,13 @@ Value *ScalarExprEmitter::GetWidthMinusOneValue(Value* 
LHS,Value* RHS) {
 Ty = cast(VT->getElementType());
   else
 Ty = cast(LHS->getType());
+  // Testing with small _BitInt types has shown that Ty->getBitwidth() - 1
+  // can sometimes overflow the capacity of RHS->getType(), cap the value
+  // to be the largest RHS->getType() can hold
+  llvm::APInt RHSMax =
+  llvm::APInt::getMaxValue(RHS->getType()->getScalarSizeInBits());
+  if (RHSMax.ult(Ty->getBitWidth()))
+return llvm::ConstantInt::get(RHS->getType(), RHSMax);
   return llvm::ConstantInt::get(RHS->getType(), Ty->getBitWidth() - 1);
 }
 
@@ -4235,7 +4242,7 @@ Value *ScalarExprEmitter::EmitShr(const BinOpInfo &Ops) {
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 llvm::Value *Valid =
-Builder.CreateICmpULE(RHS, GetWidthMinusOneValue(Ops.LHS, RHS));
+Builder.CreateICmpULE(Ops.RHS, GetWidthMinusOneValue(Ops.LHS, 
Ops.RHS));
 EmitBinOpCheck(std::make_pair(Valid, SanitizerKind::ShiftExponent), Ops);
   }
 
diff --git a/clang/test/CodeGen/ubsan-shift-bitint.c 
b/clang/test/CodeGen/ubsan-shift-bitint.c
new file mode 100644
index 0..8ca94b7de5a42
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-shift-bitint.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -O0 -fsanitize=shift-exponent -emit-llvm -o - | 
FileCheck %s
+
+// Checking that the code generation is using the unextended/untruncated
+// exponent values and capping the values accordingly
+
+// CHECK-LABEL: define{{.*}} i32 @test_left_variable
+int test_left_variable(unsigned _BitInt(5) b, unsigned _BitInt(2) e) {
+  // CHECK: [[E_REG:%.+]] = load [[E_SIZE:i2]]
+  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], -1
+  return b << e;
+}
+
+// CHECK-LABEL: define{{.*}} i32 @test_right_variable
+int test_right_variable(unsigned _BitInt(2) b, unsigned _BitInt(3) e) {
+  // CHECK: [[E_REG:%.+]] = load [[E_SIZE:i3]]
+  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 1
+  return b >> e;
+}
+
+// Old code generation would give false positives on left shifts when:
+//   value(e) > (width(b) - 1 % 2 ** width(e))
+// CHECK-LABEL: define{{.*}} i32 @test_left_literal
+int test_left_literal(unsigned _BitInt(5) b) {
+  // CHECK-NOT: br i1 false, label %cont, label %handler.shift_out_of_bounds
+  // CHECK: br i1 true, label %cont, label %handler.shift_out_of_bounds
+  return b << 3uwb;
+}
+
+// Old code generation would give false positives on right shifts when:
+//   (value(e) % 2 ** width(b)) < width(b)
+// CHECK-LABEL: define{{.*}} i32 @test_right_literal
+int test_right_literal(unsigned _BitInt(2) b) {
+  // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds
+  // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds
+  return b >> 4uwb;
+}

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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-02 Thread James Y Knight via cfe-commits

jyknight wrote:

I think there is a bit of a problematic interaction with getDenormalModeForType 
[here](https://github.com/llvm/llvm-project/blob/7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73/clang/lib/Driver/ToolChains/Linux.cpp#L838C8-L838C37).
 "-shared" is (should be) a flag used only for linking, but that function is 
calling isFastMathRuntimeAvailable to affect the default denormal math mode for 
_compilation_. That's not going to work.

Probably we should effectively revert the x86-linux parts of 
fa7cd549d604bfd8f9dce5d649a19720cbc39cca.

I wonder if, instead, we should just have `-ffast-math` always downgrade 
`-fdenormal-fp-math=ieee` to `-fdenormal-fp-math=preserve-sign`, under the 
rationale of "you asked for fast math, and preserve-sign mode might let the 
compiler generate faster code"?

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


[clang] [Headers][X86] Editorial fixes to ia32intrin.h descriptions (PR #80490)

2024-02-02 Thread Craig Topper via cfe-commits

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

LGTM

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


[llvm] [clang] [flang] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)

2024-02-02 Thread Artem Belevich via cfe-commits

Artem-B wrote:

Another corner case here. Untyped GEP resulted in SimpifyCFG producing a 
`load(gep(argptr, cond ? 24 : 0))` instead of `load( cond ? gep(argptr, 24) : 
argptr)` it produced before the patch, and that eventually prevented SROA from 
processing that load.

While it's not a bug in this patch, the consequence is a pretty serious 
performance regression in some GPU code. And we do not have a workaround. :-/ 

Minimized reproducer:
```
# opt 
-passes='inline,simplifycfg,instcombine,sroa'
 -S https://github.com/llvm/llvm-project/pull/68882
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [compiler-rt] [mlir] [llvm] [clang] [lldb] [clang-tools-extra] [lld] [flang] [libcxx] [libc] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/8] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df..2d6986d145483 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d2241684..0e87cbe8ce812 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89b..18edcd05ea85c 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516a..e56f787e824f2 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f724..525ea6df3643c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25

[openmp] [compiler-rt] [mlir] [llvm] [clang] [lldb] [clang-tools-extra] [lld] [flang] [libcxx] [libc] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/7] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df..2d6986d145483 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d2241684..0e87cbe8ce812 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89b..18edcd05ea85c 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516a..e56f787e824f2 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f724..525ea6df3643c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25

[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

2024-02-02 Thread Craig Topper via cfe-commits


@@ -70,13 +70,17 @@ fixed_float64m1_t call_float64_ff(fixed_float64m1_t op1, 
fixed_float64m1_t op2)
 
 // CHECK-LABEL: @call_bool1_ff(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 8
-// CHECK-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 8
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv64i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 256)
-// CHECK-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 8, !tbaa [[TBAA4:![0-9]+]]
-// CHECK-NEXT:[[TMP1:%.*]] = load <32 x i8>, ptr [[SAVED_VALUE4]], align 
8, !tbaa [[TBAA8:![0-9]+]]
-// CHECK-NEXT:store <32 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 8
-// CHECK-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 8
+// CHECK-NEXT:[[OP1:%.*]] = alloca <32 x i8>, align 8

topperc wrote:

Need to check what happened here.

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

2024-02-02 Thread Craig Topper via cfe-commits


@@ -2136,14 +2136,16 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
-// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
+// If we are casting a fixed i8 vector to a scalable i1 predicate
 // vector, use a vector insert and bitcast the result.
 bool NeedsBitCast = false;
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
 llvm::Type *OrigType = DstTy;
-if (ScalableDst == PredType &&
-FixedSrc->getElementType() == Builder.getInt8Ty()) {
-  DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableDst->getElementType()->isIntegerTy(1) &&

topperc wrote:

I plan to do another update to address this.

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

2024-02-02 Thread Craig Topper via cfe-commits

topperc wrote:

> Generalising this code makes sense, 16 should never have been hardcoded here.
> 
> Is it possible to add a test for the case where the predicate type is not 
> ``?

I rebased, which picked up more tests that are affected for RISC-V. This also 
pointed out that I missed very similar code in CGCall.cpp so that's been 
updated now.

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

2024-02-02 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/76548

>From 3dfa00b0dab1820d1d8692ea91e98b29c9f8b627 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 28 Dec 2023 16:49:03 -0800
Subject: [PATCH 1/3] [IRGen][AArch64][RISCV] Generalize bitcast between i1
 predicate vector and i8 fixed vector.

Instead of only handling vscale x 16 x i1 predicate vectors, handle
any scalable i1 vector where the known minimum is divisible by 8.

This will be used on RISC-V where we have multiple sizes of predicate
types.

Though I do wonder if we have the bitcast on the wrong side. Maybe
we should be casting the fixed type to an i1 fixed vector? That would
better handle cases where the mininum elements isn't a multiple of 8,
but vscale*min_elements is.
---
 clang/lib/CodeGen/CGExprScalar.cpp | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 5502f685f6474..871714d62d91d 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2139,14 +2139,16 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
-// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
+// If we are casting a fixed i8 vector to a scalable i1 predicate
 // vector, use a vector insert and bitcast the result.
 bool NeedsBitCast = false;
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
 llvm::Type *OrigType = DstTy;
-if (ScalableDst == PredType &&
-FixedSrc->getElementType() == Builder.getInt8Ty()) {
-  DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableDst->getElementType()->isIntegerTy(1) &&
+ScalableDst->getElementCount().isKnownMultipleOf(8) &&
+FixedSrc->getElementType()->isIntegerTy(8)) {
+  DstTy = llvm::VectorType::get(
+  FixedSrc->getElementType(),
+  ScalableDst->getElementCount().divideCoefficientBy(8));
   ScalableDst = cast(DstTy);
   NeedsBitCast = true;
 }
@@ -2167,12 +2169,14 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *ScalableSrc = dyn_cast(SrcTy)) {
   if (const auto *FixedDst = dyn_cast(DstTy)) {
-// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
+// If we are casting a scalable i1 predicate vector to a fixed i8
 // vector, bitcast the source and use a vector extract.
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
-if (ScalableSrc == PredType &&
-FixedDst->getElementType() == Builder.getInt8Ty()) {
-  SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableSrc->getElementType()->isIntegerTy(1) &&
+ScalableSrc->getElementCount().isKnownMultipleOf(8) &&
+FixedDst->getElementType()->isIntegerTy(8)) {
+  SrcTy = llvm::VectorType::get(
+  FixedDst->getElementType(),
+  ScalableSrc->getElementCount().divideCoefficientBy(8));
   ScalableSrc = cast(SrcTy);
   Src = Builder.CreateBitCast(Src, SrcTy);
 }

>From ce55e64e919ebbedc701ff5c1c76780ca38d2c16 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Fri, 2 Feb 2024 14:20:52 -0800
Subject: [PATCH 2/3] fixup! Update tests after rebase.

---
 .../attr-riscv-rvv-vector-bits-bitcast.c  | 36 ++
 .../CodeGen/attr-riscv-rvv-vector-bits-call.c | 48 ---
 .../CodeGen/attr-riscv-rvv-vector-bits-cast.c | 26 +-
 .../attr-riscv-rvv-vector-bits-codegen.c  | 13 +++--
 .../attr-riscv-rvv-vector-bits-globals.c  | 26 +-
 5 files changed, 77 insertions(+), 72 deletions(-)

diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c 
b/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
index a7b3123e61cd5..20fb4a04564c7 100644
--- a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
+++ b/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
@@ -177,29 +177,26 @@ void write_float64m1(struct struct_float64m1 *s, 
vfloat64m1_t x) {
 
 // CHECK-64-LABEL: @read_bool1(
 // CHECK-64-NEXT:  entry:
-// CHECK-64-NEXT:[[SAVED_VALUE:%.*]] = alloca <8 x i8>, align 8
 // CHECK-64-NEXT:[[Y:%.*]] = getelementptr inbounds i8, ptr [[S:%.*]], i64 
8
 // CHECK-64-NEXT:[[TMP0:%.*]] = load <8 x i8>, ptr [[Y]], align 8, !tbaa 
[[TBAA4]]
-// CHECK-64-NEXT:store <8 x i8> [[TMP0]], ptr [[SAVED_VALUE]], align 8, 
!tbaa [[TBAA4]]
-// CHECK-64-NEXT:[[TMP1:%.*]] = load , ptr 
[[SAVED_VALUE]], align 8, !tbaa [[TBAA4]]
+// CHECK-64-NEXT:[[CAST_SCALABLE:%.*]] = tail call  
@llvm.vector.insert.nxv8i8.v8i8( undef, <8 x i8> [[TMP0]], i64 
0)
+// CHEC

[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [Clang] Fix a crash when dumping a pack indexing type. (PR #80439)

2024-02-02 Thread via cfe-commits

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


[clang] 7a94acb - [Clang] Fix a crash when dumping a pack indexing type. (#80439)

2024-02-02 Thread via cfe-commits

Author: cor3ntin
Date: 2024-02-03T00:09:07+01:00
New Revision: 7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73

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

LOG: [Clang] Fix a crash when dumping a pack indexing type. (#80439)

Fix a crash caused by incorrect assumptions
Reported here
https://github.com/llvm/llvm-project/pull/72644#discussion_r1469525524

Added: 
clang/test/AST/ast-dump-pack-indexing-crash.cpp

Modified: 
clang/lib/AST/TypePrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 4363280757714..c2ebe2c500174 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1195,10 +1195,10 @@ void TypePrinter::printDecltypeBefore(const 
DecltypeType *T, raw_ostream &OS) {
 
 void TypePrinter::printPackIndexingBefore(const PackIndexingType *T,
   raw_ostream &OS) {
-  if (T->isInstantiationDependentType())
-OS << T->getPattern() << "...[" << T->getIndexExpr() << "]";
-  else
+  if (T->hasSelectedType())
 OS << T->getSelectedType();
+  else
+OS << T->getPattern() << "...[" << T->getIndexExpr() << "]";
   spaceBeforePlaceHolder(OS);
 }
 

diff  --git a/clang/test/AST/ast-dump-pack-indexing-crash.cpp 
b/clang/test/AST/ast-dump-pack-indexing-crash.cpp
new file mode 100644
index 0..0b0c0b572b5e6
--- /dev/null
+++ b/clang/test/AST/ast-dump-pack-indexing-crash.cpp
@@ -0,0 +1,25 @@
+// RUN: not %clang_cc1 -std=c++2c -ast-dump %s | FileCheck  %s
+
+namespace InvalidPacksShouldNotCrash {
+
+struct NotAPack;
+template  typename Tp>
+void not_pack() {
+int i = 0;
+i...[0]; // expected-error {{i does not refer to the name of a parameter 
pack}}
+V...[0]; // expected-error {{V does not refer to the name of a parameter 
pack}}
+NotAPack...[0] a; // expected-error{{'NotAPack' does not refer to the name 
of a parameter pack}}
+T...[0] b;   // expected-error{{'T' does not refer to the name of a 
parameter pack}}
+Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a 
parameter pack}}
+}
+
+// CHECK:  FunctionDecl {{.*}} not_pack 'void ()'
+// CHECK:   DeclStmt {{.*}}
+// CHECK:   DeclStmt {{.*}}
+// CHECK-NEXT:VarDecl {{.*}} a 'NotAPack...{{.*}}'
+// CHECK-NEXT:  DeclStmt {{.*}}
+// CHECK-NEXT:VarDecl {{.*}} 'T...{{.*}}'
+// CHECK-NEXT:   DeclStmt {{.*}}
+// CHECK-NEXT:VarDecl {{.*}} c 'Tp...{{.*}}'
+
+}



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


[clang] [-Wunsafe-buffer-usage] Ignore constant safe indices in array subscripts (PR #80504)

2024-02-02 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 86cd2fbdfe67d70a7fe061ed5d3a644f50f070f5 
b510cf7ca8c47c64e0b9f5fcd5634759dfe95751 -- 
clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-array.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
clang/lib/Analysis/UnsafeBufferUsage.cpp 
clang/lib/Sema/AnalysisBasedWarnings.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 8f8751f4ee..4399d15f46 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -281,10 +281,10 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   // 4. the operand of a pointer subtraction operation
   //(i.e., computing the distance between two pointers); or ...
 
-  auto CallArgMatcher =
-  callExpr(forEachArgumentWithParamType(InnerMatcher,
-  isAnyPointer() /* array also decays to pointer type*/),
-  unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
+  auto CallArgMatcher = callExpr(
+  forEachArgumentWithParamType(
+  InnerMatcher, isAnyPointer() /* array also decays to pointer type*/),
+  unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
 
   auto CastOperandMatcher =
   castExpr(anyOf(hasCastKind(CastKind::CK_PointerToIntegral),
@@ -404,7 +404,8 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) {
 }
 
 AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
-  const DeclRefExpr * BaseDRE = 
dyn_cast_or_null(Node.getBase()->IgnoreParenImpCasts());
+  const DeclRefExpr *BaseDRE =
+  dyn_cast_or_null(Node.getBase()->IgnoreParenImpCasts());
   if (!BaseDRE)
 return false;
   if (!BaseDRE->getDecl())
@@ -412,15 +413,17 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   auto BaseVarDeclTy = BaseDRE->getDecl()->getType();
   if (!BaseVarDeclTy->isConstantArrayType())
 return false;
-  const auto * CATy = dyn_cast_or_null(BaseVarDeclTy);
+  const auto *CATy = dyn_cast_or_null(BaseVarDeclTy);
   if (!CATy)
 return false;
   const APInt ArrSize = CATy->getSize();
 
-  if (const auto * IdxLit = dyn_cast(Node.getIdx())) {
+  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
 const APInt ArrIdx = IdxLit->getValue();
-// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a bug
-if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < 
ArrSize.getLimitedValue())
+// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
+// bug
+if (ArrIdx.isNonNegative() &&
+ArrIdx.getLimitedValue() < ArrSize.getLimitedValue())
   return true;
   }
 

``




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


[clang] [-Wunsafe-buffer-usage] Ignore constant safe indices in array subscripts (PR #80504)

2024-02-02 Thread via cfe-commits

https://github.com/jkorous-apple created 
https://github.com/llvm/llvm-project/pull/80504

depends on
https://github.com/llvm/llvm-project/pull/80358

>From 463a9904c1ae85fbdc0bd6029c6effea3fb16ea6 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Tue, 23 Jan 2024 16:16:10 -0800
Subject: [PATCH 01/19] [-Wunsafe-buffer-usage] Move Strategy class to the
 header

It needs to be used from handleUnsafeVariableGroup function.
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |  37 +++
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 238 --
 2 files changed, 140 insertions(+), 135 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index aca1ad998822c..622c094f5b1eb 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -42,6 +42,43 @@ class VariableGroupsManager {
   virtual VarGrpRef getGroupOfParms() const =0;
 };
 
+// FixitStrategy is a map from variables to the way we plan to emit fixes for
+// these variables. It is figured out gradually by trying different fixes
+// for different variables depending on gadgets in which these variables
+// participate.
+class FixitStrategy {
+public:
+  enum class Kind {
+Wontfix,  // We don't plan to emit a fixit for this variable.
+Span, // We recommend replacing the variable with std::span.
+Iterator, // We recommend replacing the variable with std::span::iterator.
+Array,// We recommend replacing the variable with std::array.
+Vector// We recommend replacing the variable with std::vector.
+  };
+
+private:
+  using MapTy = llvm::DenseMap;
+
+  MapTy Map;
+
+public:
+  FixitStrategy() = default;
+  FixitStrategy(const FixitStrategy &) = delete; // Let's avoid copies.
+  FixitStrategy &operator=(const FixitStrategy &) = delete;
+  FixitStrategy(FixitStrategy &&) = default;
+  FixitStrategy &operator=(FixitStrategy &&) = default;
+
+  void set(const VarDecl *VD, Kind K) { Map[VD] = K; }
+
+  Kind lookup(const VarDecl *VD) const {
+auto I = Map.find(VD);
+if (I == Map.end())
+  return Kind::Wontfix;
+
+return I->second;
+  }
+};
+
 /// The interface that lets the caller handle unsafe buffer usage analysis
 /// results by overriding this class's handle... methods.
 class UnsafeBufferUsageHandler {
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 823cd2a7b9969..924d677786275 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -407,9 +407,6 @@ using DeclUseList = SmallVector;
 
 // Convenience typedef.
 using FixItList = SmallVector;
-
-// Defined below.
-class Strategy;
 } // namespace
 
 namespace {
@@ -486,7 +483,7 @@ class FixableGadget : public Gadget {
   /// Returns a fixit that would fix the current gadget according to
   /// the current strategy. Returns std::nullopt if the fix cannot be produced;
   /// returns an empty list if no fixes are necessary.
-  virtual std::optional getFixits(const Strategy &) const {
+  virtual std::optional getFixits(const FixitStrategy &) const {
 return std::nullopt;
   }
 
@@ -737,7 +734,8 @@ class PointerInitGadget : public FixableGadget {
 return stmt(PtrInitStmt);
   }
 
-  virtual std::optional getFixits(const Strategy &S) const override;
+  virtual std::optional
+  getFixits(const FixitStrategy &S) const override;
 
   virtual const Stmt *getBaseStmt() const override {
 // FIXME: This needs to be the entire DeclStmt, assuming that this method
@@ -789,7 +787,8 @@ class PointerAssignmentGadget : public FixableGadget {
 return stmt(isInUnspecifiedUntypedContext(PtrAssignExpr));
   }
 
-  virtual std::optional getFixits(const Strategy &S) const override;
+  virtual std::optional
+  getFixits(const FixitStrategy &S) const override;
 
   virtual const Stmt *getBaseStmt() const override {
 // FIXME: This should be the binary operator, assuming that this method
@@ -892,7 +891,8 @@ class ULCArraySubscriptGadget : public FixableGadget {
 return expr(isInUnspecifiedLvalueContext(Target));
   }
 
-  virtual std::optional getFixits(const Strategy &S) const override;
+  virtual std::optional
+  getFixits(const FixitStrategy &S) const override;
 
   virtual const Stmt *getBaseStmt() const override { return Node; }
 
@@ -932,7 +932,8 @@ class UPCStandalonePointerGadget : public FixableGadget {
 return stmt(isInUnspecifiedPointerContext(target));
   }
 
-  virtual std::optional getFixits(const Strategy &S) const override;
+  virtual std::optional
+  getFixits(const FixitStrategy &S) const override;
 
   virtual const Stmt *getBaseStmt() const override { return Node; }
 
@@ -976,7 +977,8 @@ class PointerDereferenceGadget : public FixableGadget {
 
   virtual const Stmt *getBaseStmt() const final { return Op; }
 
-  virtual std::optional getFixits(const Strategy &S) const overri

[compiler-rt] [lld] [flang] [libcxx] [mlir] [openmp] [llvm] [libc] [clang-tools-extra] [lldb] [clang] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/7] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df..2d6986d145483 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d2241684..0e87cbe8ce812 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89b..18edcd05ea85c 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516a..e56f787e824f2 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f724..525ea6df3643c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25

[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/80327

>From 154465e0a81b96daaf71f2c0cf23c39e6f9a8d75 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Thu, 1 Feb 2024 11:19:14 -0800
Subject: [PATCH] [Clang][Sema] Fix crash with const qualified member operator
 new

We should diagnose a const qualified member operator new but we fail to do so
and this leads to crash during debug info generation.

The fix is to diagnose this as ill-formed in the front-end.

Fixes: https://github.com/llvm/llvm-project/issues/79748
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaType.cpp   | 13 +++--
 clang/test/SemaCXX/function-type-qual.cpp | 18 ++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53040aa0f9074..21d72d188d7a0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -188,6 +188,8 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix crash and diagnostic with const qualified member operator new.
+  Fixes (`#79748 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 7cee73d5d6bae..aee2c9c4a7ded 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5907,6 +5907,11 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //  - the type-id in the default argument of a type-parameter, or
 //  - the type-id of a template-argument for a type-parameter
 //
+// C++23 [dcl.fct]p6 (P0847R7)
+// ... A member-declarator with an explicit-object-parameter-declaration
+// shall not include a ref-qualifier or a cv-qualifier-seq and shall not be
+// declared static or virtual ...
+//
 // FIXME: Checking this here is insufficient. We accept-invalid on:
 //
 //   template struct S { void f(T); };
@@ -5914,8 +5919,12 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //
 // ... for instance.
 if (IsQualifiedFunction &&
-!(Kind == Member && !D.isExplicitObjectMemberFunction() &&
-  D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
+// Check for non-static member function and not and
+// explicit-object-parameter-declaration
+(Kind != Member || D.isExplicitObjectMemberFunction() ||
+ D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+ (D.getContext() == clang::DeclaratorContext::Member &&
+  D.isStaticMember())) &&
 !IsTypedefName && D.getContext() != DeclaratorContext::TemplateArg &&
 D.getContext() != DeclaratorContext::TemplateTypeArg) {
   SourceLocation Loc = D.getBeginLoc();
diff --git a/clang/test/SemaCXX/function-type-qual.cpp 
b/clang/test/SemaCXX/function-type-qual.cpp
index bb25c17e83bdf..f4906f58abbae 100644
--- a/clang/test/SemaCXX/function-type-qual.cpp
+++ b/clang/test/SemaCXX/function-type-qual.cpp
@@ -37,3 +37,21 @@ void instantiateArrayDecay() {
   int a[1];
   arrayDecay(a);
 }
+
+namespace GH79748 {
+typedef decltype(sizeof(0)) size_t;
+struct A {
+  void* operator new(size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+  void* operator new[](size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+
+  void operator delete(void*) const; //expected-error {{static member function 
cannot have 'const' qualifier}}
+  void operator delete[](void*) const; //expected-error {{static member 
function cannot have 'const' qualifier}}
+};
+struct B {
+  void* operator new(size_t bytes) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+  void* operator new[](size_t bytes) volatile; //expected-error {{static 
member function cannot have 'volatile' qualifier}}
+
+  void operator delete(void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+  void operator delete[](void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
+};
+}

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

2024-02-02 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/76548

>From 3dfa00b0dab1820d1d8692ea91e98b29c9f8b627 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 28 Dec 2023 16:49:03 -0800
Subject: [PATCH 1/2] [IRGen][AArch64][RISCV] Generalize bitcast between i1
 predicate vector and i8 fixed vector.

Instead of only handling vscale x 16 x i1 predicate vectors, handle
any scalable i1 vector where the known minimum is divisible by 8.

This will be used on RISC-V where we have multiple sizes of predicate
types.

Though I do wonder if we have the bitcast on the wrong side. Maybe
we should be casting the fixed type to an i1 fixed vector? That would
better handle cases where the mininum elements isn't a multiple of 8,
but vscale*min_elements is.
---
 clang/lib/CodeGen/CGExprScalar.cpp | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 5502f685f6474..871714d62d91d 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2139,14 +2139,16 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
-// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
+// If we are casting a fixed i8 vector to a scalable i1 predicate
 // vector, use a vector insert and bitcast the result.
 bool NeedsBitCast = false;
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
 llvm::Type *OrigType = DstTy;
-if (ScalableDst == PredType &&
-FixedSrc->getElementType() == Builder.getInt8Ty()) {
-  DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableDst->getElementType()->isIntegerTy(1) &&
+ScalableDst->getElementCount().isKnownMultipleOf(8) &&
+FixedSrc->getElementType()->isIntegerTy(8)) {
+  DstTy = llvm::VectorType::get(
+  FixedSrc->getElementType(),
+  ScalableDst->getElementCount().divideCoefficientBy(8));
   ScalableDst = cast(DstTy);
   NeedsBitCast = true;
 }
@@ -2167,12 +2169,14 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *ScalableSrc = dyn_cast(SrcTy)) {
   if (const auto *FixedDst = dyn_cast(DstTy)) {
-// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
+// If we are casting a scalable i1 predicate vector to a fixed i8
 // vector, bitcast the source and use a vector extract.
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
-if (ScalableSrc == PredType &&
-FixedDst->getElementType() == Builder.getInt8Ty()) {
-  SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableSrc->getElementType()->isIntegerTy(1) &&
+ScalableSrc->getElementCount().isKnownMultipleOf(8) &&
+FixedDst->getElementType()->isIntegerTy(8)) {
+  SrcTy = llvm::VectorType::get(
+  FixedDst->getElementType(),
+  ScalableSrc->getElementCount().divideCoefficientBy(8));
   ScalableSrc = cast(SrcTy);
   Src = Builder.CreateBitCast(Src, SrcTy);
 }

>From ce55e64e919ebbedc701ff5c1c76780ca38d2c16 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Fri, 2 Feb 2024 14:20:52 -0800
Subject: [PATCH 2/2] fixup! Update tests after rebase.

---
 .../attr-riscv-rvv-vector-bits-bitcast.c  | 36 ++
 .../CodeGen/attr-riscv-rvv-vector-bits-call.c | 48 ---
 .../CodeGen/attr-riscv-rvv-vector-bits-cast.c | 26 +-
 .../attr-riscv-rvv-vector-bits-codegen.c  | 13 +++--
 .../attr-riscv-rvv-vector-bits-globals.c  | 26 +-
 5 files changed, 77 insertions(+), 72 deletions(-)

diff --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c 
b/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
index a7b3123e61cd5..20fb4a04564c7 100644
--- a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
+++ b/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
@@ -177,29 +177,26 @@ void write_float64m1(struct struct_float64m1 *s, 
vfloat64m1_t x) {
 
 // CHECK-64-LABEL: @read_bool1(
 // CHECK-64-NEXT:  entry:
-// CHECK-64-NEXT:[[SAVED_VALUE:%.*]] = alloca <8 x i8>, align 8
 // CHECK-64-NEXT:[[Y:%.*]] = getelementptr inbounds i8, ptr [[S:%.*]], i64 
8
 // CHECK-64-NEXT:[[TMP0:%.*]] = load <8 x i8>, ptr [[Y]], align 8, !tbaa 
[[TBAA4]]
-// CHECK-64-NEXT:store <8 x i8> [[TMP0]], ptr [[SAVED_VALUE]], align 8, 
!tbaa [[TBAA4]]
-// CHECK-64-NEXT:[[TMP1:%.*]] = load , ptr 
[[SAVED_VALUE]], align 8, !tbaa [[TBAA4]]
+// CHECK-64-NEXT:[[CAST_SCALABLE:%.*]] = tail call  
@llvm.vector.insert.nxv8i8.v8i8( undef, <8 x i8> [[TMP0]], i64 
0)
+// CHEC

[clang] [Headers][X86] Editorial fixes to ia32intrin.h descriptions (PR #80490)

2024-02-02 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

Tag @cflores as well, 

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


[clang] [libcxxabi] [lldb] [flang] [lld] [llvm] [libcxx] [libc] [msan] Unpoison indirect outputs for userspace using memset for large operands (PR #79924)

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


@@ -4552,16 +4552,22 @@ struct MemorySanitizerVisitor : public 
InstVisitor {
 }
 if (!ElemTy->isSized())
   return;
-Value *SizeVal =
-  IRB.CreateTypeSize(MS.IntptrTy, DL.getTypeStoreSize(ElemTy));
+auto Size = DL.getTypeStoreSize(ElemTy);
+Value *SizeVal = IRB.CreateTypeSize(MS.IntptrTy, Size);
 if (MS.CompileKernel) {
   IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Operand, SizeVal});
 } else {
   // ElemTy, derived from elementtype(), does not encode the alignment of
   // the pointer. Conservatively assume that the shadow memory is 
unaligned.
+  // When Size is large, avoid StoreInst as it would expand to many
+  // instructions.
   auto [ShadowPtr, _] =
   getShadowOriginPtrUserspace(Operand, IRB, IRB.getInt8Ty(), Align(1));
-  IRB.CreateAlignedStore(getCleanShadow(ElemTy), ShadowPtr, Align(1));
+  if (Size <= 32)

vitalybuka wrote:

Memset will go into interceptor and do a lot of check, see `__msan_memset`, so 
it's more expensive than a regular memset. I can't tell what can be optimal 
constant here, but I would expect something larger. But I doubt it will make a 
meaningful difference.

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


[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Joseph Huber via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

jhuber6 wrote:

Yes, I'll make the offloading entries less dumb in the future. I don't like how 
for working w/ CUDA and stuff we need `cuda_offloading_entries` and  whatnot as 
well. I've been planning on merging them and simply having a field for the 
language kind and stuff. Been planning on doing that for awhile.

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


[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Gheorghe-Teodor Bercea via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

doru1004 wrote:

So it will only enter this branch if size is 0 and then if the address is not 
nullptr.

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


[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Joseph Huber via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

jhuber6 wrote:

Isn't that already done in the `if` above?

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


[clang] [attributes][analyzer] Generalize [[clang::suppress]] to declarations. (PR #80371)

2024-02-02 Thread Artem Dergachev via cfe-commits


@@ -147,6 +147,20 @@ bool BugSuppression::isSuppressed(const 
PathDiagnosticLocation &Location,
 // done as well as perform a lot of work we'll never need.
 // Gladly, none of our on-by-default checkers currently need it.
 DeclWithIssue = ACtx.getTranslationUnitDecl();
+  } else {
+// This is the fast path. However, we should still consider the topmost
+// declaration that isn't TranslationUnitDecl, because we should respect
+// attributes on the entire declaration chain.
+while (true) {

haoNoQ wrote:

This is, uh, a somewhat premature performance optimization. I think I want to 
get rid of it, as discussed in #79398 (it's incorrect as well), but it probably 
requires a separate discussion.

The static analyzer normally always takes the fast path as every single 
"supported" checker fills in the data correctly.

This isn't just about scanning the TU *here* for discovering suppressed ranges, 
it's more about the fact that the static analyzer is so careful about not 
analyzing non-user code that normally it doesn't even deserialize PCHs if they 
aren't directly required for analysis. This is demonstrated by the lovely test 
case in 
[`clang/test/Analysis/check-deserialization.cpp`](https://github.com/llvm/llvm-project/blob/llvmorg-19-init/clang/test/Analysis/check-deserialization.cpp).
 A full TU scan here will cause these PCHs to be deserialized even though the 
rest of the analysis never needed to look at them.

I have some data that this can have significant performance impact. However, 
other tools such as clang-tidy never had such optimization (they always scan 
the entire TU indiscriminately) and this never stopped them from satisfying the 
usual performance expectations of static analysis tools. We've also abandoned 
this optimization in a downstream fork for a while and it seems perfectly 
livable.

So I want to either abandon this non-deserialization guarantee (simply always 
scan the entire TU), or find a different way to satisfy it (eg., collect those 
ranges eagerly during AST construction so that to avoid the after-the-fact 
scan; then if PCHs/modules are used, suppression ranges will make it into PCHs 
and get deserialized together with them as-needed). I'll probably try to do 
some of that in the coming weeks but I wanted this patch to be independent from 
that so that to get the attribute's behavior to reasonable shape without 
breaking anything else.

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


[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Gheorghe-Teodor Bercea via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

doru1004 wrote:

Or is that too restrictive

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


[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Gheorghe-Teodor Bercea via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

doru1004 wrote:

Should we check for size > 0 too? 

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


[llvm] [libc] [libcxx] [clang-tools-extra] [openmp] [compiler-rt] [clang] [lldb] [lld] [flang] [mlir] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

https://github.com/pirama-arumuga-nainar approved this pull request.


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


[llvm] [libc] [libcxx] [clang-tools-extra] [openmp] [compiler-rt] [clang] [lldb] [lld] [flang] [mlir] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/7] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df..2d6986d145483 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d2241684..0e87cbe8ce812 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89b..18edcd05ea85c 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516a..e56f787e824f2 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f724..525ea6df3643c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25

[llvm] [libc] [libcxx] [clang-tools-extra] [openmp] [compiler-rt] [clang] [lldb] [lld] [flang] [mlir] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/6] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df..2d6986d145483 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d2241684..0e87cbe8ce812 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89b..18edcd05ea85c 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516a..e56f787e824f2 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f724..525ea6df3643c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25

[llvm] [openmp] [clang] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Joseph Huber via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

jhuber6 wrote:

If the address is not-null, then it's a kernel waiting to be registered. It's a 
little hacky but in the current construction a kernel will always have a stub 
address pass in by the compiler. So one of these "requires" entries will have 
the addr be nullptr and the size be zero.

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


[llvm] [openmp] [clang] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Joseph Huber via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

jhuber6 wrote:

This is just hacking around the offloading entires. I wanted to use the same 
struct and handling for convenience, but right now there's no basic flag for 
what the kind of the thing is. Previously we just had functions and globals, if 
the size is zero it's a global. I added a third thing which can also be checked 
if the address is nullptr currently. I want to overhaul this in the future but 
I'm hoping to get this stuff working first.

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


[llvm] [openmp] [clang] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Gheorghe-Teodor Bercea via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

doru1004 wrote:

Also, could you explain in a comment why Entry.addr is used here?

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


[llvm] [openmp] [clang] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-02 Thread Gheorghe-Teodor Bercea via cfe-commits


@@ -199,7 +199,7 @@ static int initLibrary(DeviceTy &Device) {
 Entry.size) != OFFLOAD_SUCCESS)
   REPORT("Failed to write symbol for USM %s\n", Entry.name);
   }
-} else {
+} else if (Entry.addr) {

doru1004 wrote:

So now we don't have a "default" else branch here. Is it not needed?

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


[llvm] [lldb] [lld] [mlir] [libc] [clang-tools-extra] [clang] [libcxx] [flang] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/80480

>From 2793f30243a0b93d8a1f52343ab974bf9eef4e03 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 22 Aug 2023 15:24:03 +
Subject: [PATCH 1/2] [CMAKE] Enable FatLTO as a build option for LLVM

---
 clang/cmake/caches/Fuchsia-stage2.cmake|  1 +
 llvm/cmake/modules/AddLLVM.cmake   | 11 +--
 llvm/cmake/modules/HandleLLVMOptions.cmake |  6 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901f..d5a1662cbf4aa 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5e98961855282..26ba092a82948 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0699a8586fcc7..05bbe98ef96f8 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

>From 9ee6e49745ec16578c8160fd109b175f7a217edf Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 2 Feb 2024 13:09:18 -0800
Subject: [PATCH 2/2] Add -ffat-lto-objects to CMAKE_C_FLAGS and
 CMAKE_CXX_FLAGS

---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 05bbe98ef96f8..6abdddf5421fa 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1254,7 +1254,7 @@ elseif(LLVM_ENABLE_LTO)
 endif()
 
 if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
-append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+  append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS 
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
 endif()
 
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are

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


[llvm] [lldb] [lld] [openmp] [compiler-rt] [mlir] [libc] [clang-tools-extra] [clang] [libcxx] [flang] [Driver] Report invalid target triple versions for all environment types. (PR #78655)

2024-02-02 Thread via cfe-commits

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


[clang] [Clang] Allow __is_nothrow_convertible to be used as an identifier (PR #80476)

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

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


[clang] 05a6cb2 - [Clang] Allow __is_nothrow_convertible to be used as an identifier (#80476)

2024-02-02 Thread via cfe-commits

Author: Nikolas Klauser
Date: 2024-02-02T22:18:58+01:00
New Revision: 05a6cb208635a54fb63622f13420e4d8549e5ba1

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

LOG: [Clang] Allow __is_nothrow_convertible to be used as an identifier (#80476)

`__is_nothrow_convertible` has been used by libstdc++ previously as an
identifier.

Added: 
clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp

Modified: 
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index cdbfbb1bc9fff..79928ddb5af59 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1725,6 +1725,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_member_pointer,
   tok::kw___is_nothrow_assignable,
   tok::kw___is_nothrow_constructible,
+  tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
   tok::kw___is_nullptr,
   tok::kw___is_object,

diff  --git a/clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp 
b/clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp
new file mode 100644
index 0..9e84f0ab1c081
--- /dev/null
+++ b/clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++20 -fms-extensions -Wno-microsoft %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++23 -fms-extensions -Wno-microsoft %s
+
+template 
+struct Same {
+  static constexpr auto value = __is_same(T, U);
+};
+
+template 
+struct __is_nothrow_convertible { // expected-warning{{keyword 
'__is_nothrow_convertible' will be made available as an identifier for the 
remainder of the translation unit}}
+  using type = T;
+};
+
+using A = Same<__is_nothrow_convertible::type, 
__is_nothrow_convertible::type>;



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


[llvm] [lldb] [lld] [libc] [clang] [libcxx] [flang] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/80480

>From 2793f30243a0b93d8a1f52343ab974bf9eef4e03 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 22 Aug 2023 15:24:03 +
Subject: [PATCH 1/2] [CMAKE] Enable FatLTO as a build option for LLVM

---
 clang/cmake/caches/Fuchsia-stage2.cmake|  1 +
 llvm/cmake/modules/AddLLVM.cmake   | 11 +--
 llvm/cmake/modules/HandleLLVMOptions.cmake |  6 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901f..d5a1662cbf4aa 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5e98961855282..26ba092a82948 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0699a8586fcc7..05bbe98ef96f8 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

>From 9ee6e49745ec16578c8160fd109b175f7a217edf Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 2 Feb 2024 13:09:18 -0800
Subject: [PATCH 2/2] Add -ffat-lto-objects to CMAKE_C_FLAGS and
 CMAKE_CXX_FLAGS

---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 05bbe98ef96f8..6abdddf5421fa 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1254,7 +1254,7 @@ elseif(LLVM_ENABLE_LTO)
 endif()
 
 if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
-append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+  append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS 
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
 endif()
 
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are

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


[clang] [analyzer] Teach analzer about ms __analyzer_assume(bool) and friends (PR #80456)

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

Xazax-hun wrote:

Hey!

Thanks for looking into this!

Did you actually encounter this call in the wild? The reason I ask, because 
their definition looks like this in the current version of `sal.h`:

```
#ifndef __analysis_assume // [
#ifdef _PREFAST_ // [
#define __analysis_assume(expr) __assume(expr)
#else // ][
#define __analysis_assume(expr)
#endif // ]
#endif // ]

#ifndef _Analysis_assume_ // [
#ifdef _PREFAST_ // [
#define _Analysis_assume_(expr) __assume(expr)
#else // ][
#define _Analysis_assume_(expr)
#endif // ]
#endif // ]
```

The basic idea is, when MSVC's analyzer is invoked, `_PREFAST_` is defined, and 
these macros should expand to `__assume(expr)`. This makes me a bit surprised 
if the original names are present in the preprocessed code.

There is no difference between `__analysis_assume` and `_Analysis_assume_`. The 
former is following the naming conventions in SAL 1, the latter is following 
the conventions of SAL 2. The latter is preferred in user code, but MSVC's 
toolchain still supports both spellings. 

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


[llvm] [lldb] [lld] [libc] [clang] [libcxx] [flang] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits


@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)

ilovepi wrote:

Dang, I thought I had done that. That's probably why I'm seeing an odd result. 
Thank you.

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


[llvm] [lldb] [lld] [libc] [clang] [libcxx] [flang] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Petr Hosek via cfe-commits


@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)

petrhosek wrote:

I think you also need to append this flag to `CMAKE_C_FLAGS` and 
`CMAKE_CXX_FLAGS` just like we do for `-flto` above.

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


[llvm] [lldb] [lld] [libc] [clang] [libcxx] [flang] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

ilovepi wrote:

This speeds up a 2 stage build by about 3 minutes, tests time are still much 
closer than expected. Locally I saw a bout a 5-8% speedup to build clang unit 
tests, but maybe the unit tests are too small in the overall test regime to 
make a difference.

I'll try to collect more performance numbers locally w.r.t. the test times.

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


[llvm] [lldb] [lld] [libc] [clang-tools-extra] [clang] [libcxx] [flang] [AMDGPU] Add IR-level pass to rewrite away address space 7 (PR #77952)

2024-02-02 Thread Krzysztof Drewniak via cfe-commits

krzysz00 wrote:

@piotrAMD Thanks for the thorough testing! I found the issue (stale pointer) 
and your code also gave me an unrelated crash, namely that I wasn't correctly 
handling unreachable intrinssics.

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


[llvm] [lldb] [lld] [openmp] [compiler-rt] [mlir] [libc] [clang-tools-extra] [clang] [libcxx] [flang] Make clang report invalid target versions for all environment types. (PR #78655)

2024-02-02 Thread Fangrui Song via cfe-commits


@@ -1219,8 +1222,25 @@ VersionTuple Triple::getEnvironmentVersion() const {
 
 StringRef Triple::getEnvironmentVersionString() const {
   StringRef EnvironmentName = getEnvironmentName();
+
+  // none is a valid environment type - it basically amounts to a freestanding
+  // environment.
+  if (EnvironmentName == "none")
+return "";
+
   StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
   EnvironmentName.consume_front(EnvironmentTypeName);
+
+  if (EnvironmentName.contains("-")) {
+// -obj is the suffix
+if (getObjectFormat() != Triple::UnknownObjectFormat) {
+  StringRef ObjectFormatTypeName =
+  getObjectFormatTypeName(getObjectFormat());
+  const std::string &tmp = (Twine("-") + ObjectFormatTypeName).str();

MaskRay wrote:

Just use `const std::string`. The lifetime extension due to `const &` is subtle 
and fragile, and does not give any benefit here.

https://en.cppreference.com/w/cpp/language/reference_initialization#Lifetime_of_a_temporary
https://abseil.io/tips/107

Then `EnvironmentName.consume_back(tmp);`

Avoid the used-once `StringRef Suffix = tmp;`

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


[flang] [clang-tools-extra] [openmp] [compiler-rt] [lld] [libc] [mlir] [lldb] [clang] [llvm] [libcxx] Make clang report invalid target versions for all environment types. (PR #78655)

2024-02-02 Thread Fangrui Song via cfe-commits

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

A better title may be:

[Driver] Report invalid target triple versions for all environment types.

"Driver" is better than "clang" as it is specific about where the error arises.

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


[lldb] [openmp] [llvm] [lld] [flang] [clang] [compiler-rt] [libcxx] [clang-tools-extra] [mlir] [libc] Make clang report invalid target versions for all environment types. (PR #78655)

2024-02-02 Thread Fangrui Song via cfe-commits

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


[lldb] [llvm] [lld] [clang] [libcxx] [flang] [libc] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Kirth (ilovepi)


Changes

Since LLVM supports `-ffat-lto-objects` we should enable this as an option in 
the LLVM build. FatLTO should improve the time it takes to build tests for LTO 
enabled builds of the compiler by not linking w/ the bitcode portion of the 
object files, which should speed up build times for LTO builds without 
disabling optimizations.

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


3 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+1) 
- (modified) llvm/cmake/modules/AddLLVM.cmake (+9-2) 
- (modified) llvm/cmake/modules/HandleLLVMOptions.cmake (+6) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901f..d5a1662cbf4aa 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5e98961855282..26ba092a82948 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0699a8586fcc7..05bbe98ef96f8 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

``




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


[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-02 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] cc38cd8 - [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (#80333)

2024-02-02 Thread via cfe-commits

Author: Carlos Galvez
Date: 2024-02-02T21:48:21+01:00
New Revision: cc38cd856d9a9df77d5d727377e38a891807774b

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

LOG: [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… 
(#80333)

…ationFileExtensions

Deprecated since clang-tidy 17. Use the corresponding global options
instead.

Fixes #61947

-

Co-authored-by: Carlos Gálvez 

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
clang-tools-extra/clang-tidy/utils/HeaderGuard.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersion

[flang] [lld] [lldb] [clang] [libcxx] [llvm] [libc] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

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


[clang] [Headers][X86] Editorial fixes to ia32intrin.h descriptions (PR #80490)

2024-02-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: Paul T Robinson (pogo59)


Changes

Use indicative not imperative; fix missing capitalization; spell out some 
abbreviations; "time-stamp" not "time stamp".

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


1 Files Affected:

- (modified) clang/lib/Headers/ia32intrin.h (+30-30) 


``diff
diff --git a/clang/lib/Headers/ia32intrin.h b/clang/lib/Headers/ia32intrin.h
index 1b979770e1962..fca502f1bd17b 100644
--- a/clang/lib/Headers/ia32intrin.h
+++ b/clang/lib/Headers/ia32intrin.h
@@ -26,8 +26,8 @@
 #define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
 #endif
 
-/// Find the first set bit starting from the lsb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the least significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -43,8 +43,8 @@ __bsfd(int __A) {
   return __builtin_ctz((unsigned int)__A);
 }
 
-/// Find the first set bit starting from the msb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the most significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -90,8 +90,8 @@ _bswap(int __A) {
   return (int)__builtin_bswap32((unsigned int)__A);
 }
 
-/// Find the first set bit starting from the lsb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the least significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -108,8 +108,8 @@ _bswap(int __A) {
 /// \see __bsfd
 #define _bit_scan_forward(A) __bsfd((A))
 
-/// Find the first set bit starting from the msb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the most significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -127,8 +127,8 @@ _bswap(int __A) {
 #define _bit_scan_reverse(A) __bsrd((A))
 
 #ifdef __x86_64__
-/// Find the first set bit starting from the lsb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the least significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -143,8 +143,8 @@ __bsfq(long long __A) {
   return (long long)__builtin_ctzll((unsigned long long)__A);
 }
 
-/// Find the first set bit starting from the msb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the most significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -159,7 +159,7 @@ __bsrq(long long __A) {
   return 63 - __builtin_clzll((unsigned long long)__A);
 }
 
-/// Swaps the bytes in the input. Converting little endian to big endian or
+/// Swaps the bytes in the input, converting little endian to big endian or
 ///vice versa.
 ///
 /// \headerfile 
@@ -175,7 +175,7 @@ __bswapq(long long __A) {
   return (long long)__builtin_bswap64((unsigned long long)__A);
 }
 
-/// Swaps the bytes in the input. Converting little endian to big endian or
+/// Swaps the bytes in the input, converting little endian to big endian or
 ///vice versa.
 ///
 /// \headerfile 
@@ -198,7 +198,7 @@ __bswapq(long long __A) {
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param __A
 ///An unsigned 32-bit integer operand.
@@ -220,7 +220,7 @@ __popcntd(unsigned int __A)
 /// \endcode
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param A
 ///An unsigned 32-bit integer operand.
@@ -235,7 +235,7 @@ __popcntd(unsigned int __A)
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param __A
 ///An unsigned 64-bit integer operand.
@@ -257,7 +257,7 @@ __popcntq(unsigned long long __A)
 /// \endcode
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param A
 ///An unsigned 64-bit integer operand.
@@ -328,7 +328,7 @@ __writeeflags(unsigned int __f)
 }
 #endif /* !__x86_64__ */
 
-/// Cast a 32-bit float value to a 32-bit unsigned integer value.
+/// Casts a 32-bit float value to a 32-bit unsigned integer value.
 ///
 /// \headerfile 
 ///
@@ -337,13 +337,13 @@ __writeeflags(unsigned int __f)
 ///
 /// \param __A
 ///A 32-bit float value.
-/// \returns a 32-bit unsigned integer containing the converted value.
+/// \returns A 32-bit unsigned integer conta

[clang] [Headers][X86] Editorial fixes to ia32intrin.h descriptions (PR #80490)

2024-02-02 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 created 
https://github.com/llvm/llvm-project/pull/80490

Use indicative not imperative; fix missing capitalization; spell out some 
abbreviations; "time-stamp" not "time stamp".

>From c068144b1e372aec29f268edf7184ee3d3dc7d54 Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Fri, 2 Feb 2024 12:38:16 -0800
Subject: [PATCH] [Headers][X86] Editorial fixes to ia32intrin.h descriptions

Use indicative not imperative; fix missing capitalization; spell out some 
abbreviations; "time-stamp" not "time stamp".
---
 clang/lib/Headers/ia32intrin.h | 60 +-
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/clang/lib/Headers/ia32intrin.h b/clang/lib/Headers/ia32intrin.h
index 1b979770e1962..fca502f1bd17b 100644
--- a/clang/lib/Headers/ia32intrin.h
+++ b/clang/lib/Headers/ia32intrin.h
@@ -26,8 +26,8 @@
 #define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
 #endif
 
-/// Find the first set bit starting from the lsb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the least significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -43,8 +43,8 @@ __bsfd(int __A) {
   return __builtin_ctz((unsigned int)__A);
 }
 
-/// Find the first set bit starting from the msb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the most significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -90,8 +90,8 @@ _bswap(int __A) {
   return (int)__builtin_bswap32((unsigned int)__A);
 }
 
-/// Find the first set bit starting from the lsb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the least significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -108,8 +108,8 @@ _bswap(int __A) {
 /// \see __bsfd
 #define _bit_scan_forward(A) __bsfd((A))
 
-/// Find the first set bit starting from the msb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the most significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -127,8 +127,8 @@ _bswap(int __A) {
 #define _bit_scan_reverse(A) __bsrd((A))
 
 #ifdef __x86_64__
-/// Find the first set bit starting from the lsb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the least significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -143,8 +143,8 @@ __bsfq(long long __A) {
   return (long long)__builtin_ctzll((unsigned long long)__A);
 }
 
-/// Find the first set bit starting from the msb. Result is undefined if
-///input is 0.
+/// Finds the first set bit starting from the most significant bit. Result is
+///undefined if input is 0.
 ///
 /// \headerfile 
 ///
@@ -159,7 +159,7 @@ __bsrq(long long __A) {
   return 63 - __builtin_clzll((unsigned long long)__A);
 }
 
-/// Swaps the bytes in the input. Converting little endian to big endian or
+/// Swaps the bytes in the input, converting little endian to big endian or
 ///vice versa.
 ///
 /// \headerfile 
@@ -175,7 +175,7 @@ __bswapq(long long __A) {
   return (long long)__builtin_bswap64((unsigned long long)__A);
 }
 
-/// Swaps the bytes in the input. Converting little endian to big endian or
+/// Swaps the bytes in the input, converting little endian to big endian or
 ///vice versa.
 ///
 /// \headerfile 
@@ -198,7 +198,7 @@ __bswapq(long long __A) {
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param __A
 ///An unsigned 32-bit integer operand.
@@ -220,7 +220,7 @@ __popcntd(unsigned int __A)
 /// \endcode
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param A
 ///An unsigned 32-bit integer operand.
@@ -235,7 +235,7 @@ __popcntd(unsigned int __A)
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param __A
 ///An unsigned 64-bit integer operand.
@@ -257,7 +257,7 @@ __popcntq(unsigned long long __A)
 /// \endcode
 ///
 /// This intrinsic corresponds to the \c POPCNT instruction or a
-///a sequence of arithmetic and logic ops to calculate it.
+///sequence of arithmetic and logic operations to calculate it.
 ///
 /// \param A
 ///An unsigned 64-bit integer operand.
@@ -328,7 +328,7 @@ __writeeflags(unsigned int __f)
 }
 #endif /* !__x86_64__ */
 
-/// Cast a 32-bit float value to a 32-bit unsigned integer value.
+/// Casts a 32-bit float value to a 32-bit unsigned integer 

[clang] [NFC][Clang] Replace Arch with Triplet. (PR #80465)

2024-02-02 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[llvm] [clang] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED (PR #79942)

2024-02-02 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/79942

>From 63904124dc6c6cd9b855046fac3ad1a5e72d60b7 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Wed, 19 Jul 2023 20:30:29 -0700
Subject: [PATCH 1/4] [Clang][CMake] Add CSSPGO support to
 LLVM_BUILD_INSTRUMENTED

Build on Clang-BOLT infrastructure to collect sample profiles for CSSPGO.
Add clang/cmake/caches/CSSPGO.cmake to automate CSSPGO Clang build.

Differential Revision: https://reviews.llvm.org/D155419
---
 clang/CMakeLists.txt   | 12 -
 clang/cmake/caches/CSSPGO.cmake|  3 ++
 clang/utils/perf-training/CMakeLists.txt   | 32 -
 clang/utils/perf-training/lit.cfg  |  6 +++
 clang/utils/perf-training/lit.site.cfg.in  |  1 +
 clang/utils/perf-training/perf-helper.py   | 55 ++
 llvm/CMakeLists.txt|  3 ++
 llvm/cmake/modules/HandleLLVMOptions.cmake | 26 +-
 8 files changed, 124 insertions(+), 14 deletions(-)
 create mode 100644 clang/cmake/caches/CSSPGO.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc..5d16442ac7bc3 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -741,11 +741,21 @@ if (CLANG_ENABLE_BOOTSTRAP)
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+string(TOUPPER "${BOOTSTRAP_LLVM_BUILD_INSTRUMENTED}" 
BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+if (BOOTSTRAP_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  add_dependencies(clang-bootstrap-deps llvm-profgen)
+  list(APPEND PGO_OPT 
-DLLVM_PROFGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profgen)
+endif()
   endif()
 
   if(LLVM_BUILD_INSTRUMENTED)
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps generate-profdata)
-set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PGO_OPT 
-DLLVM_SPROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+else()
+  set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+endif()
 # Use the current tools for LTO instead of the instrumented ones
 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
   CMAKE_CXX_COMPILER
diff --git a/clang/cmake/caches/CSSPGO.cmake b/clang/cmake/caches/CSSPGO.cmake
new file mode 100644
index 0..34159068d5ea3
--- /dev/null
+++ b/clang/cmake/caches/CSSPGO.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED "CSSPGO" CACHE STRING "")
+include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 61df987da7139..b8da611ad4506 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -18,8 +18,33 @@ if(LLVM_BUILD_INSTRUMENTED)
 DEPENDS clang clear-profraw ${CLANG_PGO_TRAINING_DEPS}
 )
 
+  add_custom_target(generate-profdata-deps)
+  string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" 
uppercase_LLVM_BUILD_INSTRUMENTED)
+  if (uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+set(PROFDATA_SAMPLE "--sample")
+if(NOT LLVM_PROFGEN)
+  find_program(LLVM_PROFGEN llvm-profgen)
+endif()
+
+if(NOT LLVM_PROFGEN)
+  message(STATUS "To enable converting CSSPGO samples LLVM_PROFGEN has to 
point to llvm-profgen")
+endif()
+
+# Convert perf profiles into profraw
+add_custom_target(convert-perf-profraw
+  COMMAND "${Python3_EXECUTABLE}"
+  ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py perf2prof ${LLVM_PROFGEN}
+  $ ${CMAKE_CURRENT_BINARY_DIR}
+  COMMENT "Converting perf profiles into profraw"
+  DEPENDS generate-profraw)
+add_dependencies(generate-profdata-deps convert-perf-profraw)
+  else()
+add_dependencies(generate-profdata-deps generate-profraw)
+  endif()
+
   add_custom_target(clear-profraw
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} perf.data
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -30,9 +55,12 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
+  COMMAND "${Python3_EXECUTABLE}"
+  ${CMAKE_CURRENT_SOURCE_DIR}/perf-helpe

[llvm] [compiler-rt] [libcxx] [clang-tools-extra] [flang] [clang] [libc++] Introduce one-sided binary search for lower_bound on non-random iterators, and use that to improve the average complexity of

2024-02-02 Thread Iuri Chaer via cfe-commits

ichaer wrote:

Sorry for all the noise, I'll work through the CI failures in a private PR... I 
thought I had a good handle on the tests being executed, but clearly I was 
mistaken :sweat_smile: 

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


[llvm] [clang] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED (PR #79942)

2024-02-02 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/79942

>From 63904124dc6c6cd9b855046fac3ad1a5e72d60b7 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Wed, 19 Jul 2023 20:30:29 -0700
Subject: [PATCH 1/3] [Clang][CMake] Add CSSPGO support to
 LLVM_BUILD_INSTRUMENTED

Build on Clang-BOLT infrastructure to collect sample profiles for CSSPGO.
Add clang/cmake/caches/CSSPGO.cmake to automate CSSPGO Clang build.

Differential Revision: https://reviews.llvm.org/D155419
---
 clang/CMakeLists.txt   | 12 -
 clang/cmake/caches/CSSPGO.cmake|  3 ++
 clang/utils/perf-training/CMakeLists.txt   | 32 -
 clang/utils/perf-training/lit.cfg  |  6 +++
 clang/utils/perf-training/lit.site.cfg.in  |  1 +
 clang/utils/perf-training/perf-helper.py   | 55 ++
 llvm/CMakeLists.txt|  3 ++
 llvm/cmake/modules/HandleLLVMOptions.cmake | 26 +-
 8 files changed, 124 insertions(+), 14 deletions(-)
 create mode 100644 clang/cmake/caches/CSSPGO.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc..5d16442ac7bc3 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -741,11 +741,21 @@ if (CLANG_ENABLE_BOOTSTRAP)
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+string(TOUPPER "${BOOTSTRAP_LLVM_BUILD_INSTRUMENTED}" 
BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+if (BOOTSTRAP_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  add_dependencies(clang-bootstrap-deps llvm-profgen)
+  list(APPEND PGO_OPT 
-DLLVM_PROFGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profgen)
+endif()
   endif()
 
   if(LLVM_BUILD_INSTRUMENTED)
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps generate-profdata)
-set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PGO_OPT 
-DLLVM_SPROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+else()
+  set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+endif()
 # Use the current tools for LTO instead of the instrumented ones
 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
   CMAKE_CXX_COMPILER
diff --git a/clang/cmake/caches/CSSPGO.cmake b/clang/cmake/caches/CSSPGO.cmake
new file mode 100644
index 0..34159068d5ea3
--- /dev/null
+++ b/clang/cmake/caches/CSSPGO.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED "CSSPGO" CACHE STRING "")
+include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 61df987da7139..b8da611ad4506 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -18,8 +18,33 @@ if(LLVM_BUILD_INSTRUMENTED)
 DEPENDS clang clear-profraw ${CLANG_PGO_TRAINING_DEPS}
 )
 
+  add_custom_target(generate-profdata-deps)
+  string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" 
uppercase_LLVM_BUILD_INSTRUMENTED)
+  if (uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+set(PROFDATA_SAMPLE "--sample")
+if(NOT LLVM_PROFGEN)
+  find_program(LLVM_PROFGEN llvm-profgen)
+endif()
+
+if(NOT LLVM_PROFGEN)
+  message(STATUS "To enable converting CSSPGO samples LLVM_PROFGEN has to 
point to llvm-profgen")
+endif()
+
+# Convert perf profiles into profraw
+add_custom_target(convert-perf-profraw
+  COMMAND "${Python3_EXECUTABLE}"
+  ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py perf2prof ${LLVM_PROFGEN}
+  $ ${CMAKE_CURRENT_BINARY_DIR}
+  COMMENT "Converting perf profiles into profraw"
+  DEPENDS generate-profraw)
+add_dependencies(generate-profdata-deps convert-perf-profraw)
+  else()
+add_dependencies(generate-profdata-deps generate-profraw)
+  endif()
+
   add_custom_target(clear-profraw
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} perf.data
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -30,9 +55,12 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
+  COMMAND "${Python3_EXECUTABLE}"
+  ${CMAKE_CURRENT_SOURCE_DIR}/perf-helpe

[clang-tools-extra] [clang] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

2024-02-02 Thread kadir çetinkaya via cfe-commits


@@ -138,15 +138,9 @@ std::string getNamespaceScope(const Decl *D) {
 
 std::string printDefinition(const Decl *D, PrintingPolicy PP,
 const syntax::TokenBuffer &TB) {
-  if (auto *VD = llvm::dyn_cast(D)) {
-if (auto *IE = VD->getInit()) {
-  // Initializers might be huge and result in lots of memory allocations in
-  // some catostrophic cases. Such long lists are not useful in hover cards
-  // anyway.
-  if (200 < TB.expandedTokens(IE->getSourceRange()).size())
-PP.SuppressInitializers = true;
-}
-  }
+  // Initializers might be huge and result in lots of memory allocations in 
some
+  // catostrophic cases. Such long lists are not useful in hover cards anyway.
+  PP.EntireContentsOfLargeArray = false;

kadircet wrote:

I wasn't suggesting to use tokens, but rather count the number of elements 
directly through the AST.
we've got the expression available already, so we can go over its `chidlren()` 
and count total elements we **might** encounter, and suppress intializers based 
on that (when the tokens aren't available)

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


[flang] [lld] [libc] [libcxx] [llvm] [clang] [lldb] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/80480

>From 2793f30243a0b93d8a1f52343ab974bf9eef4e03 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 22 Aug 2023 15:24:03 +
Subject: [PATCH] [CMAKE] Enable FatLTO as a build option for LLVM

---
 clang/cmake/caches/Fuchsia-stage2.cmake|  1 +
 llvm/cmake/modules/AddLLVM.cmake   | 11 +--
 llvm/cmake/modules/HandleLLVMOptions.cmake |  6 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901f..d5a1662cbf4aa 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5e98961855282..26ba092a82948 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0699a8586fcc7..05bbe98ef96f8 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

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


[clang] [clang][dataflow] Add new `join` API and replace existing `merge` implementations. (PR #80361)

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

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


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


[clang] [clang-tools-extra] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-02-02 Thread Tom Stellard via cfe-commits

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


[clang] dd0356d - [CMake][PGO] Add option for using an external project to generate profile data (#78879)

2024-02-02 Thread via cfe-commits

Author: Tom Stellard
Date: 2024-02-02T11:35:08-08:00
New Revision: dd0356d741aefa25ece973d6cc4b55dcb73b84b4

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

LOG: [CMake][PGO] Add option for using an external project to generate profile 
data (#78879)

The new CLANG_PGO_TRAINING_DATA_SOURCE_DIR allows users to specify a
CMake project to use for generating the profile data. For example, to
use the llvm-test-suite to generate profile data you would do:

$ cmake -G Ninja -B build -S llvm -C /clang/cmake/caches/PGO.cmake \
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR=
\
-DBOOTSTRAP_CLANG_PGO_TRAINING_DEPS=runtimes

Note that the CLANG_PERF_TRAINING_DEPS has been renamed to
CLANG_PGO_TRAINING_DEPS.

-

Co-authored-by: Petr Hosek 

Added: 


Modified: 
clang/utils/perf-training/CMakeLists.txt
clang/utils/perf-training/perf-helper.py
llvm/docs/AdvancedBuilds.rst

Removed: 




diff  --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 601f40902fa34..61df987da7139 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -1,6 +1,10 @@
+include(LLVMExternalProjectUtils)
+
 set(CLANG_PGO_TRAINING_DATA "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH
   "The path to a lit testsuite containing samples for PGO and order file 
generation"
   )
+set(CLANG_PGO_TRAINING_DATA_SOURCE_DIR OFF CACHE STRING "Path to source 
directory containing cmake project with source files to use for generating pgo 
data")
+set(CLANG_PGO_TRAINING_DEPS "" CACHE STRING "Extra dependencies needed to 
build the PGO training data.")
 
 if(LLVM_BUILD_INSTRUMENTED)
   configure_lit_site_cfg(
@@ -11,11 +15,11 @@ if(LLVM_BUILD_INSTRUMENTED)
   add_lit_testsuite(generate-profraw "Generating clang PGO data"
 ${CMAKE_CURRENT_BINARY_DIR}/pgo-data/
 EXCLUDE_FROM_CHECK_ALL
-DEPENDS clang clear-profraw ${CLANG_PERF_TRAINING_DEPS}
+DEPENDS clang clear-profraw ${CLANG_PGO_TRAINING_DEPS}
 )
 
   add_custom_target(clear-profraw
-COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -26,9 +30,14 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
   COMMENT "Merging profdata"
   DEPENDS generate-profraw)
+if (CLANG_PGO_TRAINING_DATA_SOURCE_DIR)
+  llvm_ExternalProject_Add(generate-profraw-external 
${CLANG_PGO_TRAINING_DATA_SOURCE_DIR}
+  USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL DEPENDS 
generate-profraw)
+  add_dependencies(generate-profdata generate-profraw-external)
+endif()
   endif()
 endif()
 

diff  --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index 959bdba5c98cc..3ed42a187fd80 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -30,26 +30,28 @@ def findFilesWithExtension(path, extension):
 
 
 def clean(args):
-if len(args) != 2:
+if len(args) < 2:
 print(
-"Usage: %s clean  \n" % __file__
+"Usage: %s clean  \n" % __file__
 + "\tRemoves all files with extension from ."
 )
 return 1
-for filename in findFilesWithExtension(args[0], args[1]):
-os.remove(filename)
+for path in args[1:-1]:
+for filename in findFilesWithExtension(path, args[-1]):
+os.remove(filename)
 return 0
 
 
 def merge(args):
-if len(args) != 3:
+if len(args) < 3:
 print(
-"Usage: %s merge   \n" % __file__
+"Usage: %s merge   \n" % __file__
 + "\tMerges all profraw files from path into output."
 )
 return 1
 cmd = [args[0], "merge", "-o", args[1]]
-cmd.extend(findFilesWithExtension(args[2], "profraw"))
+for path in args[2:]:
+cmd.extend(findFilesWithExtension(path, "profraw"))
 subprocess.check_call(cmd)
 return 0
 

diff  --git a/llvm/docs/AdvancedBuilds.rst b/llvm/docs/AdvancedBuilds.rst
index 960b19fa5317f

[clang] [llvm] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

ilovepi wrote:

I'm keeping this as a draft until I confirm the cmake config works as expected, 
especially in 2 stage builds.

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


[clang] [llvm] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-02 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/80480

Since LLVM supports `-ffat-lto-objects` we should enable this as an option in 
the LLVM build. FatLTO should improve the time it takes to build tests for LTO 
enabled builds of the compiler by not linking w/ the bitcode portion of the 
object files, which should speed up build times for LTO builds without 
disabling optimizations.

>From 2793f30243a0b93d8a1f52343ab974bf9eef4e03 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 22 Aug 2023 15:24:03 +
Subject: [PATCH] [CMAKE] Enable FatLTO as a build option for LLVM

---
 clang/cmake/caches/Fuchsia-stage2.cmake|  1 +
 llvm/cmake/modules/AddLLVM.cmake   | 11 +--
 llvm/cmake/modules/HandleLLVMOptions.cmake |  6 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901f..d5a1662cbf4aa 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5e98961855282..26ba092a82948 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0699a8586fcc7..05bbe98ef96f8 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

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


[compiler-rt] [libc] [libcxx] [libcxxabi] [llvm] [clang-tools-extra] [lld] [lldb] [clang] [flang] [TTI][RISCV]Improve costs for fixed vector whole reg extract/insert. (PR #80164)

2024-02-02 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev updated 
https://github.com/llvm/llvm-project/pull/80164

>From cfd0dcfa1f5fabd12cf4d7bf8d5a10bd324ace0a Mon Sep 17 00:00:00 2001
From: Alexey Bataev 
Date: Wed, 31 Jan 2024 16:47:49 +
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 .../Target/RISCV/RISCVTargetTransformInfo.cpp |  42 +
 .../RISCV/shuffle-extract_subvector.ll| 174 +-
 .../RISCV/shuffle-insert_subvector.ll |  42 ++---
 .../CostModel/RISCV/shuffle-interleave.ll |   6 +-
 4 files changed, 153 insertions(+), 111 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp 
b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index fe1cdb2dfa423..465a05b6497a2 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -326,6 +326,48 @@ InstructionCost 
RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
 switch (Kind) {
 default:
   break;
+case TTI::SK_ExtractSubvector:
+  if (isa(SubTp)) {
+unsigned TpRegs = getRegUsageForType(Tp);
+unsigned NumElems =
+divideCeil(Tp->getElementCount().getFixedValue(), TpRegs);
+// Whole vector extract - just the vector itself + (possible) vsetvli.
+// TODO: consider adding the cost for vsetvli.
+if (Index % NumElems == 0) {
+  std::pair SubLT =
+  getTypeLegalizationCost(SubTp);
+  return Index == 0
+ ? TTI::TCC_Free
+ : SubLT.first * getRISCVInstructionCost(RISCV::VMV_V_V,
+ SubLT.second,
+ CostKind);
+}
+  }
+  break;
+case TTI::SK_InsertSubvector:
+  if (auto *FSubTy = dyn_cast(SubTp)) {
+unsigned TpRegs = getRegUsageForType(Tp);
+unsigned SubTpRegs = getRegUsageForType(SubTp);
+unsigned NextSubTpRegs = getRegUsageForType(FixedVectorType::get(
+Tp->getElementType(), FSubTy->getNumElements() + 1));
+unsigned NumElems =
+divideCeil(Tp->getElementCount().getFixedValue(), TpRegs);
+// Whole vector insert - just the vector itself + (possible) vsetvli.
+// TODO: consider adding the cost for vsetvli.
+if (Index % NumElems == 0 &&
+(any_of(Args, UndefValue::classof) ||
+ (SubTpRegs != 0 && SubTpRegs != NextSubTpRegs &&
+  TpRegs / SubTpRegs > 1))) {
+  std::pair SubLT =
+  getTypeLegalizationCost(SubTp);
+  return Index == 0
+ ? TTI::TCC_Free
+ : SubLT.first * getRISCVInstructionCost(RISCV::VMV_V_V,
+ SubLT.second,
+ CostKind);
+}
+  }
+  break;
 case TTI::SK_PermuteSingleSrc: {
   if (Mask.size() >= 2 && LT.second.isFixedLengthVector()) {
 MVT EltTp = LT.second.getVectorElementType();
diff --git a/llvm/test/Analysis/CostModel/RISCV/shuffle-extract_subvector.ll 
b/llvm/test/Analysis/CostModel/RISCV/shuffle-extract_subvector.ll
index 76cb1955a2b37..901d66e1124d8 100644
--- a/llvm/test/Analysis/CostModel/RISCV/shuffle-extract_subvector.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/shuffle-extract_subvector.ll
@@ -9,15 +9,15 @@
 
 define void @test_vXf64(<4 x double> %src256, <8 x double> %src512) {
 ; CHECK-LABEL: 'test_vXf64'
-; CHECK-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: 
%V256_01 = shufflevector <4 x double> %src256, <4 x double> undef, <2 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: 
%V256_23 = shufflevector <4 x double> %src256, <4 x double> undef, <2 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: 
%V512_01 = shufflevector <8 x double> %src512, <8 x double> undef, <2 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: 
%V512_23 = shufflevector <8 x double> %src512, <8 x double> undef, <2 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: 
%V512_45 = shufflevector <8 x double> %src512, <8 x double> undef, <2 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: 
%V512_67 = shufflevector <8 x double> %src512, <8 x double> undef, <2 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: 
%V512_0123 = shufflevector <8 x double> %src512, <8 x double> undef, <4 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: 
%V512_2345 = shufflevector <8 x double> %src512, <8 x double> undef, <4 x i32> 

-; CHECK-NEXT:  Cost Model: Found an estimat

[clang] [-Wunsafe-buffer-usage] Introduce std::array fixits (PR #80084)

2024-02-02 Thread Ziqing Luo via cfe-commits


@@ -2495,10 +2470,97 @@ static FixItList fixVariableWithSpan(const VarDecl *VD,
   return fixLocalVarDeclWithSpan(VD, Ctx, getUserFillPlaceHolder(), Handler);
 }
 
+static FixItList fixVarDeclWithArray(const VarDecl *D, const ASTContext &Ctx,
+ UnsafeBufferUsageHandler &Handler) {
+  FixItList FixIts{};
+
+  if (auto CAT = dyn_cast(D->getType())) {
+const QualType &ArrayEltT = CAT->getElementType();
+assert(!ArrayEltT.isNull() && "Trying to fix a non-array type variable!");
+
+const SourceLocation IdentifierLoc = getVarDeclIdentifierLoc(D);
+
+// Get the spelling of the element type as written in the source file
+// (including macros, etc.).
+auto MaybeElemTypeTxt =
+getRangeText({D->getBeginLoc(), IdentifierLoc}, Ctx.getSourceManager(),
+ Ctx.getLangOpts());
+if (!MaybeElemTypeTxt)
+  return {};
+const llvm::StringRef ElemTypeTxt = MaybeElemTypeTxt->trim();
+
+// Find the '[' token.
+std::optional NextTok = Lexer::findNextToken(
+IdentifierLoc, Ctx.getSourceManager(), Ctx.getLangOpts());
+while (NextTok && !NextTok->is(tok::l_square))
+  NextTok = Lexer::findNextToken(NextTok->getLocation(),
+ Ctx.getSourceManager(), 
Ctx.getLangOpts());
+if (!NextTok)
+  return {};
+const SourceLocation LSqBracketLoc = NextTok->getLocation();
+
+// Get the spelling of the array size as written in the source file
+// (including macros, etc.).

ziqingluo-90 wrote:

I wish we could have a more elegant way to get the spelling of the array size.  
I feel like `TypeLoc` is suppose to offer it but it does not behave as I expect 
in this case.  (`TypeLoc` also disappointed me in dealing with cv-qualifiers. 
`¯\_(ツ)_/¯`) 

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


[clang] [Clang] Allow __is_nothrow_convertible to be used as an identifier (PR #80476)

2024-02-02 Thread via cfe-commits

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


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


  1   2   3   4   >