[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-05 Thread via cfe-commits


@@ -5432,6 +5432,9 @@ class Sema final : public SemaBase {
   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
   CXXRecordDecl *Record);
 
+  void MarkBaseDestructorsReferenced(SourceLocation Loc, CXXRecordDecl 
*Record);
+  void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);

cor3ntin wrote:

I feel these should just be static functions in the cpp file

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits

https://github.com/rj-jesus updated 
https://github.com/llvm/llvm-project/pull/129732

>From 624d1e924aa130eea2a8ddaefaeb587aab642f2f Mon Sep 17 00:00:00 2001
From: Ricardo Jesus 
Date: Tue, 4 Mar 2025 02:36:06 -0800
Subject: [PATCH 1/5] Precommit tests

---
 .../AArch64/sve-fixed-length-offsets.ll   | 227 ++
 1 file changed, 227 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll

diff --git a/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll 
b/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll
new file mode 100644
index 0..04ace95de3348
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll
@@ -0,0 +1,227 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ptrue p0.b
+; CHECK-128-NEXT:mov w8, #256 // =0x100
+; CHECK-128-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-128-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ptrue p0.b
+; CHECK-256-NEXT:mov w8, #256 // =0x100
+; CHECK-256-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-256-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ptrue p0.b
+; CHECK-512-NEXT:mov w8, #256 // =0x100
+; CHECK-512-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-512-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ptrue p0.b
+; CHECK-1024-NEXT:mov w8, #256 // =0x100
+; CHECK-1024-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-1024-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ptrue p0.b
+; CHECK-2048-NEXT:mov w8, #256 // =0x100
+; CHECK-2048-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-2048-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ptrue p0.h
+; CHECK-128-NEXT:mov x8, #128 // =0x80
+; CHECK-128-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-128-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ptrue p0.h
+; CHECK-256-NEXT:mov x8, #128 // =0x80
+; CHECK-256-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-256-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ptrue p0.h
+; CHECK-512-NEXT:mov x8, #128 // =0x80
+; CHECK-512-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-512-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ptrue p0.h
+; CHECK-1024-NEXT:mov x8, #128 // =0x80
+; CHECK-1024-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-1024-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-1024-NEXT:  

[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread David Sherwood via cfe-commits


@@ -0,0 +1,362 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv8i16:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i16, ptr %ldptr, i64 128
+  %stoff = getelementptr inbounds nuw i16, ptr %stptr, i64 128
+  %x = load , ptr %ldoff, align 2
+  store  %x, ptr %stoff, align 2
+  ret void
+}
+
+define void @nxv4i32(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv4i32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s
+; CHECK-NEXT:mov x8, #64 // =0x40
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0, x8, lsl #2]
+; CHECK-NEXT:st1w { z0.s }, p0, [x1, x8, lsl #2]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv4i32:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv4i32:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv4i32:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv4i32:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv4i32:
+; CHECK-2048:   // %bb.0:
+; CHECK-

[clang] [clang] Fix crash when #embed data does not fit into an array (PR #129567)

2025-03-05 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [llvm] [Assignment Tracking] Replace `undef` debug info with `poison` (PR #129755)

2025-03-05 Thread Orlando Cazalet-Hyams via cfe-commits

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

LGTM, thanks

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibm (Bit Manipulation) extension (PR #129504)

2025-03-05 Thread via cfe-commits


@@ -341,6 +341,19 @@ static DecodeStatus decodeUImmOperandGE(MCInst &Inst, 
uint32_t Imm,
   return MCDisassembler::Success;
 }
 
+template 
+static DecodeStatus decodeUImmPlus1OperandGE(MCInst &Inst, uint32_t Imm,
+ int64_t Address,
+ const MCDisassembler *Decoder) {
+  assert(isUInt(Imm) && "Invalid immediate");
+
+  if (Imm < LowerBound)
+return MCDisassembler::Fail;

hchandel wrote:

Done. Please have a look at the test and let me know if I should change 
anything.

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


[clang] 5916903 - [clang] Fix crash when #embed data does not fit into an array (#129567)

2025-03-05 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2025-03-05T11:04:52+01:00
New Revision: 59169036ca0e064612886713d609873f776e85db

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

LOG: [clang] Fix crash when #embed data does not fit into an array (#129567)

Tune SemaInit code handling #embed to take into account how many array
elements remains to initialize.
Also issue a warning/error message when the array/struct is at the end
but there is still #embed data left.

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

Added: 
clang/test/CodeGen/excess-embed-data.c
clang/test/Sema/excess-embed-data.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5098e5e983103..38111db3e6919 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -243,6 +243,8 @@ Bug Fixes in This Version
   when it can affect template argument deduction (#GH122306).
 - Fix crash on code completion of function calls involving partial order of 
function templates
   (#GH125500).
+- Fixed clang crash when #embed data does not fit into an array
+  (#GH128987).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 86f5a5c1d4434..56ec33fe37bf3 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -519,12 +519,13 @@ class InitListChecker {
 uint64_t ElsCount = 1;
 // Otherwise try to fill whole array with embed data.
 if (Entity.getKind() == InitializedEntity::EK_ArrayElement) {
+  unsigned ArrIndex = Entity.getElementIndex();
   auto *AType =
   SemaRef.Context.getAsArrayType(Entity.getParent()->getType());
   assert(AType && "expected array type when initializing array");
   ElsCount = Embed->getDataElementCount();
   if (const auto *CAType = dyn_cast(AType))
-ElsCount = std::min(CAType->getSize().getZExtValue(),
+ElsCount = std::min(CAType->getSize().getZExtValue() - ArrIndex,
 ElsCount - CurEmbedIndex);
   if (ElsCount == Embed->getDataElementCount()) {
 CurEmbed = nullptr;
@@ -1317,7 +1318,7 @@ void InitListChecker::CheckExplicitInitList(const 
InitializedEntity &Entity,
 return;
 
   // Don't complain for incomplete types, since we'll get an error elsewhere.
-  if (Index < IList->getNumInits() && !T->isIncompleteType()) {
+  if ((Index < IList->getNumInits() || CurEmbed) && !T->isIncompleteType()) {
 // We have leftover initializers
 bool ExtraInitsIsError = SemaRef.getLangOpts().CPlusPlus ||
   (SemaRef.getLangOpts().OpenCL && T->isVectorType());
@@ -2180,6 +2181,7 @@ void InitListChecker::CheckArrayType(const 
InitializedEntity &Entity,
 
 InitializedEntity ElementEntity = InitializedEntity::InitializeElement(
 SemaRef.Context, StructuredIndex, Entity);
+ElementEntity.setElementIndex(elementIndex.getExtValue());
 
 unsigned EmbedElementIndexBeforeInit = CurEmbedIndex;
 // Check this element.

diff  --git a/clang/test/CodeGen/excess-embed-data.c 
b/clang/test/CodeGen/excess-embed-data.c
new file mode 100644
index 0..9143125ba2398
--- /dev/null
+++ b/clang/test/CodeGen/excess-embed-data.c
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c23 -emit-llvm -triple x86_64 %s -o - | FileCheck %s
+
+struct S {
+  int arr[3];
+};
+
+struct S1 {
+  struct S s;
+};
+
+// CHECK: @[[BConst:.*]] = private unnamed_addr constant [2 x i32] [i32 47, 
i32 47]
+// CHECK: @[[DConst:.*]] = private unnamed_addr constant [2 x i8] c"//"
+// CHECK: @[[SConst:.*]] = private unnamed_addr constant %struct.S { [3 x i32] 
[i32 47, i32 47, i32 32] }
+// CHECK: @[[S1Const:.*]] = private unnamed_addr constant %struct.S1 { 
%struct.S { [3 x i32] [i32 47, i32 47, i32 32] } }
+
+void cases(int x) {
+  int a[3] = {x, x,
+#embed __FILE__
+  };
+
+  int b[2] = {
+#embed __FILE__
+  };
+
+  char d[2] = {
+#embed __FILE__
+  };
+
+  struct S s = {
+#embed __FILE__
+  , x
+  };
+
+  struct S1 s1 = {
+#embed __FILE__
+  , x
+  };
+}
+// CHECK: define dso_local void @cases(i32 noundef %[[X:.*]])
+// CHECK:  %[[A:.*]] = alloca [3 x i32]
+// CHECK:  %[[B:.*]] = alloca [2 x i32]
+// CHECK:  %[[D:.*]] = alloca [2 x i8]
+// CHECK:  %[[S:.*]] = alloca %struct.S
+// CHECK:  %[[S1:.*]] = alloca %struct.S1
+// CHECK:  %[[LX:.*]] = load i32, ptr %[[X]].addr
+// CHECK:  store i32 %[[LX]], ptr %[[A]]
+// CHECK:  %[[GEP1:.*]] = getelementptr inbounds i32, ptr %[[A]], i64 1
+// CHECK:  %[[LX1:.*]] = load i32, ptr %[[X]].addr
+// CHECK:  store i32 %1, ptr %arrayinit.element
+// CHECK:  %[[GEP1:.*]] = getelementptr inbounds i32, ptr %[[A]], i64 2
+// CHECK:  store i32 47, ptr %[[GEP1]

[clang] [clang] Fix crash when #embed data does not fit into an array (PR #129567)

2025-03-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

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


Here is the relevant piece of the build log for the reference

```
Step 7 (Add check check-offload) failure: test (failure)
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp 
(1002 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (1003 
of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp 
(1004 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug50022.cpp 
(1005 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (1006 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (1007 
of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (1008 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp 
(1009 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (1010 of 1011)
TIMEOUT: libomptarget :: amdgcn-amd-amdhsa :: 
offloading/parallel_offloading_map.cpp (1011 of 1011)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
offloading/parallel_offloading_map.cpp' FAILED 
Exit Code: -9
Timeout: Reached timeout of 100 seconds

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/parallel_offloading_map.cpp
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/parallel_offloading_map.cpp.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
 && 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/parallel_offloading_map.cpp.tmp
 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/parallel_offloading_map.cpp
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/parallel_offloading_map.cpp
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/parallel_offloading_map.cpp.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/parallel_offloading_map.cpp.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -9
# error: command reached timeout: True
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runt

[clang] [clang][bytecode][NFC] Fix getting references to local function ptrs (PR #129852)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

This is the same thing we do for globals and parameters.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 394e39e99a106..281fb7e14a57d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6325,7 +6325,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
   if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
 if (IsReference)
-  return this->emitGetLocal(PT_Ptr, Offset, E);
+  return this->emitGetLocal(classifyPrim(E), Offset, E);
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
 if (IsReference) {

``




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


[clang-tools-extra] [clangd] gitignore index directories (PR #90305)

2025-03-05 Thread Sumit Sahrawat via cfe-commits

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread David Sherwood via cfe-commits

https://github.com/david-arm approved this pull request.

LGTM!

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


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-05 Thread via cfe-commits


@@ -10333,6 +10334,74 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   }
 }
 
+// Loop over the parameters to see if any of the size expressions contains

cor3ntin wrote:

Can we
 - Put all of that in a separate function
 - Maybe not run it in modes VLAs are not supported

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


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-05 Thread via cfe-commits


@@ -10333,6 +10334,74 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   }
 }
 
+// Loop over the parameters to see if any of the size expressions contains
+// a DeclRefExpr which refers to a variable from an outer scope that is
+// also named later in the parameter list.
+// e.g., int n; void func(int array[n], int n);
+SmallVector DRESizeExprs;
+llvm::for_each(Params, [&](const ParmVarDecl *Param) {
+  // If we have any size expressions we need to check against, check them
+  // now.
+  for (const auto *DRE : DRESizeExprs) {
+// Check to see if this parameter has the same name as one of the
+// DeclRefExprs we wanted to test against. If so, then we found a
+// situation where an earlier parameter refers to the name of a later
+// parameter, which is (currently) only valid if there's a variable
+// from an outer scope with the same name.
+if (const auto *SizeExprND = dyn_cast(DRE->getDecl())) {
+  if (SizeExprND->getIdentifier() == Param->getIdentifier()) {
+// Diagnose the DeclRefExpr from the parameter with the size
+// expression.
+Diag(DRE->getLocation(), diag::warn_vla_size_expr_shadow);
+// Note the parameter that a user could be confused into thinking
+// they're referring to.
+Diag(Param->getLocation(), diag::note_vla_size_expr_shadow_param);
+// Note the DeclRefExpr that's actually being used.
+Diag(DRE->getDecl()->getLocation(),
+ diag::note_vla_size_expr_shadow_actual);
+  }
+}
+  }
+
+  // To check whether its size expression is a simple DeclRefExpr, we first
+  // have to walk through pointers or references, but array types always
+  // decay to a pointer, so skip if this is a DecayedType.
+  QualType QT = Param->getType();
+  while (!isa(QT.getTypePtr()) &&
+ (QT->isPointerType() || QT->isReferenceType()))
+QT = QT->getPointeeType();

cor3ntin wrote:

There isn't already a way to do that?

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


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-05 Thread via cfe-commits


@@ -10333,6 +10334,74 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   }
 }
 
+// Loop over the parameters to see if any of the size expressions contains
+// a DeclRefExpr which refers to a variable from an outer scope that is
+// also named later in the parameter list.
+// e.g., int n; void func(int array[n], int n);
+SmallVector DRESizeExprs;
+llvm::for_each(Params, [&](const ParmVarDecl *Param) {
+  // If we have any size expressions we need to check against, check them
+  // now.
+  for (const auto *DRE : DRESizeExprs) {
+// Check to see if this parameter has the same name as one of the
+// DeclRefExprs we wanted to test against. If so, then we found a
+// situation where an earlier parameter refers to the name of a later
+// parameter, which is (currently) only valid if there's a variable
+// from an outer scope with the same name.
+if (const auto *SizeExprND = dyn_cast(DRE->getDecl())) {
+  if (SizeExprND->getIdentifier() == Param->getIdentifier()) {
+// Diagnose the DeclRefExpr from the parameter with the size
+// expression.
+Diag(DRE->getLocation(), diag::warn_vla_size_expr_shadow);
+// Note the parameter that a user could be confused into thinking
+// they're referring to.
+Diag(Param->getLocation(), diag::note_vla_size_expr_shadow_param);
+// Note the DeclRefExpr that's actually being used.
+Diag(DRE->getDecl()->getLocation(),
+ diag::note_vla_size_expr_shadow_actual);
+  }
+}
+  }
+
+  // To check whether its size expression is a simple DeclRefExpr, we first
+  // have to walk through pointers or references, but array types always
+  // decay to a pointer, so skip if this is a DecayedType.
+  QualType QT = Param->getType();
+  while (!isa(QT.getTypePtr()) &&
+ (QT->isPointerType() || QT->isReferenceType()))
+QT = QT->getPointeeType();
+
+  // An array type is always decayed to a pointer, so we need to get the
+  // original type in that case.
+  if (const auto *DT = QT->getAs())
+QT = DT->getOriginalType();
+
+  // Now we can see if it's a VLA type with a size expression.
+  // FIXME: it would be nice to handle constant-sized arrays as well,
+  // e.g., constexpr int n = 12; void foo(int array[n], int n);
+  // however, the constant expression is replaced by its value at the time
+  // we form the type, so we've lost that information here.
+  if (!QT->hasSizedVLAType())
+return;
+
+  const VariableArrayType *VAT = 
getASTContext().getAsVariableArrayType(QT);
+  if (!VAT)
+return;
+
+  class DeclRefFinder : public RecursiveASTVisitor {

cor3ntin wrote:

Do we want to use the dynamic ast visitor?

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


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-05 Thread via cfe-commits


@@ -10333,6 +10334,74 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   }
 }
 
+// Loop over the parameters to see if any of the size expressions contains
+// a DeclRefExpr which refers to a variable from an outer scope that is
+// also named later in the parameter list.
+// e.g., int n; void func(int array[n], int n);
+SmallVector DRESizeExprs;
+llvm::for_each(Params, [&](const ParmVarDecl *Param) {
+  // If we have any size expressions we need to check against, check them
+  // now.
+  for (const auto *DRE : DRESizeExprs) {
+// Check to see if this parameter has the same name as one of the
+// DeclRefExprs we wanted to test against. If so, then we found a
+// situation where an earlier parameter refers to the name of a later
+// parameter, which is (currently) only valid if there's a variable
+// from an outer scope with the same name.
+if (const auto *SizeExprND = dyn_cast(DRE->getDecl())) {
+  if (SizeExprND->getIdentifier() == Param->getIdentifier()) {

cor3ntin wrote:

In C++, we probably don't want to warn on `int foo[::a], int a`, so we should 
look at nested name specifiers

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


[clang] [Clang] Add support for missing OpenCL extensions (PR #129777)

2025-03-05 Thread Sven van Haastregt via cfe-commits

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

What is the motivation for this change?  We are trying to move away from adding 
extensions to this file for extensions that only add builtin functions, see 
e.g. https://reviews.llvm.org/D92231 .  What functionality are you gaining by 
adding them here?

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


[clang] clang: Regenerate test checks (PR #129834)

2025-03-05 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/129834

The previous checks missed the new metadata at the end of the line.
Regenerate to avoid future spurious diffs.

>From 677c5bdaecc01020e00abd1814701680091fa367 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 5 Mar 2025 12:58:34 +0700
Subject: [PATCH] clang: Regenerate test checks

The previous checks missed the new metadata at the end of the line.
Regenerate to avoid future spurious diffs.
---
 .../builtin-amdgcn-atomic-inc-dec.cpp | 80 +--
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp 
b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
index 4f3b5a4ce7760..5920ceda4a811 100644
--- a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
+++ b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
@@ -13,12 +13,12 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 
[[TMP2]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 
[[TMP2]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4:![0-9]+]]
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 
[[TMP6]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 
[[TMP6]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -39,12 +39,12 @@ __attribute__((device)) void 
test_non_volatile_parameter32(__UINT32_TYPE__ *ptr)
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 
[[TMP2]] syncscope("workgroup") seq_cst, align 8
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 
[[TMP2]] syncscope("workgroup") seq_cst, align 8, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i64 [[TMP3]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i64, ptr [[TMP5]], align 8
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 
[[TMP6]] syncscope("workgroup") seq_cst, align 8
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 
[[TMP6]] syncscope("workgroup") seq_cst, align 8, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i64 [[TMP7]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:ret void
 //
@@ -65,12 +65,12 @@ __attribute__((device)) void 
test_non_volatile_parameter64(__UINT64_TYPE__ *ptr)
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load volatile i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load volatile i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw volatile udec_wrap ptr [[TMP4]], 
i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw volatile udec_wrap ptr [[TMP4]], 
i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -91,12 +91,12 @@ __attribute__((device)) void 
test_volatile_parameter32(volatile __UINT32_TYPE__
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHEC

[clang] [clang] Fix crash when #embed data does not fit into an array (PR #129567)

2025-03-05 Thread via cfe-commits

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


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


[clang] [clang] Fix crash when #embed data does not fit into an array (PR #129567)

2025-03-05 Thread via cfe-commits

cor3ntin wrote:

Thanks for the fix!

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


[clang] [CIR] Upstream global variable linkage types (PR #129072)

2025-03-05 Thread Morris Hafner via cfe-commits

https://github.com/mmha updated https://github.com/llvm/llvm-project/pull/129072

>From 1432050465c1e351edfdfe908de52d1d6d1cf15e Mon Sep 17 00:00:00 2001
From: Morris Hafner 
Date: Mon, 3 Mar 2025 18:44:40 +0100
Subject: [PATCH 1/7] [CIR] Upstream global variable linkage types

This change implements variable linkage types in ClangIR except for common 
linkage which requires Comdat support.
---
 .../include/clang/CIR/Dialect/IR/CIRDialect.h |   2 +
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  83 ++-
 .../clang/CIR/Dialect/IR/CIROpsEnums.h| 119 +++
 .../clang/CIR/Dialect/IR/CMakeLists.txt   |   4 +-
 .../clang/CIR/Interfaces/CIROpInterfaces.h|  29 +++
 .../clang/CIR/Interfaces/CIROpInterfaces.td   |  63 ++
 .../clang/CIR/Interfaces/CMakeLists.txt   |   9 +
 clang/include/clang/CIR/MissingFeatures.h |   4 +
 clang/lib/CIR/CodeGen/CIRGenModule.cpp| 202 +-
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  12 ++
 clang/lib/CIR/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |   8 +-
 clang/lib/CIR/Dialect/IR/CMakeLists.txt   |   3 +-
 clang/lib/CIR/FrontendAction/CMakeLists.txt   |   4 +
 clang/lib/CIR/Interfaces/CIROpInterfaces.cpp  |  22 ++
 clang/lib/CIR/Interfaces/CMakeLists.txt   |   4 +-
 .../CIR/Lowering/DirectToLLVM/CMakeLists.txt  |   5 +
 clang/test/CIR/global-var-simple.cpp  |  64 +++---
 clang/test/CIR/global_var_linkage.cpp |  11 +
 19 files changed, 608 insertions(+), 41 deletions(-)
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIROpsEnums.h
 create mode 100644 clang/include/clang/CIR/Interfaces/CIROpInterfaces.h
 create mode 100644 clang/include/clang/CIR/Interfaces/CIROpInterfaces.td
 create mode 100644 clang/lib/CIR/Interfaces/CIROpInterfaces.cpp
 create mode 100644 clang/test/CIR/global_var_linkage.cpp

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h 
b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
index 683176b139ca4..0684cf5034f5d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
@@ -28,6 +28,8 @@
 
 #include "clang/CIR/Dialect/IR/CIRAttrs.h"
 #include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
+#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
+#include "clang/CIR/Interfaces/CIROpInterfaces.h"
 
 // TableGen'erated files for MLIR dialects require that a macro be defined when
 // they are included.  GET_OP_CLASSES tells the file to define the classes for
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 48178b0ff247d..2cef98099fdbb 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -18,6 +18,8 @@ include "clang/CIR/Dialect/IR/CIRDialect.td"
 include "clang/CIR/Dialect/IR/CIRTypes.td"
 include "clang/CIR/Dialect/IR/CIRAttrs.td"
 
+include "clang/CIR/Interfaces/CIROpInterfaces.td"
+
 include "mlir/IR/BuiltinAttributeInterfaces.td"
 include "mlir/IR/EnumAttr.td"
 include "mlir/IR/SymbolInterfaces.td"
@@ -430,6 +432,59 @@ def ScopeOp : CIR_Op<"scope", [
 // GlobalOp
 
//===--===//
 
+// Linkage types. This is currently a replay of llvm/IR/GlobalValue.h, this is
+// currently handy as part of forwarding appropriate linkage types for LLVM
+// lowering, specially useful for C++ support.
+
+// Externally visible function
+def Global_ExternalLinkage :
+  I32EnumAttrCase<"ExternalLinkage", 0, "external">;
+// Available for inspection, not emission.
+def Global_AvailableExternallyLinkage :
+  I32EnumAttrCase<"AvailableExternallyLinkage", 1, "available_externally">;
+// Keep one copy of function when linking (inline)
+def Global_LinkOnceAnyLinkage :
+  I32EnumAttrCase<"LinkOnceAnyLinkage", 2, "linkonce">;
+// Same, but only replaced by something equivalent.
+def Global_LinkOnceODRLinkage :
+  I32EnumAttrCase<"LinkOnceODRLinkage", 3, "linkonce_odr">;
+// Keep one copy of named function when linking (weak)
+def Global_WeakAnyLinkage :
+  I32EnumAttrCase<"WeakAnyLinkage", 4, "weak">;
+// Same, but only replaced by something equivalent.
+def Global_WeakODRLinkage :
+  I32EnumAttrCase<"WeakODRLinkage", 5, "weak_odr">;
+// TODO: should we add something like appending linkage too?
+// Special purpose, only applies to global arrays
+// def Global_AppendingLinkage :
+//   I32EnumAttrCase<"AppendingLinkage", 6, "appending">;
+// Rename collisions when linking (static functions).
+def Global_InternalLinkage :
+  I32EnumAttrCase<"InternalLinkage", 7, "internal">;
+// Like Internal, but omit from symbol table, prefix it with
+// "cir_" to prevent clash with MLIR's symbol "private".
+def Global_PrivateLinkage :
+  I32EnumAttrCase<"PrivateLinkage", 8, "cir_private">;
+// ExternalWeak linkage description.
+def Global_ExternalWeakLinkage :
+  I32EnumAttrCase<"ExternalWeakLinkage", 9, "extern_weak">;
+// Tentative defi

[clang] [CLANG-CL] Remove the 'static' specifier for _FUNCTION_ in MSVC mode. (PR #128184)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -747,8 +747,10 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 if (const CXXMethodDecl *MD = dyn_cast(FD)) {
   if (MD->isVirtual() && IK != 
PredefinedIdentKind::PrettyFunctionNoVirtual)
 Out << "virtual ";
-  if (MD->isStatic())
-Out << "static ";
+  if (MD->isStatic()) {
+if (!ForceElaboratedPrinting)
+  Out << "static ";
+  }

AaronBallman wrote:

```suggestion
  if (MD->isStatic() && !ForceElaboratedPrinting)
Out << "static ";
```

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


[clang] [llvm] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

This change is about 20 years overdue 

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


[clang] [CLANG-CL] Remove the 'static' specifier for _FUNCTION_ in MSVC mode. (PR #128184)

2025-03-05 Thread Aaron Ballman via cfe-commits

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


[libclc] [libclc] Reduce bithacking in CLC frexp (PR #129871)

2025-03-05 Thread Matt Arsenault via cfe-commits

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

I haven't spent much time looking at this one, because we have instructions for 
the two halves 

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


[clang] [Sema] Instantiate destructors for initialized members (PR #128866)

2025-03-05 Thread Maurice Heumann via cfe-commits

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits

https://github.com/rj-jesus updated 
https://github.com/llvm/llvm-project/pull/129732

>From 624d1e924aa130eea2a8ddaefaeb587aab642f2f Mon Sep 17 00:00:00 2001
From: Ricardo Jesus 
Date: Tue, 4 Mar 2025 02:36:06 -0800
Subject: [PATCH 1/7] Precommit tests

---
 .../AArch64/sve-fixed-length-offsets.ll   | 227 ++
 1 file changed, 227 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll

diff --git a/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll 
b/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll
new file mode 100644
index 0..04ace95de3348
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll
@@ -0,0 +1,227 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ptrue p0.b
+; CHECK-128-NEXT:mov w8, #256 // =0x100
+; CHECK-128-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-128-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ptrue p0.b
+; CHECK-256-NEXT:mov w8, #256 // =0x100
+; CHECK-256-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-256-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ptrue p0.b
+; CHECK-512-NEXT:mov w8, #256 // =0x100
+; CHECK-512-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-512-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ptrue p0.b
+; CHECK-1024-NEXT:mov w8, #256 // =0x100
+; CHECK-1024-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-1024-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ptrue p0.b
+; CHECK-2048-NEXT:mov w8, #256 // =0x100
+; CHECK-2048-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-2048-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ptrue p0.h
+; CHECK-128-NEXT:mov x8, #128 // =0x80
+; CHECK-128-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-128-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ptrue p0.h
+; CHECK-256-NEXT:mov x8, #128 // =0x80
+; CHECK-256-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-256-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ptrue p0.h
+; CHECK-512-NEXT:mov x8, #128 // =0x80
+; CHECK-512-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-512-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ptrue p0.h
+; CHECK-1024-NEXT:mov x8, #128 // =0x80
+; CHECK-1024-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-1024-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-1024-NEXT:  

[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-05 Thread via cfe-commits


@@ -5863,6 +5869,26 @@ 
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
  &DirectVirtualBases);
 }
 
+void Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
+  CXXRecordDecl *ClassDecl) {
+  // Ignore dependent contexts. Also ignore unions, since their members never
+  // have destructors implicitly called.
+  if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
+return;
+
+  // FIXME: all the access-control diagnostics are positioned on the
+  // field/base declaration.  That's probably good; that said, the
+  // user might reasonably want to know why the destructor is being
+  // emitted, and we currently don't say.

cor3ntin wrote:

I'm not sure that this fix me is actually useful

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits

https://github.com/rj-jesus updated 
https://github.com/llvm/llvm-project/pull/129732

>From 624d1e924aa130eea2a8ddaefaeb587aab642f2f Mon Sep 17 00:00:00 2001
From: Ricardo Jesus 
Date: Tue, 4 Mar 2025 02:36:06 -0800
Subject: [PATCH 1/4] Precommit tests

---
 .../AArch64/sve-fixed-length-offsets.ll   | 227 ++
 1 file changed, 227 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll

diff --git a/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll 
b/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll
new file mode 100644
index 0..04ace95de3348
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sve-fixed-length-offsets.ll
@@ -0,0 +1,227 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ptrue p0.b
+; CHECK-128-NEXT:mov w8, #256 // =0x100
+; CHECK-128-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-128-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ptrue p0.b
+; CHECK-256-NEXT:mov w8, #256 // =0x100
+; CHECK-256-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-256-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ptrue p0.b
+; CHECK-512-NEXT:mov w8, #256 // =0x100
+; CHECK-512-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-512-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ptrue p0.b
+; CHECK-1024-NEXT:mov w8, #256 // =0x100
+; CHECK-1024-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-1024-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ptrue p0.b
+; CHECK-2048-NEXT:mov w8, #256 // =0x100
+; CHECK-2048-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-2048-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ptrue p0.h
+; CHECK-128-NEXT:mov x8, #128 // =0x80
+; CHECK-128-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-128-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ptrue p0.h
+; CHECK-256-NEXT:mov x8, #128 // =0x80
+; CHECK-256-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-256-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ptrue p0.h
+; CHECK-512-NEXT:mov x8, #128 // =0x80
+; CHECK-512-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-512-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ptrue p0.h
+; CHECK-1024-NEXT:mov x8, #128 // =0x80
+; CHECK-1024-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-1024-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-1024-NEXT:  

[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-05 Thread Sven van Haastregt via cfe-commits

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


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


[clang] [Clang][diagnostics] Improve the diagnostics for chained comparisons (PR #129285)

2025-03-05 Thread via cfe-commits

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


[clang] [clang][bytecode][NFC] Fix getting references to local function ptrs (PR #129852)

2025-03-05 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/129852

This is the same thing we do for globals and parameters.

>From 9f71da5ed2b6dfa7ec26b1b0b5a51a713edeee4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 5 Mar 2025 10:01:39 +0100
Subject: [PATCH] [clang][bytecode][NFC] Fix getting references to local
 function ptrs

This is the same thing we do for globals and parameters.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 394e39e99a106..281fb7e14a57d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6325,7 +6325,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
   if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
 if (IsReference)
-  return this->emitGetLocal(PT_Ptr, Offset, E);
+  return this->emitGetLocal(classifyPrim(E), Offset, E);
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
 if (IsReference) {

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


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-05 Thread via cfe-commits


@@ -10333,6 +10334,74 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   }
 }
 
+// Loop over the parameters to see if any of the size expressions contains
+// a DeclRefExpr which refers to a variable from an outer scope that is
+// also named later in the parameter list.
+// e.g., int n; void func(int array[n], int n);
+SmallVector DRESizeExprs;
+llvm::for_each(Params, [&](const ParmVarDecl *Param) {
+  // If we have any size expressions we need to check against, check them
+  // now.
+  for (const auto *DRE : DRESizeExprs) {
+// Check to see if this parameter has the same name as one of the
+// DeclRefExprs we wanted to test against. If so, then we found a
+// situation where an earlier parameter refers to the name of a later
+// parameter, which is (currently) only valid if there's a variable
+// from an outer scope with the same name.
+if (const auto *SizeExprND = dyn_cast(DRE->getDecl())) {
+  if (SizeExprND->getIdentifier() == Param->getIdentifier()) {

cor3ntin wrote:

```suggestion
if (const auto *SizeExprND = dyn_cast(DRE->getDecl()); 
SizeExprND && SizeExprND->getIdentifier() == Param->getIdentifier()) {
```

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


[clang] [llvm] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread Yingwei Zheng via cfe-commits


@@ -189,8 +190,10 @@ class LLVM_ABI Module {
   std::string ModuleID;   ///< Human readable identifier for the module
   std::string SourceFileName; ///< Original source file name for module,
   ///< recorded in bitcode.
-  std::string TargetTriple;   ///< Platform target triple Module compiled 
on
-  ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
+  /// Platform target triple Module compiled on
+  /// Format: (arch)(sub)-(vendor)-(sys0-(abi)

dtcxzyw wrote:

```suggestion
  /// Format: (arch)(sub)-(vendor)-(sys)-(abi)
```

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits


@@ -7380,17 +7380,31 @@ bool 
AArch64DAGToDAGISel::SelectAddrModeIndexedSVE(SDNode *Root, SDValue N,
 return false;
 
   SDValue VScale = N.getOperand(1);
-  if (VScale.getOpcode() != ISD::VSCALE)
+  std::optional MulImm;
+  if (VScale.getOpcode() == ISD::VSCALE) {
+MulImm = cast(VScale.getOperand(0))->getSExtValue();
+  } else if (auto C = dyn_cast(VScale)) {
+int64_t ByteOffset = C->getSExtValue();
+constexpr auto SVEBitsPerBlock = AArch64::SVEBitsPerBlock;
+auto MinVScale = Subtarget->getMinSVEVectorSizeInBits() / SVEBitsPerBlock;
+auto MaxVScale = Subtarget->getMaxSVEVectorSizeInBits() / SVEBitsPerBlock;
+
+if (!MaxVScale || MinVScale != MaxVScale || ByteOffset % MaxVScale != 0)

rj-jesus wrote:

Thanks - I've added this. Please let me know if that's what you had in mind. :)


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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibm (Bit Manipulation) extension (PR #129504)

2025-03-05 Thread via cfe-commits


@@ -333,6 +397,59 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
 } // hasSideEffects = 0, mayLoad = 0, mayStore = 0
 } // Predicates = [HasVendorXqcia, IsRV32]
 
+let Predicates = [HasVendorXqcibm, IsRV32] in {
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
+  def QC_INSBRI : QCIRVInstRI<0b1, simm11, "qc.insbri">;
+  def QC_INSBI : RVInstIBase<0b001, OPC_CUSTOM_0, (outs GPRNoX0:$rd),
+ (ins simm5:$imm5, uimm5_plus1:$width,
+ uimm5:$shamt), "qc.insbi",
+ "$rd, $imm5, $width, $shamt"> {
+bits<5> imm5;
+bits<5> shamt;
+bits<6> width;

hchandel wrote:

Done

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


[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #129234)

2025-03-05 Thread Gábor Horváth via cfe-commits

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


[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #129234)

2025-03-05 Thread Gábor Horváth via cfe-commits


@@ -443,21 +443,44 @@ class reverse_children {
 
 } // namespace
 
-reverse_children::reverse_children(Stmt *S) {
-  if (CallExpr *CE = dyn_cast(S)) {
-children = CE->getRawSubExprs();
+reverse_children::reverse_children(Stmt *S, ASTContext &Ctx) {
+  switch (S->getStmtClass()) {
+  case Stmt::CallExprClass: {

Xazax-hun wrote:

I think `dyn_cast` would succeed for `CXXMemberCallExpr` and similar subclasses 
because `classof` is implemented  like:
```
  static bool classof(const Stmt *T) {
return T->getStmtClass() >= firstCallExprConstant &&
   T->getStmtClass() <= lastCallExprConstant;
  }
  ```
On the other hand, I'd expect the stmt class to be `CallExprClass` only when it 
is not a derived type. 

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Paul Walker via cfe-commits


@@ -0,0 +1,362 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv8i16:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i16, ptr %ldptr, i64 128
+  %stoff = getelementptr inbounds nuw i16, ptr %stptr, i64 128
+  %x = load , ptr %ldoff, align 2
+  store  %x, ptr %stoff, align 2
+  ret void
+}
+
+define void @nxv4i32(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv4i32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s
+; CHECK-NEXT:mov x8, #64 // =0x40
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0, x8, lsl #2]
+; CHECK-NEXT:st1w { z0.s }, p0, [x1, x8, lsl #2]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv4i32:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv4i32:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv4i32:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv4i32:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv4i32:
+; CHECK-2048:   // %bb.0:
+; CHECK-

[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-05 Thread Maurice Heumann via cfe-commits


@@ -5432,6 +5432,9 @@ class Sema final : public SemaBase {
   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
   CXXRecordDecl *Record);
 
+  void MarkBaseDestructorsReferenced(SourceLocation Loc, CXXRecordDecl 
*Record);
+  void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);

momo5502 wrote:

done

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits


@@ -0,0 +1,362 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv8i16:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i16, ptr %ldptr, i64 128
+  %stoff = getelementptr inbounds nuw i16, ptr %stptr, i64 128
+  %x = load , ptr %ldoff, align 2
+  store  %x, ptr %stoff, align 2
+  ret void
+}
+
+define void @nxv4i32(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv4i32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s
+; CHECK-NEXT:mov x8, #64 // =0x40
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0, x8, lsl #2]
+; CHECK-NEXT:st1w { z0.s }, p0, [x1, x8, lsl #2]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv4i32:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv4i32:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv4i32:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv4i32:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv4i32:
+; CHECK-2048:   // %bb.0:
+; CHECK-

[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Paul Walker via cfe-commits


@@ -7380,17 +7380,31 @@ bool 
AArch64DAGToDAGISel::SelectAddrModeIndexedSVE(SDNode *Root, SDValue N,
 return false;
 
   SDValue VScale = N.getOperand(1);
-  if (VScale.getOpcode() != ISD::VSCALE)
+  std::optional MulImm;
+  if (VScale.getOpcode() == ISD::VSCALE) {
+MulImm = cast(VScale.getOperand(0))->getSExtValue();
+  } else if (auto C = dyn_cast(VScale)) {
+int64_t ByteOffset = C->getSExtValue();
+constexpr auto SVEBitsPerBlock = AArch64::SVEBitsPerBlock;
+auto MinVScale = Subtarget->getMinSVEVectorSizeInBits() / SVEBitsPerBlock;
+auto MaxVScale = Subtarget->getMaxSVEVectorSizeInBits() / SVEBitsPerBlock;
+
+if (!MaxVScale || MinVScale != MaxVScale || ByteOffset % MaxVScale != 0)

paulwalker-arm wrote:

This might start being a common idiom.  Do you mind adding a helper function to 
AArch64Subtarget along the lines of `optional 
getSVEVectorSizeInBits()`?


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


[clang] ea15e8b - [C++20] [Modules] Avoid use-but-not-defined error

2025-03-05 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2025-03-05T19:05:49+08:00
New Revision: ea15e8b16eacdf2fb3a9715c5fc753b62fdfd516

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

LOG: [C++20] [Modules] Avoid use-but-not-defined error

See the attached test for example.

Added: 
clang/test/Modules/external-but-not-type-external.cppm

Modified: 
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index a1810003f5425..88dd212259085 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -330,6 +330,12 @@ namespace clang {
 }
 
 bool clang::CanElideDeclDef(const Decl *D) {
+  bool isExternalWithNoLinkageType = false;
+  if (auto *VD = dyn_cast(D))
+if (VD->hasExternalFormalLinkage() &&
+!isExternalFormalLinkage(VD->getType()->getLinkage()))
+  isExternalWithNoLinkageType = true;
+
   if (auto *FD = dyn_cast(D)) {
 if (FD->isInlined() || FD->isConstexpr())
   return false;
@@ -339,6 +345,9 @@ bool clang::CanElideDeclDef(const Decl *D) {
 
 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
   return false;
+
+if (isExternalWithNoLinkageType && !FD->isExternC())
+  return false;
   }
 
   if (auto *VD = dyn_cast(D)) {
@@ -352,6 +361,9 @@ bool clang::CanElideDeclDef(const Decl *D) {
 
 if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
   return false;
+
+if (isExternalWithNoLinkageType && !VD->isExternC())
+  return false;
   }
 
   return true;

diff  --git a/clang/test/Modules/external-but-not-type-external.cppm 
b/clang/test/Modules/external-but-not-type-external.cppm
new file mode 100644
index 0..37a0d29104c5d
--- /dev/null
+++ b/clang/test/Modules/external-but-not-type-external.cppm
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o 
%t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only 
-verify
+
+//--- a.cppm
+export module a;
+namespace {
+struct Local {};
+}
+
+export class A { 
+public:
+void *external_but_not_type_external(Local *) {
+return nullptr;
+}
+};
+
+//--- use.cc
+// expected-no-diagnostics
+import a;
+void *use() {
+A a;
+return a.external_but_not_type_external(nullptr);
+}



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


[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #129234)

2025-03-05 Thread Gábor Horváth via cfe-commits


@@ -180,3 +183,58 @@ int test_reference_that_might_be_after_the_end(int idx) {
   return ref;
 }
 
+// From: https://github.com/llvm/llvm-project/issues/100762
+extern int arrOf10[10];
+void using_builtin(int x) {
+  __builtin_assume(x > 101); // CallExpr
+  arrOf10[x] = 404; // expected-warning {{Out of bound access to memory}}
+}
+
+void using_assume_attr(int ax) {
+  [[assume(ax > 100)]]; // NullStmt with an "assume" attribute.
+  arrOf10[ax] = 405; // expected-warning {{Out of bound access to memory}}
+}
+
+void using_many_assume_attr(int yx) {
+  [[assume(yx > 104), assume(yx > 200), assume(yx < 300)]]; // NullStmt with 
an attribute
+  arrOf10[yx] = 406; // expected-warning{{Out of bound access to memory}}
+}
+
+
+int using_builtin_assume_has_no_sideeffects(int y) {
+  // We should not apply sideeffects of the argument of [[assume(...)]].
+  // "y" should not get incremented;
+  __builtin_assume(++y == 43); // expected-warning {{assumption is ignored 
because it contains (potential) side-effects}}
+  clang_analyzer_eval(y == 42); // expected-warning {{FALSE}}
+  return y;
+}
+
+
+
+int using_assume_attr_has_no_sideeffects(int y) {
+
+  // We should not apply sideeffects of the argument of [[assume(...)]].
+  // "y" should not get incremented;
+  [[assume(++y == 43)]]; // expected-warning {{assumption is ignored because 
it contains (potential) side-effects}}
+ 
+  clang_analyzer_eval(y == 42); // expected-warning {{TRUE}} expected-warning 
{{FALSE}} FIXME: This should be only TRUE.
+
+  clang_analyzer_eval(y == 43); // expected-warning {{FALSE}} expected-warning 
{{TRUE}} FIXME: This should be only FALSE.
+
+  return y;
+}
+
+
+int using_builtinassume_has_no_sideeffects(int u) {
+  // We should not apply sideeffects of the argument of __builtin_assume(...)
+  // "u" should not get incremented;
+  __builtin_assume(++u == 43); // expected-warning {{assumption is ignored 
because it contains (potential) side-effects}}

Xazax-hun wrote:

I am a bit confused why is this not addressed by the `if 
(!AssumeExpr->HasSideEffects(Ctx)) {` checks in the code. Any idea?


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


[clang] [llvm] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Nikita Popov (nikic)


Changes

The module currently stores the target triple as a string. This means that any 
code that wants to actually use the triple first has to instantiate a Triple, 
which is somewhat expensive. The change in #121652 caused a moderate 
compile-time regression due to this. While it would be easy enough to work 
around, I think that architecturally, it makes more sense to store the parsed 
Triple in the module, so that it can always be directly queried.

For this change, I've opted not to add any magic conversions between 
std::string and Triple for backwards-compatibilty purses, and instead write out 
needed Triple()s or str()s explicitly. This is because I think a decent number 
of them should be changed to work on Triple as well, to avoid unnecessary 
conversions back and forth.

The only interesting part in this patch is that the default triple is 
Triple("") instead of Triple() to preserve existing behavior. The former 
defaults to using the ELF object format instead of unknown object format. We 
should fix that as well.

Compile-time: 
https://llvm-compile-time-tracker.com/compare.php?from=e5d5503e4efa48b61194b1e70e469aba91297bec&to=8187b17ebd5ab65ad8bcc0b4ec288d77cb4f739c&stat=instructions:u

---

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


93 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenAction.cpp (+3-3) 
- (modified) clang/lib/CodeGen/ModuleBuilder.cpp (+1-1) 
- (modified) clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp (+1-1) 
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+2-2) 
- (modified) clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (+2-2) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+7-6) 
- (modified) 
llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
 (+1-1) 
- (modified) llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h (+1-1) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+1-1) 
- (modified) llvm/include/llvm/IR/Module.h (+7-5) 
- (modified) llvm/include/llvm/LTO/legacy/LTOModule.h (+2-6) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+3) 
- (modified) llvm/lib/Analysis/DXILMetadataAnalysis.cpp (+1-1) 
- (modified) llvm/lib/Analysis/Lint.cpp (+1-1) 
- (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+3-4) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2-2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+3-3) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+5-5) 
- (modified) llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp (+1-2) 
- (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MIRParser/MIRParser.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/StackProtector.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/WinEHPrepare.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/TargetSelect.cpp (+1-1) 
- (modified) llvm/lib/Frontend/Offloading/OffloadWrapper.cpp (+1-1) 
- (modified) llvm/lib/Frontend/Offloading/Utility.cpp (+3-3) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+2-2) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+1-1) 
- (modified) llvm/lib/IR/Core.cpp (+3-3) 
- (modified) llvm/lib/IR/EHPersonalities.cpp (+1-1) 
- (modified) llvm/lib/IR/Globals.cpp (+2-4) 
- (modified) llvm/lib/IR/ValueSymbolTable.cpp (+1-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTO.cpp (+3-2) 
- (modified) llvm/lib/LTO/LTOBackend.cpp (+9-8) 
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+3-3) 
- (modified) llvm/lib/LTO/LTOModule.cpp (+3-3) 
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+7-7) 
- (modified) llvm/lib/LTO/UpdateCompilerUsed.cpp (+1-1) 
- (modified) llvm/lib/Linker/IRMover.cpp (+4-4) 
- (modified) llvm/lib/Object/IRObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Object/IRSymtab.cpp (+3-4) 
- (modified) llvm/lib/ProfileData/InstrProf.cpp (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+2-3) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp (+2-2) 
- (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+2-2) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp (+2-2) 
- (modified) llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp (+1-1) 
- (modified) llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (+3-3) 
- (modified) llvm/lib/Target/SPIRV/SPIRVAPI.cpp (+5-5) 
- (modified) llvm/lib/Target/X86/X86MCInstLower.cpp (+2-3) 
- (modified) llvm/lib/Transforms/CFGuard/CFGuard.cpp (+2-2) 
- 

[clang] [llvm] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Nikita Popov (nikic)


Changes

The module currently stores the target triple as a string. This means that any 
code that wants to actually use the triple first has to instantiate a Triple, 
which is somewhat expensive. The change in #121652 caused a moderate 
compile-time regression due to this. While it would be easy enough to work 
around, I think that architecturally, it makes more sense to store the parsed 
Triple in the module, so that it can always be directly queried.

For this change, I've opted not to add any magic conversions between 
std::string and Triple for backwards-compatibilty purses, and instead write out 
needed Triple()s or str()s explicitly. This is because I think a decent number 
of them should be changed to work on Triple as well, to avoid unnecessary 
conversions back and forth.

The only interesting part in this patch is that the default triple is 
Triple("") instead of Triple() to preserve existing behavior. The former 
defaults to using the ELF object format instead of unknown object format. We 
should fix that as well.

Compile-time: 
https://llvm-compile-time-tracker.com/compare.php?from=e5d5503e4efa48b61194b1e70e469aba91297bec&to=8187b17ebd5ab65ad8bcc0b4ec288d77cb4f739c&stat=instructions:u

---

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


93 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenAction.cpp (+3-3) 
- (modified) clang/lib/CodeGen/ModuleBuilder.cpp (+1-1) 
- (modified) clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp (+1-1) 
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+2-2) 
- (modified) clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (+2-2) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+7-6) 
- (modified) 
llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
 (+1-1) 
- (modified) llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h (+1-1) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+1-1) 
- (modified) llvm/include/llvm/IR/Module.h (+7-5) 
- (modified) llvm/include/llvm/LTO/legacy/LTOModule.h (+2-6) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+3) 
- (modified) llvm/lib/Analysis/DXILMetadataAnalysis.cpp (+1-1) 
- (modified) llvm/lib/Analysis/Lint.cpp (+1-1) 
- (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+3-4) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2-2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+3-3) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+5-5) 
- (modified) llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp (+1-2) 
- (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MIRParser/MIRParser.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/StackProtector.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/WinEHPrepare.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/TargetSelect.cpp (+1-1) 
- (modified) llvm/lib/Frontend/Offloading/OffloadWrapper.cpp (+1-1) 
- (modified) llvm/lib/Frontend/Offloading/Utility.cpp (+3-3) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+2-2) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+1-1) 
- (modified) llvm/lib/IR/Core.cpp (+3-3) 
- (modified) llvm/lib/IR/EHPersonalities.cpp (+1-1) 
- (modified) llvm/lib/IR/Globals.cpp (+2-4) 
- (modified) llvm/lib/IR/ValueSymbolTable.cpp (+1-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTO.cpp (+3-2) 
- (modified) llvm/lib/LTO/LTOBackend.cpp (+9-8) 
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+3-3) 
- (modified) llvm/lib/LTO/LTOModule.cpp (+3-3) 
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+7-7) 
- (modified) llvm/lib/LTO/UpdateCompilerUsed.cpp (+1-1) 
- (modified) llvm/lib/Linker/IRMover.cpp (+4-4) 
- (modified) llvm/lib/Object/IRObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Object/IRSymtab.cpp (+3-4) 
- (modified) llvm/lib/ProfileData/InstrProf.cpp (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+2-3) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp (+2-2) 
- (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+2-2) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp (+2-2) 
- (modified) llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp (+1-1) 
- (modified) llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (+3-3) 
- (modified) llvm/lib/Target/SPIRV/SPIRVAPI.cpp (+5-5) 
- (modified) llvm/lib/Target/X86/X86MCInstLower.cpp (+2-3) 
- (modified) llvm/lib/Transforms/CFGuard/CFGuard.cpp (+2-2)

[libclc] [libclc] Reduce bithacking in CLC frexp (PR #129871)

2025-03-05 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/129871

Also replace some magic constants with named ones.

Checking against FP zero and using isnan and isinf functions allows the 
optimizer to create one unified @llvm.is.fpclass intrinsic. This results in 
fewer more canonical IR instructions.

>From 92a9ff3d37b64523577719c2be844061da1ac3ce Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 5 Mar 2025 11:20:21 +
Subject: [PATCH] [libclc] Reduce bithacking in CLC frexp

Also replace some magic constants with named ones.

Checking against FP zero and using isnan and isinf functions allows the
optimizer to create one unified @llvm.is.fpclass intrinsic. This results
in fewer more canonical IR instructions.
---
 libclc/clc/lib/generic/math/clc_frexp.cl  |  2 +
 libclc/clc/lib/generic/math/clc_frexp.inc | 52 +--
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/libclc/clc/lib/generic/math/clc_frexp.cl 
b/libclc/clc/lib/generic/math/clc_frexp.cl
index ecc3eb6281b1e..dc9b00f7ef664 100644
--- a/libclc/clc/lib/generic/math/clc_frexp.cl
+++ b/libclc/clc/lib/generic/math/clc_frexp.cl
@@ -23,6 +23,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 
diff --git a/libclc/clc/lib/generic/math/clc_frexp.inc 
b/libclc/clc/lib/generic/math/clc_frexp.inc
index 22966f08579a9..d59ccad9ac98c 100644
--- a/libclc/clc/lib/generic/math/clc_frexp.inc
+++ b/libclc/clc/lib/generic/math/clc_frexp.inc
@@ -28,17 +28,22 @@
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE
 __clc_frexp(__CLC_GENTYPE x, __CLC_ADDRESS_SPACE __CLC_INTN *ep) {
   __CLC_INTN i = __CLC_AS_INTN(x);
-  __CLC_INTN ai = i & 0x7fff;
-  __CLC_INTN d = ai > 0 & ai < 0x0080;
-  /* scale subnormal by 2^26 without multiplying */
+  __CLC_INTN ai = i & EXSIGNBIT_SP32;
+
+  // Scale subnormal by 2^26 without multiplying
+  __CLC_INTN is_subnormal = ai > 0 && ai < 0x0080;
   __CLC_GENTYPE s = __CLC_AS_GENTYPE(ai | 0x0d80) - 0x1.0p-100f;
-  ai = __clc_select(ai, __CLC_AS_INTN(s), d);
-  __CLC_INTN e =
-  (ai >> 23) - 126 - __clc_select((__CLC_INTN)0, (__CLC_INTN)26, d);
-  __CLC_INTN t = ai == (__CLC_INTN)0 | e == (__CLC_INTN)129;
-  i = (i & (__CLC_INTN)0x8000) | (__CLC_INTN)0x3f00 | (ai & 
0x007f);
-  *ep = __clc_select(e, (__CLC_INTN)0, t);
-  return __clc_select(__CLC_AS_GENTYPE(i), x, t);
+  ai = __clc_select(ai, __CLC_AS_INTN(s), is_subnormal);
+  __CLC_INTN e = (ai >> EXPSHIFTBITS_SP32) - 126 -
+ __clc_select((__CLC_INTN)0, (__CLC_INTN)26, is_subnormal);
+
+  i = (i & (__CLC_INTN)SIGNBIT_SP32) | (__CLC_INTN)HALFEXPBITS_SP32 |
+  (ai & (__CLC_INTN)MANTBITS_SP32);
+
+  __CLC_INTN is_inf_nan_or_zero =
+  x == __CLC_FP_LIT(0.0) || __clc_isinf(x) || __clc_isnan(x);
+  *ep = __clc_select(e, (__CLC_INTN)0, is_inf_nan_or_zero);
+  return __clc_select(__CLC_AS_GENTYPE(i), x, is_inf_nan_or_zero);
 }
 #endif
 
@@ -56,19 +61,22 @@ __clc_frexp(__CLC_GENTYPE x, __CLC_ADDRESS_SPACE __CLC_INTN 
*ep) {
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE
 __clc_frexp(__CLC_GENTYPE x, __CLC_ADDRESS_SPACE __CLC_INTN *ep) {
   __CLC_LONGN i = __CLC_AS_LONGN(x);
-  __CLC_LONGN ai = i & 0x7fffL;
-  __CLC_LONGN d = ai > 0 & ai < 0x0010L;
-  // scale subnormal by 2^54 without multiplying
+  __CLC_LONGN ai = i & EXSIGNBIT_DP64;
+
+  // Scale subnormal by 2^54 without multiplying
+  __CLC_LONGN is_subnormal = ai > 0 && ai < 0x0010L;
   __CLC_GENTYPE s = __CLC_AS_GENTYPE(ai | 0x0370L) - 0x1.0p-968;
-  ai = __clc_select(ai, __CLC_AS_LONGN(s), d);
-  __CLC_LONGN e = (ai >> 52) - (__CLC_LONGN)1022 -
-  __clc_select((__CLC_LONGN)0, (__CLC_LONGN)54, d);
-  __CLC_LONGN t = ai == 0 | e == 1025;
-  i = (i & (__CLC_LONGN)0x8000L) |
-  (__CLC_LONGN)0x3fe0L |
-  (ai & (__CLC_LONGN)0x000fL);
-  *ep = __CLC_CONVERT_INTN(__clc_select(e, 0L, t));
-  return __clc_select(__CLC_AS_GENTYPE(i), x, t);
+  ai = __clc_select(ai, __CLC_AS_LONGN(s), is_subnormal);
+  __CLC_LONGN e = (ai >> EXPSHIFTBITS_DP64) - (__CLC_LONGN)1022 -
+  __clc_select((__CLC_LONGN)0, (__CLC_LONGN)54, is_subnormal);
+
+  i = (i & (__CLC_LONGN)SIGNBIT_DP64) | (__CLC_LONGN)HALFEXPBITS_DP64 |
+  (ai & (__CLC_LONGN)MANTBITS_DP64);
+
+  __CLC_LONGN is_inf_nan_or_zero =
+  x == __CLC_FP_LIT(0.0) || __clc_isinf(x) || __clc_isnan(x);
+  *ep = __CLC_CONVERT_INTN(__clc_select(e, 0L, is_inf_nan_or_zero));
+  return __clc_select(__CLC_AS_GENTYPE(i), x, is_inf_nan_or_zero);
 }
 
 #endif

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


[clang] [llvm] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread Nikita Popov via cfe-commits

https://github.com/nikic created 
https://github.com/llvm/llvm-project/pull/129868

The module currently stores the target triple as a string. This means that any 
code that wants to actually use the triple first has to instantiate a Triple, 
which is somewhat expensive. The change in #121652 caused a moderate 
compile-time regression due to this. While it would be easy enough to work 
around, I think that architecturally, it makes more sense to store the parsed 
Triple in the module, so that it can always be directly queried.

For this change, I've opted not to add any magic conversions between 
std::string and Triple for backwards-compatibilty purses, and instead write out 
needed Triple()s or str()s explicitly. This is because I think a decent number 
of them should be changed to work on Triple as well, to avoid unnecessary 
conversions back and forth.

The only interesting part in this patch is that the default triple is 
Triple("") instead of Triple() to preserve existing behavior. The former 
defaults to using the ELF object format instead of unknown object format. We 
should fix that as well.

Compile-time: 
https://llvm-compile-time-tracker.com/compare.php?from=e5d5503e4efa48b61194b1e70e469aba91297bec&to=8187b17ebd5ab65ad8bcc0b4ec288d77cb4f739c&stat=instructions:u

>From 13e2505e361d7ed462486162a5fe56b904018f65 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 4 Mar 2025 17:04:48 +0100
Subject: [PATCH] [IR] Store Triple in Module (NFC)

The module currently stores the target triple as a string. This
means that any code that wants to actually use the triple first
has to instantiate a Triple, which is somewhat expensive. The
change in #121652 caused a moderate compile-time regression due
to this. While it would be easy enough to work around, I think
that architecturally, it makes more sense to store the parsed
Triple in the module, so that it can always be directly queried.

For this change, I've opted not to add any magic conversions
between std::string and Triple for backwards-compatibilty purses,
and instead write out needed Triple()s or str()s explicitly. This
is because I think a decent number of them should be changed to
work on Triple as well, to avoid unnecessary conversions back and
forth.

The only interesting part in this patch is that the default triple
is Triple("") instead of Triple() to preserve existing behavior.
The former defaults to using the ELF object format instead of
unknown object format. We should fix that as well.
---
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/ModuleBuilder.cpp |  2 +-
 .../CodeGen/ObjectFilePCHContainerWriter.cpp|  2 +-
 clang/lib/Interpreter/DeviceOffload.cpp |  4 ++--
 .../clang-fuzzer/handle-llvm/handle_llvm.cpp|  4 ++--
 .../clang-linker-wrapper/ClangLinkerWrapper.cpp | 13 +++--
 .../LLJITWithThinLTOSummaries.cpp   |  2 +-
 .../llvm/ExecutionEngine/Orc/ExecutionUtils.h   |  2 +-
 .../include/llvm/Frontend/OpenMP/OMPIRBuilder.h |  2 +-
 llvm/include/llvm/IR/Module.h   | 12 +++-
 llvm/include/llvm/LTO/legacy/LTOModule.h|  8 ++--
 llvm/include/llvm/TargetParser/Triple.h |  3 +++
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp  |  2 +-
 llvm/lib/Analysis/Lint.cpp  |  2 +-
 llvm/lib/Analysis/TargetLibraryInfo.cpp |  7 +++
 llvm/lib/AsmParser/LLParser.cpp |  4 ++--
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp   |  6 +++---
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp   |  4 ++--
 llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp   | 10 +-
 llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp |  3 +--
 llvm/lib/CodeGen/GlobalMerge.cpp|  2 +-
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp|  8 
 llvm/lib/CodeGen/StackProtector.cpp |  2 +-
 llvm/lib/CodeGen/WinEHPrepare.cpp   |  2 +-
 llvm/lib/ExecutionEngine/TargetSelect.cpp   |  2 +-
 llvm/lib/Frontend/Offloading/OffloadWrapper.cpp |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp|  6 +++---
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp   |  4 ++--
 llvm/lib/IR/AsmWriter.cpp   |  2 +-
 llvm/lib/IR/Core.cpp|  6 +++---
 llvm/lib/IR/EHPersonalities.cpp |  2 +-
 llvm/lib/IR/Globals.cpp |  6 ++
 llvm/lib/IR/ValueSymbolTable.cpp|  2 +-
 llvm/lib/IR/Verifier.cpp|  2 +-
 llvm/lib/LTO/LTO.cpp|  5 +++--
 llvm/lib/LTO/LTOBackend.cpp | 17 +
 llvm/lib/LTO/LTOCodeGenerator.cpp   |  6 +++---
 llvm/lib/LTO/LTOModule.cpp  |  6 +++---
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp   | 14 +++---
 llvm/lib/LTO/UpdateCompilerUsed.cpp |  2 +-
 llvm/lib/Linker/IRMover.cpp 

[libclc] [libclc] Reduce bithacking for INF/NAN values (PR #129738)

2025-03-05 Thread Fraser Cormack via cfe-commits


@@ -86,13 +84,10 @@ _CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE 
__clc_hypot(__CLC_GENTYPE x,
   r = c ? s : r;
 
   // Check for NaN
-  c = __clc_isnan(x) || __clc_isnan(y);
-  r = c ? __CLC_AS_GENTYPE((__CLC_ULONGN)QNANBITPATT_DP64) : r;
+  r = __clc_isnan(x) || __clc_isnan(y) ? __CLC_GENTYPE_NAN : r;

frasercrmck wrote:

> Doesn't matter much, but can fold this condition into one 
> __builtin_isunordered (or just let instcombine do it)

Yeah I think I'll just let instcombine do it (which it does).

> Above should also be rewritten with frexp and ldexp

Sorry, I'm not seeing which bit - could you explain? I note that libclc's frexp 
and ldexp are more involved than any of the bithacking here (possibly due to 
subnormal support?) so I'm not sure what the goal would be.

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


[clang] [Clang][diagnostics] Improve the diagnostics for chained comparisons (PR #129285)

2025-03-05 Thread via cfe-commits

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

LGTM

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


[clang] [Clang] use parameter location for abbreviated function templates (PR #129139)

2025-03-05 Thread via cfe-commits


@@ -7991,8 +7991,12 @@ Sema::CheckTemplateDeclScope(Scope *S, 
TemplateParameterList *TemplateParams) {
   //   have C linkage.
   DeclContext *Ctx = S->getEntity();
   if (Ctx && Ctx->isExternCContext()) {
-Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
-<< TemplateParams->getSourceRange();
+SourceRange Range =
+TemplateParams->getTemplateLoc().isInvalid() && TemplateParams->size()
+? TemplateParams->getParam(TemplateParams->size() - 1)
+  ->getSourceRange()

cor3ntin wrote:

Why use the last one and not the first one?
(Either getTemplateLoc is valid or all parameters are invented)

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


[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-05 Thread Alex Voicu via cfe-commits

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

I'm temporarily blocking this to go through a bit more than OCL - I just want 
to ensure that this doesn't break some C/C++ corner case. Otherwise LGTM.

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


[clang] d1bcac0 - [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode (#129814)

2025-03-05 Thread via cfe-commits

Author: A. Jiang
Date: 2025-03-05T18:25:06+08:00
New Revision: d1bcac06c7c11699e7931bb7315a1bb9b9784179

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

LOG: [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode (#129814)

Per P2493R0 and SD6, `__cpp_constexpr` of value `202002L` indicates that
P1330R0 "Changing the active member of a union inside constexpr" is
implemented, which is true for Clang 9 and later.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Lexer/cxx-features.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 38111db3e6919..35efa2ca4aa93 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,9 @@ Resolutions to C++ Defect Reports
 - Implemented `CWG2918 Consideration of constraints for address of overloaded `
   `function `_
 
+- Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 
mode as indicated in
+  `P2493R0 `_.
+
 C Language Changes
 --
 

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e1dc728558def..1a816cb6269d4 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -664,7 +664,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_lambdas", "200907L");
 Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus26   ? "202406L"
: LangOpts.CPlusPlus23 ? "202211L"
-   : LangOpts.CPlusPlus20 ? "201907L"
+   : LangOpts.CPlusPlus20 ? "202002L"
: LangOpts.CPlusPlus17 ? "201603L"
: LangOpts.CPlusPlus14 ? "201304L"
   : "200704");

diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index ff9a1a1210c44..8c1867d5c7365 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -314,7 +314,7 @@
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202406L)
+#if check(constexpr, 0, 200704, 201304, 201603, 202002, 202211, 202406L)
 #error "wrong value for __cpp_constexpr"
 #endif
 



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


[clang] [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode (PR #129814)

2025-03-05 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja closed 
https://github.com/llvm/llvm-project/pull/129814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][bytecode][NFC] Fix getting references to local function ptrs (PR #129852)

2025-03-05 Thread Timm Baeder via cfe-commits

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


[clang] 3fed3bf - [clang][bytecode][NFC] Fix getting references to local function ptrs (#129852)

2025-03-05 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-05T11:26:43+01:00
New Revision: 3fed3bfef2f620d9423733298ee1e99d6c7d3068

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

LOG: [clang][bytecode][NFC] Fix getting references to local function ptrs 
(#129852)

This is the same thing we do for globals and parameters.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 394e39e99a106..281fb7e14a57d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6325,7 +6325,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
   if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
 if (IsReference)
-  return this->emitGetLocal(PT_Ptr, Offset, E);
+  return this->emitGetLocal(classifyPrim(E), Offset, E);
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
 if (IsReference) {



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


[clang] [Clang] use parameter location for abbreviated function templates (PR #129139)

2025-03-05 Thread Oleksandr T. via cfe-commits


@@ -7991,8 +7991,12 @@ Sema::CheckTemplateDeclScope(Scope *S, 
TemplateParameterList *TemplateParams) {
   //   have C linkage.
   DeclContext *Ctx = S->getEntity();
   if (Ctx && Ctx->isExternCContext()) {
-Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
-<< TemplateParams->getSourceRange();
+SourceRange Range =
+TemplateParams->getTemplateLoc().isInvalid() && TemplateParams->size()
+? TemplateParams->getParam(TemplateParams->size() - 1)
+  ->getSourceRange()

a-tarasyuk wrote:

@cor3ntin thanks for the review. The decision to retrieve the last parameter 
was driven by the following comment for this helper 
https://github.com/llvm/llvm-project/blob/36cd60144b15dd35c8e0081100421c3511242e02/clang/include/clang/AST/DeclTemplate.h#L1091

Or better to use first param? 



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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits


@@ -0,0 +1,362 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=128 -aarch64-sve-vector-bits-max=128 < %s | 
FileCheck %s --check-prefix=CHECK-128
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=256 -aarch64-sve-vector-bits-max=256 < %s | 
FileCheck %s --check-prefix=CHECK-256
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=512 -aarch64-sve-vector-bits-max=512 < %s | 
FileCheck %s --check-prefix=CHECK-512
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=1024 -aarch64-sve-vector-bits-max=1024 < %s | 
FileCheck %s --check-prefix=CHECK-1024
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve 
-aarch64-sve-vector-bits-min=2048 -aarch64-sve-vector-bits-max=2048 < %s | 
FileCheck %s --check-prefix=CHECK-2048
+
+define void @nxv16i8(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv16i8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.b
+; CHECK-NEXT:mov w8, #256 // =0x100
+; CHECK-NEXT:ld1b { z0.b }, p0/z, [x0, x8]
+; CHECK-NEXT:st1b { z0.b }, p0, [x1, x8]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv16i8:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv16i8:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv16i8:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv16i8:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv16i8:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i8, ptr %ldptr, i64 256
+  %stoff = getelementptr inbounds nuw i8, ptr %stptr, i64 256
+  %x = load , ptr %ldoff, align 1
+  store  %x, ptr %stoff, align 1
+  ret void
+}
+
+define void @nxv8i16(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv8i16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.h
+; CHECK-NEXT:mov x8, #128 // =0x80
+; CHECK-NEXT:ld1h { z0.h }, p0/z, [x0, x8, lsl #1]
+; CHECK-NEXT:st1h { z0.h }, p0, [x1, x8, lsl #1]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv8i16:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv8i16:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv8i16:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv8i16:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv8i16:
+; CHECK-2048:   // %bb.0:
+; CHECK-2048-NEXT:ldr z0, [x0, #1, mul vl]
+; CHECK-2048-NEXT:str z0, [x1, #1, mul vl]
+; CHECK-2048-NEXT:ret
+  %ldoff = getelementptr inbounds nuw i16, ptr %ldptr, i64 128
+  %stoff = getelementptr inbounds nuw i16, ptr %stptr, i64 128
+  %x = load , ptr %ldoff, align 2
+  store  %x, ptr %stoff, align 2
+  ret void
+}
+
+define void @nxv4i32(ptr %ldptr, ptr %stptr) {
+; CHECK-LABEL: nxv4i32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s
+; CHECK-NEXT:mov x8, #64 // =0x40
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0, x8, lsl #2]
+; CHECK-NEXT:st1w { z0.s }, p0, [x1, x8, lsl #2]
+; CHECK-NEXT:ret
+;
+; CHECK-128-LABEL: nxv4i32:
+; CHECK-128:   // %bb.0:
+; CHECK-128-NEXT:ldr z0, [x0, #16, mul vl]
+; CHECK-128-NEXT:str z0, [x1, #16, mul vl]
+; CHECK-128-NEXT:ret
+;
+; CHECK-256-LABEL: nxv4i32:
+; CHECK-256:   // %bb.0:
+; CHECK-256-NEXT:ldr z0, [x0, #8, mul vl]
+; CHECK-256-NEXT:str z0, [x1, #8, mul vl]
+; CHECK-256-NEXT:ret
+;
+; CHECK-512-LABEL: nxv4i32:
+; CHECK-512:   // %bb.0:
+; CHECK-512-NEXT:ldr z0, [x0, #4, mul vl]
+; CHECK-512-NEXT:str z0, [x1, #4, mul vl]
+; CHECK-512-NEXT:ret
+;
+; CHECK-1024-LABEL: nxv4i32:
+; CHECK-1024:   // %bb.0:
+; CHECK-1024-NEXT:ldr z0, [x0, #2, mul vl]
+; CHECK-1024-NEXT:str z0, [x1, #2, mul vl]
+; CHECK-1024-NEXT:ret
+;
+; CHECK-2048-LABEL: nxv4i32:
+; CHECK-2048:   // %bb.0:
+; CHECK-

[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits

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


[clang] [clang][bytecode] Check dtor instance pointers for active-ness (PR #128732)

2025-03-05 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang] Support --sysroot= for ${arch}-windows-msvc targets (PR #96417)

2025-03-05 Thread via cfe-commits

GoodenoughPhysicsLab wrote:

This patch is extremely useful, I want it can be merged.

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


[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2025-03-05 Thread Gábor Horváth via cfe-commits

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


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


[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #129234)

2025-03-05 Thread Balazs Benics via cfe-commits

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

>From 67d6420eb64949b9639385a8a2f647db0d05d078 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sat, 1 Feb 2025 10:03:27 +0100
Subject: [PATCH 1/4] Reapply "[analyzer] Handle [[assume(cond)]] as
 __builtin_assume(cond) (#116462)"

This reverts commit 2b9abf0db2d106c7208b4372e662ef5df869e6f1.
---
 clang/include/clang/AST/AttrIterator.h| 12 
 .../Core/PathSensitive/ExprEngine.h   |  4 ++
 clang/lib/Analysis/CFG.cpp| 72 +--
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  8 ++-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  7 +-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 18 +
 .../test/Analysis/cxx23-assume-attribute.cpp  | 58 +++
 clang/test/Analysis/out-of-bounds-new.cpp | 60 +++-
 8 files changed, 214 insertions(+), 25 deletions(-)
 create mode 100644 clang/test/Analysis/cxx23-assume-attribute.cpp

diff --git a/clang/include/clang/AST/AttrIterator.h 
b/clang/include/clang/AST/AttrIterator.h
index 7e2bb0381d4c8..2f39c144dc160 100644
--- a/clang/include/clang/AST/AttrIterator.h
+++ b/clang/include/clang/AST/AttrIterator.h
@@ -16,6 +16,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/ADL.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
@@ -124,6 +125,17 @@ inline auto *getSpecificAttr(const Container &container) {
   return It != specific_attr_end(container) ? *It : nullptr;
 }
 
+template 
+inline auto getSpecificAttrs(const Container &container) {
+  using ValueTy = llvm::detail::ValueOfRange;
+  using ValuePointeeTy = std::remove_pointer_t;
+  using IterTy = std::conditional_t,
+const SpecificAttr, SpecificAttr>;
+  auto Begin = specific_attr_begin(container);
+  auto End = specific_attr_end(container);
+  return llvm::make_range(Begin, End);
+}
+
 } // namespace clang
 
 #endif // LLVM_CLANG_AST_ATTRITERATOR_H
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index 9fd07ce47175c..804fc74b009df 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -498,6 +498,10 @@ class ExprEngine {
   void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
  ExplodedNodeSet &Dst);
 
+  /// VisitAttributedStmt - Transfer function logic for AttributedStmt
+  void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred,
+   ExplodedNodeSet &Dst);
+
   /// VisitLogicalExpr - Transfer function logic for '&&', '||'
   void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
 ExplodedNodeSet &Dst);
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 3e144395cffc6..13e86be496db8 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -433,7 +433,7 @@ class reverse_children {
   ArrayRef children;
 
 public:
-  reverse_children(Stmt *S);
+  reverse_children(Stmt *S, ASTContext &Ctx);
 
   using iterator = ArrayRef::reverse_iterator;
 
@@ -443,28 +443,47 @@ class reverse_children {
 
 } // namespace
 
-reverse_children::reverse_children(Stmt *S) {
-  if (CallExpr *CE = dyn_cast(S)) {
-children = CE->getRawSubExprs();
+reverse_children::reverse_children(Stmt *S, ASTContext &Ctx) {
+  switch (S->getStmtClass()) {
+  case Stmt::CallExprClass: {
+children = cast(S)->getRawSubExprs();
 return;
   }
-  switch (S->getStmtClass()) {
-// Note: Fill in this switch with more cases we want to optimize.
-case Stmt::InitListExprClass: {
-  InitListExpr *IE = cast(S);
-  children = llvm::ArrayRef(reinterpret_cast(IE->getInits()),
-IE->getNumInits());
-  return;
-}
-default:
-  break;
+
+  // Note: Fill in this switch with more cases we want to optimize.
+  case Stmt::InitListExprClass: {
+InitListExpr *IE = cast(S);
+children = llvm::ArrayRef(reinterpret_cast(IE->getInits()),
+  IE->getNumInits());
+return;
   }
+  case Stmt::AttributedStmtClass: {
+auto *AS = cast(S);
 
-  // Default case for all other statements.
-  llvm::append_range(childrenBuf, S->children());
+// for an attributed stmt, the "children()" returns only the NullStmt
+// (;) but semantically the "children" are supposed to be the
+// expressions _within_ i.e. the two square brackets i.e. [[ HERE ]]
+// so we add the subexpressions first, _then_ add the "children"
 
-  // This needs to be done *after* childrenBuf has been populated.
-  children = childrenBuf;
+for (const auto *Attr : AS->getAttrs()) {
+  if (const auto *AssumeAttr = dyn_cast(Attr)) {
+Expr *AssumeExpr = AssumeAttr->

[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #129234)

2025-03-05 Thread Balazs Benics via cfe-commits


@@ -443,21 +443,44 @@ class reverse_children {
 
 } // namespace
 
-reverse_children::reverse_children(Stmt *S) {
-  if (CallExpr *CE = dyn_cast(S)) {
-children = CE->getRawSubExprs();
+reverse_children::reverse_children(Stmt *S, ASTContext &Ctx) {
+  switch (S->getStmtClass()) {
+  case Stmt::CallExprClass: {

steakhal wrote:

Thanks, fixed.

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Ricardo Jesus via cfe-commits


@@ -7380,17 +7380,31 @@ bool 
AArch64DAGToDAGISel::SelectAddrModeIndexedSVE(SDNode *Root, SDValue N,
 return false;
 
   SDValue VScale = N.getOperand(1);
-  if (VScale.getOpcode() != ISD::VSCALE)
+  std::optional MulImm;
+  if (VScale.getOpcode() == ISD::VSCALE) {
+MulImm = cast(VScale.getOperand(0))->getSExtValue();
+  } else if (auto C = dyn_cast(VScale)) {
+int64_t ByteOffset = C->getSExtValue();
+constexpr auto SVEBitsPerBlock = AArch64::SVEBitsPerBlock;
+auto MinVScale = Subtarget->getMinSVEVectorSizeInBits() / SVEBitsPerBlock;
+auto MaxVScale = Subtarget->getMaxSVEVectorSizeInBits() / SVEBitsPerBlock;
+
+if (!MaxVScale || MinVScale != MaxVScale || ByteOffset % MaxVScale != 0)

rj-jesus wrote:

Thanks, that's a good idea. Would you prefer `optional`, or should we follow 
the logic that `getMinSVEVectorSizeInBits` and `getMaxSVEVectorSizeInBits` 
already use and return 0 when nothing is known about the limit?

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-05 Thread Maurice Heumann via cfe-commits

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


[clang] [Clang][diagnostics] Improve the diagnostics for chained comparisons (PR #129285)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -7157,7 +7157,7 @@ def note_precedence_conditional_first : Note<
   "place parentheses around the '?:' expression to evaluate it first">;
 
 def warn_consecutive_comparison : Warning<
-  "comparisons like 'X<=Y<=Z' don't have their mathematical meaning">,
+  "comparisons like 'X %0 Y %1 Z' don't have their mathematical meaning">,

AaronBallman wrote:

```suggestion
  "chained comparison 'X %0 Y %1 Z' does not behave the same as a mathematical 
expression">,
```

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Paul Walker via cfe-commits


@@ -7380,12 +7380,26 @@ bool 
AArch64DAGToDAGISel::SelectAddrModeIndexedSVE(SDNode *Root, SDValue N,
 return false;
 
   SDValue VScale = N.getOperand(1);
-  if (VScale.getOpcode() != ISD::VSCALE)
+  int64_t MulImm = std::numeric_limits::max();
+  if (VScale.getOpcode() == ISD::VSCALE) {
+MulImm = cast(VScale.getOperand(0))->getSExtValue();
+  } else if (auto C = dyn_cast(VScale)) {
+int64_t ByteOffset = C->getSExtValue();
+const auto KnownVScale =
+Subtarget->getSVEVectorSizeInBits() / AArch64::SVEBitsPerBlock;
+
+if (!KnownVScale || ByteOffset % KnownVScale != 0)
+  return false;
+
+MulImm = ByteOffset / KnownVScale;
+  } else
 return false;
 
+  assert(MulImm != std::numeric_limits::max() &&
+ "Uninitialized MulImm.");
+

paulwalker-arm wrote:

This is not strictly true given you are initialising `MulImm` and whilst 
unlikely there's nothing stopping `ISD::VSCALE`'s operand from being 
`std::numeric_limits::max()`.

Given the following code will bail if `MulImm` is not changed from its initial 
value, you could just remove the assert?

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Paul Walker via cfe-commits


@@ -405,6 +405,17 @@ class AArch64Subtarget final : public 
AArch64GenSubtargetInfo {
 return MinSVEVectorSizeInBits;
   }
 
+  // Return the known bit length of SVE data registers. A value of 0 means the
+  // length is unkown beyond what's implied by the architecture.
+  unsigned getSVEVectorSizeInBits() const {
+assert(isSVEorStreamingSVEAvailable() &&
+   "Tried to get SVE vector length without SVE support!");
+if (MaxSVEVectorSizeInBits &&
+MinSVEVectorSizeInBits == MaxSVEVectorSizeInBits)

paulwalker-arm wrote:

This can be just `MinSVEVectorSizeInBits == MaxSVEVectorSizeInBits` given that 
returning zero when both are zero is valid?

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Paul Walker via cfe-commits

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


[clang] [clang] C++20 Modules: document how to perform automated reductions (PR #124997)

2025-03-05 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@cor3ntin do you sustain an objection due to the lack of a full 
beginner-friendly test case reduction tutorial?

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


[clang] [clang] Implement instantiation context note for checking template parameters (PR #126088)

2025-03-05 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Ping. I'll merge tomorrow if there are no further objections.

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


[clang] [Sema] Instantiate destructors for initialized members (PR #128866)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -5283,6 +5283,102 @@ Sema::SetDelegatingInitializer(CXXConstructorDecl 
*Constructor,
   return false;
 }
 
+static void MarkFieldDestructorReferenced(Sema &S, SourceLocation Location,
+  FieldDecl *Field) {
+  if (Field->isInvalidDecl())
+return;
+
+  // Don't destroy incomplete or zero-length arrays.
+  if (isIncompleteOrZeroLengthArrayType(S.Context, Field->getType()))
+return;
+
+  QualType FieldType = S.Context.getBaseElementType(Field->getType());
+
+  const RecordType *RT = FieldType->getAs();

AaronBallman wrote:

```suggestion
  const auto *RT = FieldType->getAs();
```

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


[clang] [Clang][diagnostics] Improve the diagnostics for chained comparisons (PR #129285)

2025-03-05 Thread Aaron Ballman via cfe-commits

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


[clang] [llvm] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Please fix MLIR build failure.


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


[clang] [clang] C++20 Modules: document how to perform automated reductions (PR #124997)

2025-03-05 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> @cor3ntin do you sustain an objection due to the lack of a full 
> beginner-friendly test case reduction tutorial?

I think this PR is improvement over status quo, but I see where Corentin is 
coming from with his objection. Maybe the middle ground would be to explicitly 
acknowledge somewhere that full tutorial is yet to be written, so that less 
people are confused whether such tutorial exists elsewhere in our documentation?

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


[clang] [flang] [llvm] [mlir] [mlir][OpenMP] fix crash outlining infinite loop (PR #129872)

2025-03-05 Thread Tom Eccles via cfe-commits

tblah wrote:

> The comment mentions the additional edges might come through cancellations, 
> but what test actually tests cancellation points?

Thanks for taking a look. Now I have added clang lit tests (including for 
cancel) we can see that there are no changes beyond block names and removing a 
redundant block. The commit description you mentioned says it is trying to 
avoid returning values from the outlined function, which is not something which 
has been seen in any of the lit tests.

Do you know of any clang test suites that are known to work for openmpirbuilder 
that I could try with? 

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


[clang] [flang] [llvm] [mlir] [mlir][OpenMP] fix crash outlining infinite loop (PR #129872)

2025-03-05 Thread Tom Eccles via cfe-commits

https://github.com/tblah updated 
https://github.com/llvm/llvm-project/pull/129872

>From 3055b89b8ab937bfd4ba70d87e1733b05156d0ac Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Tue, 4 Mar 2025 17:19:53 +
Subject: [PATCH 1/2] [mlir][OpenMP] fix crash outlining infinite loop

Previously an extra block was created by splitting the previous exit
block. This produced incorrect results when the outlined region
statically never terminated because then there wouldn't be a valid exit
block for the outlined region, this caused this newly added block to
have an incoming edge from outside of the outlining region, which caused
outlining to fail.

So far as I can tell this extra block no longer serves any purpose. The
comment says it is supposed to collate multiple control flow edges into
one place, but the code as it is now does not achieve this. In fact, as
can be seen from the changes to lit tests, this block was not actually
outlined in the end. This is because there are actually two code
extractors: one in the callback for creating a parallel op which is used
to find what the input/output variables are (which does have this block
added to it), and another one which actually does the outlining (which
this block was not added to).

Tested with the gfortran and fujitsu test suites.
---
 .../parallel-private-reduction-worstcase.f90  |  2 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp |  8 
 mlir/test/Target/LLVMIR/openmp-llvm.mlir  |  4 +-
 .../LLVMIR/openmp-outline-infinite-loop.mlir  | 44 +++
 .../openmp-parallel-reduction-multiblock.mlir |  6 +--
 .../openmp-reduction-array-sections.mlir  |  2 +-
 .../LLVMIR/openmp-reduction-init-arg.mlir |  6 +--
 .../LLVMIR/openmp-reduction-sections.mlir |  2 +-
 8 files changed, 52 insertions(+), 22 deletions(-)
 create mode 100644 mlir/test/Target/LLVMIR/openmp-outline-infinite-loop.mlir

diff --git 
a/flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90 
b/flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90
index 7e735b6499504..cf77c46346b7f 100644
--- a/flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90
+++ b/flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90
@@ -219,5 +219,5 @@ subroutine worst_case(a, b, c, d)
 ![var extent was non-zero: malloc a private array]
 ! CHECK: br label %omp.private.init5
 
-! CHECK:   omp.par.outlined.exit.exitStub:   ; preds = 
%omp.region.cont52
+! CHECK:   omp.par.exit.exitStub:   ; preds = 
%omp.region.cont52
 ! CHECK-NEXT:ret void
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index e34e93442ff85..0295319ec1e9d 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1602,14 +1602,6 @@ OpenMPIRBuilder::InsertPointOrErrorTy 
OpenMPIRBuilder::createParallel(
   SmallVector Blocks;
   OI.collectBlocks(ParallelRegionBlockSet, Blocks);
 
-  // Ensure a single exit node for the outlined region by creating one.
-  // We might have multiple incoming edges to the exit now due to 
finalizations,
-  // e.g., cancel calls that cause the control flow to leave the region.
-  BasicBlock *PRegOutlinedExitBB = PRegExitBB;
-  PRegExitBB = SplitBlock(PRegExitBB, &*PRegExitBB->getFirstInsertionPt());
-  PRegOutlinedExitBB->setName("omp.par.outlined.exit");
-  Blocks.push_back(PRegOutlinedExitBB);
-
   CodeExtractorAnalysisCache CEAC(*OuterFn);
   CodeExtractor Extractor(Blocks, /* DominatorTree */ nullptr,
   /* AggregateArgs */ false,
diff --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir 
b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
index f25ba4aa3c8dc..e4114d491fc85 100644
--- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -162,14 +162,12 @@ llvm.func @test_omp_parallel_if_1(%arg0: i32) -> () {
 // CHECK: %[[I32_IF_COND_VAR_1:.*]] = sext i1 %[[IF_COND_VAR_1]] to i32
 // CHECK: call void @__kmpc_fork_call_if(ptr @[[SI_VAR_IF_1]], i32 0, ptr 
@[[OMP_OUTLINED_FN_IF_1:.*]], i32 %[[I32_IF_COND_VAR_1]], ptr null)
 // CHECK: br label %[[OUTLINED_EXIT_IF_1:.*]]
-// CHECK: [[OUTLINED_EXIT_IF_1]]:
-// CHECK: br label %[[RETURN_BLOCK_IF_1:.*]]
   omp.parallel if(%1) {
 omp.barrier
 omp.terminator
   }
 
-// CHECK: [[RETURN_BLOCK_IF_1]]:
+// CHECK: [[OUTLINED_EXIT_IF_1]]:
 // CHECK: ret void
   llvm.return
 }
diff --git a/mlir/test/Target/LLVMIR/openmp-outline-infinite-loop.mlir 
b/mlir/test/Target/LLVMIR/openmp-outline-infinite-loop.mlir
new file mode 100644
index 0..faccfc678adfe
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/openmp-outline-infinite-loop.mlir
@@ -0,0 +1,44 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// Test that trying to outline an infinite loop doesn't lead to an assertion
+// failure.
+
+llvm.func @parallel_infinite_loop() -> () {
+  omp.parallel {
+

[clang] [AMDGPU][clang] provide device implementation for __builtin_logb and … (PR #129347)

2025-03-05 Thread via cfe-commits

choikwa wrote:

> > There were some stakeholders who are trying to compile cccl on AMDGPU and 
> > were looking for a solution in clang. If this short term fix isn't 
> > desirable, is there any alternative solutions to explore? I understand long 
> > term solution keeping it as libcall and having libm, but we may be some 
> > time away from achieving that.
> 
> For now these don't seem to hit any LLVM-IR intrinsics 
> https://godbolt.org/z/zasTefo53. So you should be able to link them with the 
> `libm.a` I already have from the [llvm 
> libc](https://libc.llvm.org/gpu/building.html) I already provide. That might 
> change in the future however since AFAIK we're going to have every math call 
> as an intrinsic eventually.
> 
> There's `libm.bc` in the install which you can cram into your compile via 
> your favorite method. Or just use `-Xoffload-linker -lm` if you're using the 
> new driver on HIP (I'll make it the default eventually). Alternatively just 
> make your own `libm.o` that contains the ROCm DL implementation and link that 
> in. And if absolutely none of that works, make a custom IR lowering pass.

After clang emits builtins as LibCall, it just appears as an external call, and 
it would be odd for LLVM to reserve and transform certain functions even if it 
aliases libc builtin function names as -fno-builtin exists and user could've 
defined their own. I appreciate the suggestions given here and can forward it 
to the stakeholders. Is there no desirable, acceptable solution in clang-side 
then?

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-03-05 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


apple-fcloutier wrote:

This is not intended. There is a test for a function with both a printf and 
scan format 
(https://github.com/swiftlang/llvm-project/blob/8909cd902bf9985185f59b612e478fc096e91308/clang/test/Sema/format-strings.c#L490),
 but it doesn't cover the implementation of such a function.

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


[clang] [HLSL] Fix resrouce wrapper declaration (PR #129100)

2025-03-05 Thread Steven Perron via cfe-commits

https://github.com/s-perron updated 
https://github.com/llvm/llvm-project/pull/129100

>From 1e794cd4b79235282795891f943f8f4609738d4f Mon Sep 17 00:00:00 2001
From: Steven Perron 
Date: Tue, 4 Feb 2025 11:47:42 -0500
Subject: [PATCH 1/6] [HLSL] Fix resrouce wrapper declaration

The resource wrapper should have internal linkage because it contains a
handle to the global resource, and it not the actual global.

Makeing this changed exposed that we were zeroinitializing the resouce,
which is a problem. The handle cannot be zeroinitialized. This is
changed to use poison instead.

Fixes https://github.com/llvm/llvm-project/issues/122767.
---
 clang/include/clang/AST/Type.h|  1 +
 clang/lib/AST/Type.cpp| 27 ++
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  5 ++
 clang/lib/CodeGen/CGHLSLRuntime.h |  2 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  6 ++-
 clang/lib/Sema/SemaHLSL.cpp   |  7 +++
 .../ByteAddressBuffers-constructors.hlsl  | 24 -
 .../builtins/RWBuffer-constructor-opt.hlsl| 14 ++
 .../builtins/RWBuffer-constructor.hlsl| 10 ++--
 .../StructuredBuffers-constructors.hlsl   | 50 +--
 clang/test/CodeGenHLSL/resource-bindings.hlsl | 32 ++--
 11 files changed, 108 insertions(+), 70 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 79cf237431450..5bfc78da7fa13 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2661,6 +2661,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type
   bool isHLSLAttributedResourceType() const;
+  bool isHLSLResourceWrapper() const;
   bool isHLSLIntangibleType()
   const; // Any HLSL intangible type (builtin, array, class)
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 1ddc2d1f492af..992ce8b4b4795 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -5114,6 +5114,33 @@ bool Type::hasSizedVLAType() const {
   return false;
 }
 
+bool Type::isHLSLResourceWrapper() const {
+  const Type *Ty = getUnqualifiedDesugaredType();
+
+  // check if it's a builtin type first
+  if (Ty->isBuiltinType())
+return Ty->isHLSLBuiltinIntangibleType();
+
+  // unwrap arrays
+  while (isa(Ty))
+Ty = Ty->getArrayElementTypeNoTypeQual();
+
+  const RecordType *RT =
+  dyn_cast(Ty->getUnqualifiedDesugaredType());
+  if (!RT)
+return false;
+
+  CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
+  assert(RD != nullptr &&
+  "all HLSL structs and classes should be CXXRecordDecl");
+  assert(RD->isCompleteDefinition() && "expecting complete type");
+  if (RD->field_empty()) {
+return false;
+  }
+  const FieldDecl *FirstField = *RD->field_begin();
+  return FirstField->getType()->isHLSLAttributedResourceType();
+}
+
 bool Type::isHLSLIntangibleType() const {
   const Type *Ty = getUnqualifiedDesugaredType();
 
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ed6d2036cb984..77d42e301f1f8 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -711,3 +711,8 @@ void 
CGHLSLRuntime::emitInitListOpaqueValues(CodeGenFunction &CGF,
 }
   }
 }
+
+// Returns true if the type is an HLSL resource class
+bool CGHLSLRuntime::isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a9da42324a038..31811cc390cde 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -134,6 +134,8 @@ class CGHLSLRuntime {
 BufferResBinding(HLSLResourceBindingAttr *Attr);
   };
 
+  static bool isResourceRecordType(const clang::Type *Ty);
+
 protected:
   CodeGenModule &CGM;
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cec8f1233b663..78b62d8ac4b01 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5595,7 +5595,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
   if (D->getType()->isReferenceType())
 T = D->getType();
 
-  if (getLangOpts().CPlusPlus) {
+  if (getLangOpts().HLSL &&
+  getHLSLRuntime().isResourceRecordType(D->getType().getTypePtr())) {
+Init = llvm::PoisonValue::get(getTypes().ConvertType(ASTTy));
+NeedsGlobalCtor = true;
+  } else if (getLangOpts().CPlusPlus) {
 Init = EmitNullConstant(T);
 if (!IsDefinitionAvailableExternally)
   NeedsGlobalCtor = true;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index bfe84b16218b7..5fedeb2046b4d 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLS

[clang] [analyzer] Add more C++ list initializer tests and regroup (PR #129182)

2025-03-05 Thread Michael Flanders via cfe-commits

https://github.com/Flandini updated 
https://github.com/llvm/llvm-project/pull/129182

>From 6db1434c459854ca6ea631fc33e0f773323e85d0 Mon Sep 17 00:00:00 2001
From: Michael Flanders 
Date: Sun, 23 Feb 2025 13:09:39 -0600
Subject: [PATCH 1/2] [analyzer] Add more C++ list initializer tests and
 regroup

---
 clang/test/Analysis/initialization.cpp  |  154 ---
 clang/test/Analysis/initializer.cpp |  297 -
 clang/test/Analysis/list-initialization.cpp | 1225 +++
 3 files changed, 1225 insertions(+), 451 deletions(-)
 create mode 100644 clang/test/Analysis/list-initialization.cpp

diff --git a/clang/test/Analysis/initialization.cpp 
b/clang/test/Analysis/initialization.cpp
index e5e19daad0895..29e0363f9b6bb 100644
--- a/clang/test/Analysis/initialization.cpp
+++ b/clang/test/Analysis/initialization.cpp
@@ -4,105 +4,6 @@ template 
 void clang_analyzer_dump(T x);
 void clang_analyzer_eval(int);
 
-struct S {
-  int a = 3;
-};
-S const sarr[2] = {};
-void definit() {
-  int i = 1;
-  // FIXME: Should recognize that it is 3.
-  clang_analyzer_eval(sarr[i].a); // expected-warning{{UNKNOWN}}
-}
-
-int const glob_arr1[3] = {};
-void glob_array_index1() {
-  clang_analyzer_eval(glob_arr1[0] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr1[1] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr1[2] == 0); // expected-warning{{TRUE}}
-}
-
-void glob_invalid_index1() {
-  const int *ptr = glob_arr1;
-  int idx = -42;
-  auto x = ptr[idx]; // expected-warning{{uninitialized}}
-}
-
-void glob_symbolic_index1(int idx) {
-  clang_analyzer_dump(glob_arr1[idx]); // expected-warning{{Unknown}}
-}
-
-int const glob_arr2[4] = {1, 2};
-void glob_ptr_index1() {
-  int const *ptr = glob_arr2;
-  clang_analyzer_eval(ptr[0] == 1); // expected-warning{{TRUE}}
-  clang_analyzer_eval(ptr[1] == 2); // expected-warning{{TRUE}}
-  clang_analyzer_eval(ptr[2] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNDEFINED}}
-}
-
-void glob_invalid_index2() {
-  const int *ptr = glob_arr2;
-  int idx = 42;
-  auto x = ptr[idx]; // expected-warning{{uninitialized}}
-}
-
-const float glob_arr3[] = {
-0., 0.0235, 0.0470, 0.0706, 0.0941, 0.1176};
-float no_warn_garbage_value() {
-  return glob_arr3[0]; // no-warning (not meaningful)
-}
-
-int const glob_arr4[4][2] = {};
-void glob_array_index2() {
-  clang_analyzer_eval(glob_arr4[0][0] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr4[1][0] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr4[1][1] == 0); // expected-warning{{TRUE}}
-}
-
-void glob_invalid_index3() {
-  int idx = -42;
-  auto x = glob_arr4[1][idx]; // expected-warning{{uninitialized}}
-}
-
-void glob_invalid_index4() {
-  const int *ptr = glob_arr4[1];
-  int idx = -42;
-  auto x = ptr[idx]; // expected-warning{{uninitialized}}
-}
-
-int const glob_arr5[4][2] = {{1}, 3, 4, 5};
-void glob_array_index3() {
-  clang_analyzer_eval(glob_arr5[0][0] == 1); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[0][1] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[1][0] == 3); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[1][1] == 4); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[2][0] == 5); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[2][1] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[3][0] == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr5[3][1] == 0); // expected-warning{{TRUE}}
-}
-
-void glob_ptr_index2() {
-  int const *ptr = glob_arr5[1];
-  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{TRUE}}
-  clang_analyzer_eval(ptr[1] == 4); // expected-warning{{TRUE}}
-  clang_analyzer_eval(ptr[2] == 5); // expected-warning{{UNDEFINED}}
-  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{UNDEFINED}}
-  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNDEFINED}}
-}
-
-void glob_invalid_index5() {
-  int idx = -42;
-  auto x = glob_arr5[1][idx]; // expected-warning{{uninitialized}}
-}
-
-void glob_invalid_index6() {
-  int const *ptr = &glob_arr5[1][0];
-  int idx = 42;
-  auto x = ptr[idx]; // expected-warning{{uninitialized}}
-}
-
 extern const int glob_arr_no_init[10];
 void glob_array_index4() {
   clang_analyzer_eval(glob_arr_no_init[2]); // expected-warning{{UNKNOWN}}
@@ -147,26 +48,6 @@ void glob_invalid_index8() {
   auto x = ptr[idx]; // expected-warning{{uninitialized}}
 }
 
-char const glob_arr7[5] = {"123"};
-void glob_array_index6() {
-  clang_analyzer_eval(glob_arr7[0] == '1');  // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr7[1] == '2');  // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr7[2] == '3');  // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr7[3] == '\0'); // expected-warning{{TRUE}}
-  clang_analyzer_eval(glob_arr7[4] == '\0'); // expected-warning{{TRUE

[clang] [clang] Fix UEFI Target info (PR #127290)

2025-03-05 Thread via cfe-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/127290

>From 3e6122744f355954edb6a5450ae4220ba39bc9c1 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Fri, 14 Feb 2025 16:53:33 -0800
Subject: [PATCH 1/3] [clang] Fix UEFI Target info

For X64 UEFI targets, making the integer size and va_list kind fixes.
---
 clang/include/clang/Basic/TargetOSMacros.def |  3 +++
 clang/lib/Basic/Targets/X86.h| 16 +++-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
index 58dce330f9c8f..f4f3276ad1c25 100644
--- a/clang/include/clang/Basic/TargetOSMacros.def
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
 TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
 TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
 
+// UEFI target.
+TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI())
+
 #undef TARGET_OS
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 205edcab9ccb3..20fcb25defba2 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -835,16 +835,22 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
 public:
   UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : UEFITargetInfo(Triple, Opts) {
+LongWidth = LongAlign = 32;
+DoubleAlign = LongLongAlign = 64;
+IntMaxType = SignedLongLong;
+Int64Type = SignedLongLong;
+SizeType = UnsignedLongLong;
+PtrDiffType = SignedLongLong;
+IntPtrType = SignedLongLong;
+LongDoubleWidth = LongDoubleAlign = 64;
+LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+WCharType = UnsignedShort;
+WIntType = UnsignedShort;
 this->TheCXXABI.set(TargetCXXABI::Microsoft);
-this->MaxTLSAlign = 8192u * this->getCharWidth();
 this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
   "i64:64-i128:128-f80:128-n8:16:32:64-S128");
   }
 
-  BuiltinVaListKind getBuiltinVaListKind() const override {
-return TargetInfo::CharPtrBuiltinVaList;
-  }
-
   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
 switch (CC) {
 case CC_C:

>From fa23204cb0eb6826f8866e497ff4d6ed96dbb8df Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Wed, 26 Feb 2025 09:59:47 -0800
Subject: [PATCH 2/3] More cleanups. Add test.

---
 clang/lib/Basic/Targets/X86.h  | 10 --
 clang/test/Preprocessor/init.c |  1 +
 2 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 20fcb25defba2..be07ae05f326c 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -851,16 +851,6 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
   "i64:64-i128:128-f80:128-n8:16:32:64-S128");
   }
 
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
-switch (CC) {
-case CC_C:
-case CC_Win64:
-  return CCCR_OK;
-default:
-  return CCCR_Warning;
-}
-  }
-
   TargetInfo::CallingConvKind
   getCallingConvKind(bool ClangABICompat4) const override {
 return CCK_MicrosoftWin64;
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 1ac325d444662..4c8d519c2b664 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2835,6 +2835,7 @@
 // RISCV64-LINUX: #define unix 1
 
 // RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck 
-match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck 
-match-full-lines -check-prefix UEFI %s
 
 // UEFI: #define __UEFI__ 1
 

>From 6305ac501a8b862486de7ea551ff77ff49d91dac Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Wed, 5 Mar 2025 18:14:04 +
Subject: [PATCH 3/3] Include all allowed callingconventions in
 checkCallingConvention

---
 clang/lib/Basic/Targets/X86.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index be07ae05f326c..58753e0c4d904 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -851,6 +851,30 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
   "i64:64-i128:128-f80:128-n8:16:32:64-S128");
   }
 
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_X86StdCall:
+case CC_X86ThisCall:
+case CC_X86FastCall:
+  return CCCR_Ignore;
+case CC_C:
+case CC_X86VectorCall:
+case CC_IntelOclBicc:
+case CC_PreserveMost:
+case CC_PreserveAll:
+case CC_PreserveNone:
+case CC_X86_64SysV:
+case CC_Swift:
+case CC_SwiftAsync:
+case CC_X86RegCall:
+case CC_OpenCLKernel:
+case CC_Win64:
+  re

[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -7141,6 +7141,9 @@ def warn_shift_result_sets_sign_bit : Warning<
   "signed shift result (%0) sets the sign bit of the shift expression's "
   "type (%1) and becomes negative">,
   InGroup>, DefaultIgnore;
+def warn_shift_bool : Warning<
+  "right shifting a `bool` implicitly converts it to 'int'">,

AaronBallman wrote:

```suggestion
  "right shifting a 'bool' implicitly converts it to 'int'">,
```

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


[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -11247,6 +11247,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   if (S.getLangOpts().OpenCL)
 return;
 
+  if (Opc == BO_Shr &&
+  LHS.get()->IgnoreParenImpCasts()->getType()->isBooleanType()) {
+S.Diag(Loc, diag::warn_shift_bool) << LHS.get()->getSourceRange();
+return;

AaronBallman wrote:

I don't think we want to return here, don't we want the rest of the checking? 
e.g.,

`true >> -1` should get both the shift bool warning and the negative shift 
warning?

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


[clang] [Clang][counted_by] Add support for 'counted_by' on struct pointers (PR #127116)

2025-03-05 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/127116

>From b5b9b158e7e379f2d430584e3ccf519677bf27a3 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 10 Jan 2025 17:13:30 -0800
Subject: [PATCH 1/5] [Clang][counted_by] Add support for 'counted_by' on
 struct pointers

The 'counted_by' attribute is now available for structs. It generates
code for sanity checks as well as __builtin_dynamic_object_size()
calculations. For example:

  struct annotated_ptr {
int count;
char *buf __counted_by(count);
  };

'counted_by' cannot be applied to a pointer to an incomplete type. So
this is invalid:

  struct foo;
  struct annotated_ptr {
int count;
struct foo *buf __counted_by(count); /* invalid */
  };

The 'count' field member may occur after the pointer. If it does, use
the '-fexperimental-late-parse-attributes' flag (which will hopefully be
made the default in future Clang versions).

Signed-off-by: Bill Wendling 
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 259 ++
 clang/lib/CodeGen/CGExpr.cpp  | 130 ++---
 clang/lib/CodeGen/CodeGenFunction.h   |  19 +-
 .../CodeGen/attr-counted-by-for-pointers.c| 216 +++
 4 files changed, 519 insertions(+), 105 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by-for-pointers.c

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 361e4c4bf2e2e..f7ff244a519d0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1061,7 +1061,7 @@ class StructFieldAccess
   bool AddrOfSeen = false;
 
 public:
-  const ArraySubscriptExpr *ASE = nullptr;
+  const Expr *ArrayIndex = nullptr;
 
   const Expr *VisitMemberExpr(const MemberExpr *E) {
 if (AddrOfSeen && E->getType()->isArrayType())
@@ -1071,12 +1071,12 @@ class StructFieldAccess
   }
 
   const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
-if (ASE)
+if (ArrayIndex)
   // We don't support multiple subscripts.
   return nullptr;
 
 AddrOfSeen = false; // '&ptr->array[idx]' is okay.
-ASE = E;
+ArrayIndex = E->getIdx();
 return Visit(E->getBase());
   }
   const Expr *VisitCastExpr(const CastExpr *E) {
@@ -1168,12 +1168,10 @@ GetFieldOffset(ASTContext &Ctx, const RecordDecl *RD, 
const FieldDecl *FD) {
   return std::nullopt;
 }
 
-llvm::Value *
-CodeGenFunction::emitCountedByMemberSize(const Expr *E, llvm::Value *EmittedE,
- unsigned Type,
- llvm::IntegerType *ResType) {
-  ASTContext &Ctx = getContext();
-
+llvm::Value *CodeGenFunction::emitCountedBySize(const Expr *E,
+llvm::Value *EmittedE,
+unsigned Type,
+llvm::IntegerType *ResType) {
   // Note: If the whole struct is specificed in the __bdos (i.e. Visitor
   // returns a DeclRefExpr). The calculation of the whole size of the structure
   // with a flexible array member can be done in two ways:
@@ -1192,14 +1190,161 @@ CodeGenFunction::emitCountedByMemberSize(const Expr 
*E, llvm::Value *EmittedE,
   // GCC does for consistency's sake.
 
   StructFieldAccess Visitor;
-  const MemberExpr *ME = dyn_cast_if_present(Visitor.Visit(E));
+  E = Visitor.Visit(E);
+  if (!E)
+return nullptr;
+
+  const Expr *Idx = Visitor.ArrayIndex;
+  if (Idx) {
+if (Idx->HasSideEffects(getContext()))
+  // We can't have side-effects.
+  return getDefaultBuiltinObjectSizeResult(Type, ResType);
+
+if (const auto *IL = dyn_cast(Idx)) {
+  int64_t Val = IL->getValue().getSExtValue();
+  if (Val < 0)
+return getDefaultBuiltinObjectSizeResult(Type, ResType);
+
+  // The index is 0, so we don't need to take it into account.
+  if (Val == 0)
+Idx = nullptr;
+}
+  }
+
+  if (const auto *ME = dyn_cast(E))
+// This is either a flexible array member or a pointer into a struct with a
+// flexible array member.
+return emitCountedByMemberSize(ME, Idx, EmittedE, Type, ResType);
+
+  if (const auto *ICE = dyn_cast(E);
+  ICE && ICE->getCastKind() == CK_LValueToRValue)
+// This may be a pointer.
+return emitCountedByPointerSize(ICE, Idx, EmittedE, Type, ResType);
+
+  return nullptr;
+}
+
+llvm::Value *CodeGenFunction::emitCountedByPointerSize(
+const ImplicitCastExpr *E, const Expr *Idx, llvm::Value *EmittedE,
+unsigned Type, llvm::IntegerType *ResType) {
+  assert(E->getCastKind() == CK_LValueToRValue &&
+ "must be an LValue to RValue cast");
+
+  const MemberExpr *ME = dyn_cast(E->getSubExpr());
   if (!ME)
 return nullptr;
 
+  const auto *ArrayBaseFD = dyn_cast(ME->getMemberDecl());
+  if (!ArrayBaseFD || !ArrayBaseFD->getType()->isPointerType() ||
+  !ArrayBaseFD->getType()->isCountAttributedType())
+return nullptr;
+
+  // Get the 'count' 

[clang] [Clang][ASTMatcher] Improve matching isDerivedFrom base in case of multi aliases exists (PR #126793)

2025-03-05 Thread Amr Hesham via cfe-commits

AmrDeveloper wrote:

@AaronBallman If releasenote is okey, i can merge now :D

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


[clang] [llvm] [RISCV] Xqccmp Code Generation (PR #128815)

2025-03-05 Thread Sam Elliott via cfe-commits

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


[clang] [HLSL] Fix resource wrapper declaration (PR #129100)

2025-03-05 Thread Steven Perron via cfe-commits

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


[clang] 6d4f8b1 - [HLSL] Fix resource wrapper declaration (#129100)

2025-03-05 Thread via cfe-commits

Author: Steven Perron
Date: 2025-03-05T14:02:39-05:00
New Revision: 6d4f8b1dbfd21811351bec205154992afddbc5ea

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

LOG: [HLSL] Fix resource wrapper declaration (#129100)

The resource wrapper should have internal linkage because it contains a
handle to the global resource, and it not the actual global.

Makeing this changed exposed that we were zeroinitializing the resouce,
which is a problem. The handle cannot be zeroinitialized. This is
changed to use poison instead.

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

-

Co-authored-by: Helena Kotas 

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaHLSL.cpp
clang/test/AST/HLSL/cbuffer.hlsl
clang/test/CodeGenHLSL/builtins/ByteAddressBuffers-constructors.hlsl
clang/test/CodeGenHLSL/builtins/RWBuffer-constructor-opt.hlsl
clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
clang/test/CodeGenHLSL/resource-bindings.hlsl

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 79cf237431450..ef59bd1621fb8 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2661,6 +2661,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type
   bool isHLSLAttributedResourceType() const;
+  bool isHLSLResourceRecord() const;
   bool isHLSLIntangibleType()
   const; // Any HLSL intangible type (builtin, array, class)
 

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 1ddc2d1f492af..2fd7f5800594a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -5114,6 +5114,10 @@ bool Type::hasSizedVLAType() const {
   return false;
 }
 
+bool Type::isHLSLResourceRecord() const {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(this) != nullptr;
+}
+
 bool Type::isHLSLIntangibleType() const {
   const Type *Ty = getUnqualifiedDesugaredType();
 

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ed6d2036cb984..dc34653e8f497 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -85,16 +85,11 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-// Returns true if the type is an HLSL resource class
-static bool isResourceRecordType(const clang::Type *Ty) {
-  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
-}
-
 // Returns true if the type is an HLSL resource class or an array of them
 static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
   while (const ConstantArrayType *CAT = dyn_cast(Ty))
 Ty = CAT->getArrayElementTypeNoTypeQual();
-  return isResourceRecordType(Ty);
+  return Ty->isHLSLResourceRecord();
 }
 
 // Emits constant global variables for buffer constants declarations
@@ -658,7 +653,7 @@ void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl 
*VD,
 // on?
 return;
 
-  if (!isResourceRecordType(VD->getType().getTypePtr()))
+  if (!VD->getType().getTypePtr()->isHLSLResourceRecord())
 // FIXME: Only simple declarations of resources are supported for now.
 // Arrays of resources or resources in user defined classes are
 // not implemented yet.

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cec8f1233b663..bca0a932b3495 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5595,7 +5595,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
   if (D->getType()->isReferenceType())
 T = D->getType();
 
-  if (getLangOpts().CPlusPlus) {
+  if (getLangOpts().HLSL &&
+  D->getType().getTypePtr()->isHLSLResourceRecord()) {
+Init = llvm::PoisonValue::get(getTypes().ConvertType(ASTTy));
+NeedsGlobalCtor = true;
+  } else if (getLangOpts().CPlusPlus) {
 Init = EmitNullConstant(T);
 if (!IsDefinitionAvailableExternally)
   NeedsGlobalCtor = true;

diff  --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index bfe84b16218b7..a4b0b5e4df63f 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -3065,6 +3065,16 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
 if (VD->getType()->isHLSLIntangibleType())
   collectResourceBindingsOnVarDecl(VD);
 
+const Type *VarType = V

[clang] [Clang] [Sema] Allow non-local/non-variable declarations in for loop (PR #129737)

2025-03-05 Thread via cfe-commits


@@ -10794,6 +10794,23 @@ def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
 def err_non_variable_decl_in_for : Error<
   "non-variable declaration in 'for' loop">;
+
+def ext_c23_non_local_variable_decl_in_for : Extension<

Sirraide wrote:

> You should remove the error diagnostics because they're no longer used.

Well, they *are* still used for C++ range-based for loops and for whatever an 
`ObjCForCollectionStmt` is.

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


[clang] [Clang] [Sema] Allow non-local/non-variable declarations in for loop (PR #129737)

2025-03-05 Thread via cfe-commits

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


[clang] [Clang][ASTMatcher] Improve matching isDerivedFrom base in case of multi aliases exists (PR #126793)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -361,6 +361,8 @@ Fixed Point Support in Clang
 AST Matchers
 
 
+- Ensure ``isDerivedFrom`` is matching the correct base in case of more than 
one aliases exists.

AaronBallman wrote:

```suggestion
- Ensure ``isDerivedFrom`` matches the correct base in case more than one alias 
exists.
```
Minor rewording

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


[clang] [Clang][ASTMatcher] Improve matching isDerivedFrom base in case of multi aliases exists (PR #126793)

2025-03-05 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang][ASTMatcher] Improve matching isDerivedFrom base in case of multi aliases exists (PR #126793)

2025-03-05 Thread Aaron Ballman via cfe-commits

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

Just a minor rewording, feel free to land once you've made the changes.

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


[clang] [Clang] [Sema] Allow non-local/non-variable declarations in for loop (PR #129737)

2025-03-05 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/129737

>From f0605e803b6e7748913515a4b0ffe34fa7eedc24 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 4 Mar 2025 17:36:30 +0100
Subject: [PATCH 1/2] [Clang] Allow non-local/non-variable declarations in for
 loop

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td| 17 ++
 clang/lib/Sema/SemaStmt.cpp   | 13 ++-
 clang/test/Sema/for.c | 22 +--
 4 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 97b8e32f03b57..cf205e7064aa8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,8 @@ Bug Fixes in This Version
   when it can affect template argument deduction (#GH122306).
 - Fix crash on code completion of function calls involving partial order of 
function templates
   (#GH125500).
+- Non-local variable and non-variable declarations in the first clause of a 
``for`` loop in C are no longer erroneously
+  considered an error in C23 mode and are allowed as an extension in earlier 
language modes.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d89648a8a2e83..c87ef62310cb9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10794,6 +10794,23 @@ def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
 def err_non_variable_decl_in_for : Error<
   "non-variable declaration in 'for' loop">;
+
+def ext_c23_non_local_variable_decl_in_for : Extension<
+  "declaration of non-local variable in 'for' loop is a C23 extension">,
+  InGroup;
+
+def warn_c17_non_local_variable_decl_in_for : Warning<
+  "declaration of non-local variable in 'for' loop is incompatible with C 
standards before C23">,
+  DefaultIgnore, InGroup;
+
+def ext_c23_non_variable_decl_in_for : Extension<
+  "non-variable declaration in 'for' loop is a C23 extension">,
+  InGroup;
+
+def warn_c17_non_variable_decl_in_for : Warning<
+  "non-variable declaration in 'for' loop is incompatible with C standards 
before C23">,
+  DefaultIgnore, InGroup;
+
 def err_toomany_element_decls : Error<
   "only one element declaration is allowed">;
 def err_selector_element_not_lvalue : Error<
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index d0b713f074c33..0a193b5299bcc 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2269,10 +2269,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   for (auto *DI : DS->decls()) {
 if (VarDecl *VD = dyn_cast(DI)) {
   VarDeclSeen = true;
-  if (VD->isLocalVarDecl() && !VD->hasLocalStorage()) {
-Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
-DI->setInvalidDecl();
-  }
+  if (VD->isLocalVarDecl() && !VD->hasLocalStorage())
+Diag(DI->getLocation(),
+ getLangOpts().C23
+ ? diag::warn_c17_non_local_variable_decl_in_for
+ : diag::ext_c23_non_local_variable_decl_in_for);
 } else if (!NonVarSeen) {
   // Keep track of the first non-variable declaration we saw so that
   // we can diagnose if we don't see any variable declarations. This
@@ -2284,7 +2285,9 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // Diagnose if we saw a non-variable declaration but no variable
   // declarations.
   if (NonVarSeen && !VarDeclSeen)
-Diag(NonVarSeen->getLocation(), diag::err_non_variable_decl_in_for);
+Diag(NonVarSeen->getLocation(),
+ getLangOpts().C23 ? diag::warn_c17_non_variable_decl_in_for
+   : diag::ext_c23_non_variable_decl_in_for);
 }
   }
 
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index d0c2f7f21a960..c21ef62247037 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -1,13 +1,21 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c11 -std=c11 -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 -Wpre-c23-compat %s
 
 // Check C99 6.8.5p3
 void b1 (void) { for (void (*f) (void);;); }
-void b2 (void) { for (void f (void);;); }   // expected-error {{non-variable 
declaration in 'for' loop}}
-void b3 (void) { for (static int f;;); }// expected-error {{declaration of 
non-local variable}}
-void b4 (void) { for (typedef int f;;); }   // expected-error {{non-variable 
declaration in 'for' loop}}
+void b2 (void) { for (void f (void);;); }   /* c11-warning {{non-variable 
declaration in 'for' loop is a C23 extension}}
+  

[clang] [Sema] Instantiate destructors for initialized members (PR #128866)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -5283,6 +5283,102 @@ Sema::SetDelegatingInitializer(CXXConstructorDecl 
*Constructor,
   return false;
 }
 
+static void MarkFieldDestructorReferenced(Sema &S, SourceLocation Location,
+  FieldDecl *Field) {
+  if (Field->isInvalidDecl())
+return;
+
+  // Don't destroy incomplete or zero-length arrays.
+  if (isIncompleteOrZeroLengthArrayType(S.Context, Field->getType()))
+return;
+
+  QualType FieldType = S.Context.getBaseElementType(Field->getType());
+
+  const RecordType *RT = FieldType->getAs();
+  if (!RT)
+return;
+
+  CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());

AaronBallman wrote:

```suggestion
  auto *FieldClassDecl = cast(RT->getDecl());
```

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-05 Thread Maurice Heumann via cfe-commits


@@ -5863,6 +5869,26 @@ 
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
  &DirectVirtualBases);
 }
 
+void Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
+  CXXRecordDecl *ClassDecl) {
+  // Ignore dependent contexts. Also ignore unions, since their members never
+  // have destructors implicitly called.
+  if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
+return;
+
+  // FIXME: all the access-control diagnostics are positioned on the
+  // field/base declaration.  That's probably good; that said, the
+  // user might reasonably want to know why the destructor is being
+  // emitted, and we currently don't say.

momo5502 wrote:

Hard for me to judge. It was added 15 years ago: 
https://github.com/llvm/llvm-project/commit/1064d7ef2992225ddbd792d1b54d144b809b5b39
I can remove it, if desired.

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-05 Thread Paul Walker via cfe-commits


@@ -405,6 +405,17 @@ class AArch64Subtarget final : public 
AArch64GenSubtargetInfo {
 return MinSVEVectorSizeInBits;
   }
 
+  // Return the known bit length of SVE data registers. A value of 0 means the
+  // length is unkown beyond what's implied by the architecture.
+  unsigned getSVEVectorSizeInBits() const {
+assert(isSVEorStreamingSVEAvailable() &&
+   "Tried to get SVE vector length without SVE support!");
+if (MaxSVEVectorSizeInBits &&
+MinSVEVectorSizeInBits == MaxSVEVectorSizeInBits)

paulwalker-arm wrote:

Not sure if this can happen outside of handwritten IR but otherwise it sounds 
like a reasonable suggestion to me.

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


[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)

2025-03-05 Thread Aaron Ballman via cfe-commits


@@ -8395,6 +8410,68 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, 
const ParsedAttr &Attr,
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle the __ptrauth qualifier.
+static void HandlePtrAuthQualifier(ASTContext &Ctx, QualType &T,
+   const ParsedAttr &Attr, Sema &S) {
+  if (Attr.getNumArgs() < 1 || Attr.getNumArgs() > 3) {
+S.Diag(Attr.getLoc(), diag::err_ptrauth_qualifier_bad_arg_count);
+Attr.setInvalid();
+return;
+  }

AaronBallman wrote:

I think this should be handled in parser rather than Sema; then it for sure 
won't result in oddities with SFINAE. CC @erichkeane @cor3ntin 

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


[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)

2025-03-05 Thread Oleksandr T. via cfe-commits


@@ -11246,6 +11246,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   if (S.getLangOpts().OpenCL)
 return;
 
+  if (LHS.get()->IgnoreParenImpCasts()->getType()->isBooleanType()) {
+S.Diag(Loc, diag::warn_shift_bool)
+<< (Opc == BO_Shr) /*left|right*/ << LHS.get()->getSourceRange();

a-tarasyuk wrote:

@AaronBallman could you please review the latest changes? thanks

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


  1   2   3   4   5   >