[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign matrix element atom (PR #134650)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams ready_for_review 
https://github.com/llvm/llvm-project/pull/134650
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] If stmt atom (PR #134642)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

Excellent, I mistakenly merged this into users/OCHyams/ki-clang-catch-init 
rather than main. **Merged in 123bf5f46c31a016768b7ecd9b164bde5ef881d9** 

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


[llvm-branch-commits] [clang] [KeyInstr][Clang] Bitfield atom (PR #134648)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134648
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign vector element atom (PR #134649)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134649
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Bitfield atom (PR #134648)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/134648

>From 76d8a4306760fba28fc22c936b46d98263c37971 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 19:57:39 +0100
Subject: [PATCH 1/2] [KeyInstr][Clang] Bitfield atom

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
---
 clang/lib/CodeGen/CGExpr.cpp  |  3 ++-
 clang/test/DebugInfo/KeyInstructions/bitfield.cpp | 13 +
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/DebugInfo/KeyInstructions/bitfield.cpp

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 2c0edd69d96e9..e72288ccd3c26 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2672,7 +2672,8 @@ void 
CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
   }
 
   // Write the new value back out.
-  Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, SrcVal);
 
   // Return the new value of the bit-field, if requested.
   if (Result) {
diff --git a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp 
b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp
new file mode 100644
index 0..0586050ba8397
--- /dev/null
+++ b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+struct S { int a:3; };
+
+void foo(int x, S s) {
+// CHECK: %bf.set = or i8 %bf.clear, %bf.value, !dbg [[G1R2:!.*]]
+// CHECK: store i8 %bf.set, ptr %s, align 4, !dbg [[G1R1:!.*]]
+  s.a = x;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

>From d64c34ffe83820895a8a2487dc9e72abbc16b85c Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Wed, 21 May 2025 15:55:29 +0100
Subject: [PATCH 2/2] cc1

---
 clang/test/DebugInfo/KeyInstructions/bitfield.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp 
b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp
index 0586050ba8397..b76e6ec3d9c99 100644
--- a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - \
+// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only 
-emit-llvm -o - \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
 struct S { int a:3; };

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


[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign vector element atom (PR #134649)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/134649

>From ee7ef1b588e08991f141dcef31f2c3133311f654 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 21:56:37 +0100
Subject: [PATCH] [KeyInstr][Clang] Assign vector element atom

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
---
 clang/lib/CodeGen/CGExpr.cpp   | 5 +++--
 clang/test/DebugInfo/KeyInstructions/agg.c | 8 
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 2c0edd69d96e9..f1d2c45490c68 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2507,8 +2507,9 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
 Vec = Builder.CreateBitCast(Vec, IRStoreTy);
   }
 
-  Builder.CreateStore(Vec, Dst.getVectorAddress(),
-  Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(Vec, Dst.getVectorAddress(),
+Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, Vec);
   return;
 }
 
diff --git a/clang/test/DebugInfo/KeyInstructions/agg.c 
b/clang/test/DebugInfo/KeyInstructions/agg.c
index 06c9ebbb63369..f3fa7888610e3 100644
--- a/clang/test/DebugInfo/KeyInstructions/agg.c
+++ b/clang/test/DebugInfo/KeyInstructions/agg.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -gkey-instructions -x c %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
+__attribute__((ext_vector_type(1))) char c;
 typedef struct { int a, b, c; } Struct;
 void fun(Struct a) {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
@@ -11,7 +12,14 @@ void fun(Struct a) {
 
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G2R1:!.*]]
   b = a;
+
+// CHECK: %2 = load <1 x i8>, ptr @c
+// CHECK: %vecins = insertelement <1 x i8> %2, i8 0, i32 0, !dbg [[G3R2:!.*]]
+// CHECK: store <1 x i8> %vecins, ptr @c{{.*}}, !dbg [[G3R1:!.*]]
+  c[0] = 0;
 }
 
 // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
 // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

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


[llvm-branch-commits] [clang] [KeyInstr][Clang] For range stmt atoms (PR #134647)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134647
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] For range stmt atoms (PR #134647)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/134647

>From d99a29e180b29f9bce7d6e3172d4241e3f0cba56 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 19:46:01 +0100
Subject: [PATCH 1/2] [KeyInstr][Clang] For range stmt atoms

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
---
 clang/lib/CodeGen/CGStmt.cpp  | 13 +++-
 .../DebugInfo/KeyInstructions/for-range.cpp   | 72 +++
 2 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/DebugInfo/KeyInstructions/for-range.cpp

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 3562b4ea22a24..766e77594ab5d 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1448,7 +1448,14 @@ CodeGenFunction::EmitCXXForRangeStmt(const 
CXXForRangeStmt &S,
   if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
 BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
 BoolCondVal, Stmt::getLikelihood(S.getBody()));
-  Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
+  auto *I = Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
+  // Key Instructions: Emit the condition and branch as separate atoms to
+  // match existing loop stepping behaviour. FIXME: We could have the branch as
+  // the backup location for the condition, which would probably be a better
+  // experience.
+  if (auto *I = dyn_cast(BoolCondVal))
+addInstToNewSourceAtom(I, nullptr);
+  addInstToNewSourceAtom(I, nullptr);
 
   if (ExitBlock != LoopExit.getBlock()) {
 EmitBlock(ExitBlock);
@@ -1497,6 +1504,10 @@ CodeGenFunction::EmitCXXForRangeStmt(const 
CXXForRangeStmt &S,
 
   if (CGM.shouldEmitConvergenceTokens())
 ConvergenceTokenStack.pop_back();
+
+  // We want the for closing brace to be step-able on to match existing
+  // behaviour. 
+  addInstToNewSourceAtom(ForBody->getTerminator(), nullptr);
 }
 
 void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) {
diff --git a/clang/test/DebugInfo/KeyInstructions/for-range.cpp 
b/clang/test/DebugInfo/KeyInstructions/for-range.cpp
new file mode 100644
index 0..be71d9fbfb581
--- /dev/null
+++ b/clang/test/DebugInfo/KeyInstructions/for-range.cpp
@@ -0,0 +1,72 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Perennial quesiton: should the inc be its own source atom or not
+// (currently it is).
+
+// FIXME: See do.c and while.c regarding cmp and cond br groups.
+
+// The stores in the setup (stores to __RANGE1, __BEGIN1, __END1) are all
+// marked as Key. Unclear whether that's desirable. Keep for now as that's
+// least risky.
+
+// Check the conditional branch (and the condition) in FOR_COND and
+// unconditional branch in FOR_BODY are Key Instructions.
+
+struct Range {
+int *begin();
+int *end();
+} r;
+
+// CHECK-LABEL: define dso_local void @_Z1av(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] !dbg [[DBG10:![0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[__RANGE1:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[__BEGIN1:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[__END1:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store ptr @r, ptr [[__RANGE1]], align 8, !dbg 
[[DBG14:![0-9]+]]
+// CHECK-NEXT:[[CALL:%.*]] = call noundef ptr @_ZN5Range5beginEv(ptr 
noundef nonnull align 1 dereferenceable(1) @r), !dbg [[DBG15:![0-9]+]]
+// CHECK-NEXT:store ptr [[CALL]], ptr [[__BEGIN1]], align 8, !dbg 
[[DBG16:![0-9]+]]
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef ptr @_ZN5Range3endEv(ptr 
noundef nonnull align 1 dereferenceable(1) @r), !dbg [[DBG17:![0-9]+]]
+// CHECK-NEXT:store ptr [[CALL1]], ptr [[__END1]], align 8, !dbg 
[[DBG18:![0-9]+]]
+// CHECK-NEXT:br label %[[FOR_COND:.*]], !dbg [[DBG19:![0-9]+]]
+// CHECK:   [[FOR_COND]]:
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[__BEGIN1]], align 8, !dbg 
[[DBG19]]
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[__END1]], align 8, !dbg 
[[DBG19]]
+// CHECK-NEXT:[[CMP:%.*]] = icmp ne ptr [[TMP0]], [[TMP1]], !dbg 
[[DBG20:![0-9]+]]
+// CHECK-NEXT:br i1 [[CMP]], label %[[FOR_BODY:.*]], label 
%[[FOR_END:.*]], !dbg [[DBG21:![0-9]+]]
+// CHECK:   [[FOR_BODY]]:
+// CHECK-

[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign matrix element atom (PR #134650)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134650
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign matrix element atom (PR #134650)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/134650

>From 0e2df471a1a9d1009086167b3dfe14af9a7a43af Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 22:05:32 +0100
Subject: [PATCH 1/2] [KeyInstr][Clang] Assign matrix element atom

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
---
 clang/lib/CodeGen/CGExpr.cpp   | 5 +++--
 clang/test/DebugInfo/KeyInstructions/agg.c | 9 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index f1d2c45490c68..4d9b2d217fedb 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2531,8 +2531,9 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
   llvm::Instruction *Load = Builder.CreateLoad(Dst.getMatrixAddress());
   llvm::Value *Vec =
   Builder.CreateInsertElement(Load, Src.getScalarVal(), Idx, "matins");
-  Builder.CreateStore(Vec, Dst.getMatrixAddress(),
-  Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(Vec, Dst.getMatrixAddress(),
+Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, Vec);
   return;
 }
 
diff --git a/clang/test/DebugInfo/KeyInstructions/agg.c 
b/clang/test/DebugInfo/KeyInstructions/agg.c
index f3fa7888610e3..68a4fd45ab35c 100644
--- a/clang/test/DebugInfo/KeyInstructions/agg.c
+++ b/clang/test/DebugInfo/KeyInstructions/agg.c
@@ -5,6 +5,8 @@
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
 __attribute__((ext_vector_type(1))) char c;
+typedef float m5x5 __attribute__((matrix_type(5, 5)));
+m5x5 m;
 typedef struct { int a, b, c; } Struct;
 void fun(Struct a) {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
@@ -17,9 +19,16 @@ void fun(Struct a) {
 // CHECK: %vecins = insertelement <1 x i8> %2, i8 0, i32 0, !dbg [[G3R2:!.*]]
 // CHECK: store <1 x i8> %vecins, ptr @c{{.*}}, !dbg [[G3R1:!.*]]
   c[0] = 0;
+
+// CHECK: %3 = load <25 x float>, ptr @m, align 4
+// CHECK: %matins = insertelement <25 x float> %3, float 0.00e+00, i64 0, 
!dbg [[G4R2:!.*]]
+// CHECK: store <25 x float> %matins, ptr @m{{.*}}, !dbg [[G4R1:!.*]]
+  m[0][0] = 0;
 }
 
 // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
 // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
 // CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
 // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

>From 04fd5cd6612008ab5120b509209c616b8ab55203 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Wed, 21 May 2025 16:00:41 +0100
Subject: [PATCH 2/2] cc1

---
 clang/test/DebugInfo/KeyInstructions/agg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/DebugInfo/KeyInstructions/agg.c 
b/clang/test/DebugInfo/KeyInstructions/agg.c
index 68a4fd45ab35c..e52f26e13d09f 100644
--- a/clang/test/DebugInfo/KeyInstructions/agg.c
+++ b/clang/test/DebugInfo/KeyInstructions/agg.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -gkey-instructions -x c++ %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
+// RUN: %clang_cc1 -gkey-instructions -x c++ %s 
-debug-info-kind=line-tables-only -emit-llvm -o - -fenable-matrix \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
-// RUN: %clang_cc1 -gkey-instructions -x c %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
+// RUN: %clang_cc1 -gkey-instructions -x c %s 
-debug-info-kind=line-tables-only -emit-llvm -o - -fenable-matrix \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
 __attribute__((ext_vector_type(1))) char c;

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


[llvm-branch-commits] [clang] [KeyIntsr][Clang] Builtins alloca auto-init atom (PR #134651)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134651
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Ret atom (PR #134652)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134652
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Ret atom (PR #134652)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

Keeping in draft till the patches below this in the stack are merged, as this 
touches all their tests. Unfortunately the diff is going to be messed up till 
then too due to various branch retargeting and rebasing.

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


[llvm-branch-commits] [llvm] [NFC] Updating RTS0 namespace to contain all elements related to it's representation (PR #141173)

2025-05-23 Thread Justin Bogner via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing infastructure for StaticSampler (PR #140180)

2025-05-23 Thread Justin Bogner via llvm-branch-commits

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


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


[llvm-branch-commits] change GlobPattern:Prefix from stringref to string. (PR #141270)

2025-05-23 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Qinkun Bao (qinkunbao)


Changes



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


1 Files Affected:

- (modified) llvm/include/llvm/Support/GlobPattern.h (+1-1) 


``diff
diff --git a/llvm/include/llvm/Support/GlobPattern.h 
b/llvm/include/llvm/Support/GlobPattern.h
index 62ed4a0f23fd9..5849ca5c6bc98 100644
--- a/llvm/include/llvm/Support/GlobPattern.h
+++ b/llvm/include/llvm/Support/GlobPattern.h
@@ -71,7 +71,7 @@ class GlobPattern {
   }
 
 private:
-  StringRef Prefix;
+  std::string Prefix;
 
   struct SubGlobPattern {
 /// \param Pat the pattern to match against

``




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


[llvm-branch-commits] change GlobPattern:Prefix from stringref to string. (PR #141270)

2025-05-23 Thread Qinkun Bao via llvm-branch-commits

https://github.com/qinkunbao created 
https://github.com/llvm/llvm-project/pull/141270

None


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


[llvm-branch-commits] [lld] ELF: Add branch-to-branch optimization. (PR #138366)

2025-05-23 Thread Rahman Lavaee via llvm-branch-commits

rlavaee wrote:

At my first glance, it seems this feature overwrites the target of the branch 
and doesn't move or relax the branches within the section, which would 
interfere with the SHT_LLVM_BB_ADDR_MAP. Could you please add a test just to be 
safe? You could use amend  a test with the SHT_LLVM_BB_ADDR_MAP section 
(https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/X86/basic-block-address-map.ll).


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


[llvm-branch-commits] change GlobPattern:Prefix from stringref to string. (PR #141270)

2025-05-23 Thread Qinkun Bao via llvm-branch-commits

https://github.com/qinkunbao edited 
https://github.com/llvm/llvm-project/pull/141270
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] CodeGen: Fix implementation of __builtin_trivially_relocate. (PR #140312)

2025-05-23 Thread via llvm-branch-commits

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

Thanks for finding this bug!

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


[llvm-branch-commits] [clang] [KeyInstr][Clang] If stmt atom (PR #134642)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams closed 
https://github.com/llvm/llvm-project/pull/134642
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams edited 
https://github.com/llvm/llvm-project/pull/134643
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134643
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Prevent R0/R1 allocation for rj operand of [G]CSRXCHG (#140862) (PR #141194)

2025-05-23 Thread via llvm-branch-commits

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

LGTM

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


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits


@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -gkey-instructions -x c++ -std=c++17 %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang_cc1 -gkey-instructions -x c %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A, int B) {
+// CHECK: entry:
+// The load gets associated with the branch rather than the store.
+// FIXME: Is that the best thing to do?

OCHyams wrote:

Consider also that we could have:
```
switch
  ((g = A))
{
```

If the store gets DSE'd and switch stays put, and we have the current setup 
(load in switch's atom group), then we don't step on `((g = A))`. The store and 
load are line `y` and switch is line `x`. So non-key-instructions behaviour in 
that case is step `y, x` whereas with this patch it would be just `x`. If we 
associated the load with the store instead of the switch it'd be `y, x` (step 
on the load then the switch/br).

That's a long way of saying... maybe we _should_ switch it round? I can't 
remember how tricky it would be. I think at worst it involves adding another 
param to `addInstToNewSourceAtom` to avoid overriding existing groups (atm it 
won't override an existing group if the new rank designation is lower priority.

We could make that `<=` instead too... that would impact the other 
dual-membership setups which we need to check all make sense after the change.

So - any objection to me adding this to the TODO list instead, to submit it as 
another patch after the initial stack lands?



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


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits


@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -gkey-instructions -x c++ -std=c++17 %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang_cc1 -gkey-instructions -x c %s 
-debug-info-kind=line-tables-only -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A, int B) {
+// CHECK: entry:
+// The load gets associated with the branch rather than the store.
+// FIXME: Is that the best thing to do?
+// CHECK: %0 = load i32, ptr %A.addr{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: switch i32 %0, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb
+// CHECK:   i32 1, label %sw.bb1
+// CHECK: ], !dbg [[G2R1:!.*]]
+switch ((g = A)) {
+case 0: break;
+case 1: {
+// CHECK: sw.bb1:
+// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: switch i32 %1, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb2
+// CHECK: ], !dbg [[G3R1:!.*]]
+switch ((B)) {
+case 0: {
+// Test that assignments in constant-folded switches don't go missing.
+// CHECK-CXX: sw.bb2:
+// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G4R1:!.*]]

OCHyams wrote:

There's no switch emitted as it gets constant folded: 
https://godbolt.org/z/3vv4qxTMr

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


[llvm-branch-commits] [llvm] a46c287 - Revert "[SPIR-V] Support `SPV_INTEL_int4` extension (#141031)"

2025-05-23 Thread via llvm-branch-commits

Author: Dmitry Sidorov
Date: 2025-05-23T11:45:41+02:00
New Revision: a46c28756c90b7a0214acdac2e00b491bf6520aa

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

LOG: Revert "[SPIR-V] Support `SPV_INTEL_int4` extension (#141031)"

This reverts commit ced6076dfc39aa54f6d703982e6752e4be8370f5.

Added: 


Modified: 
llvm/docs/SPIRVUsage.rst
llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td

Removed: 
llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_int4/cooperative_matrix.ll
llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_int4/negative.ll
llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_int4/trivial.ll



diff  --git a/llvm/docs/SPIRVUsage.rst b/llvm/docs/SPIRVUsage.rst
index 1858bda6160d4..1afae43aa8bce 100644
--- a/llvm/docs/SPIRVUsage.rst
+++ b/llvm/docs/SPIRVUsage.rst
@@ -215,8 +215,6 @@ list of supported SPIR-V extensions, sorted alphabetically 
by their extension na
  - Adds a bitwise instruction on three operands and a look-up table index 
for specifying the bitwise operation to perform. 
* - ``SPV_INTEL_subgroup_matrix_multiply_accumulate``
  - Adds an instruction to compute the matrix product of an M x K matrix 
with a K x N matrix and then add an M x N matrix. 
-   * - ``SPV_INTEL_int4``
- - Adds support for 4-bit integer type, and allow this type to be used in 
cooperative matrices.
 
 To enable multiple extensions, list them separated by comma. For example, to 
enable support for atomic operations on floating-point numbers and arbitrary 
precision integers, use:
 

diff  --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp 
b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
index fbaca4e0e4d81..e6cb8cee66a60 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
@@ -99,8 +99,7 @@ static const std::map>
 {"SPV_INTEL_ternary_bitwise_function",
  SPIRV::Extension::Extension::SPV_INTEL_ternary_bitwise_function},
 {"SPV_INTEL_2d_block_io",
- SPIRV::Extension::Extension::SPV_INTEL_2d_block_io},
-{"SPV_INTEL_int4", SPIRV::Extension::Extension::SPV_INTEL_int4}};
+ SPIRV::Extension::Extension::SPV_INTEL_2d_block_io}};
 
 bool SPIRVExtensionsParser::parse(cl::Option &O, StringRef ArgName,
   StringRef ArgValue,

diff  --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp 
b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index d9fcb5623b220..ac397fc486e19 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -154,8 +154,7 @@ unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(unsigned 
Width) const {
 report_fatal_error("Unsupported integer width!");
   const SPIRVSubtarget &ST = cast(CurMF->getSubtarget());
   if (ST.canUseExtension(
-  SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers) ||
-  ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4))
+  SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers))
 return Width;
   if (Width <= 8)
 Width = 8;
@@ -175,14 +174,9 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(unsigned 
Width,
   const SPIRVSubtarget &ST =
   cast(MIRBuilder.getMF().getSubtarget());
   return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
-if (Width == 4 && ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
-  MIRBuilder.buildInstr(SPIRV::OpExtension)
-  .addImm(SPIRV::Extension::SPV_INTEL_int4);
-  MIRBuilder.buildInstr(SPIRV::OpCapability)
-  .addImm(SPIRV::Capability::Int4TypeINTEL);
-} else if ((!isPowerOf2_32(Width) || Width < 8) &&
-   ST.canUseExtension(
-   SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
+if ((!isPowerOf2_32(Width) || Width < 8) &&
+ST.canUseExtension(
+SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
   MIRBuilder.buildInstr(SPIRV::OpExtension)
   .addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers);
   MIRBuilder.buildInstr(SPIRV::OpCapability)
@@ -1569,13 +1563,6 @@ SPIRVType 
*SPIRVGlobalRegistry::getOrCreateOpTypeCoopMatr(
   const MachineInstr *NewMI =
   createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 SPIRVType *SpvTypeInt32 = getOrCreateSPIRVIntegerType(32, MIRBuilder);
-const Type *ET = getTypeForSPIRVType(ElemType);
-if (ET->isIntegerTy() && ET->getIntegerBitWidth() == 4 &&
-cast(MIRBuilder.getMF().getSubtarget())
-.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
- 

[llvm-branch-commits] [clang] [KeyInstr][Clang] Do stmt atom (PR #134644)

2025-05-23 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams converted_to_draft 
https://github.com/llvm/llvm-project/pull/134644
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] Add missing imports (PR #138550)

2025-05-23 Thread Filip Laurentiu via llvm-branch-commits

FilipLaurentiu wrote:

> The LLVM 19 release is no longer supported. You'll have to apply this as a 
> local patch if you want to build and old LLVM 19 with a new libstdc++.

Some projects still use LLVM 19. I am not an LLVM developer, not even a C++ 
developer, but I am working on a project that depends on MLIR, unfortunately 
building this from scratch is anything but easy.

Documentation doesn't help much, and if you found a fix, you should suggest a 
workaround

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


[llvm-branch-commits] [lld] ELF: Add branch-to-branch optimization. (PR #138366)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

Right, this feature doesn't change section sizes, so there shouldn't be an 
interaction with SHT_LLVM_BB_ADDR_MAP. AFAICT LLD doesn't contain code that 
parses SHT_LLVM_BB_ADDR_MAP so I don't see value in adding a test for it.

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


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of floats for StaticSampler (PR #140181)

2025-05-23 Thread Deric C. via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of floats for StaticSampler (PR #140181)

2025-05-23 Thread Deric C. via llvm-branch-commits


@@ -821,22 +873,110 @@ std::optional 
RootSignatureParser::handleUIntLiteral() {
   PP.getSourceManager(), PP.getLangOpts(),
   PP.getTargetInfo(), PP.getDiagnostics());
   if (Literal.hadError)
-return true; // Error has already been reported so just return
+return std::nullopt; // Error has already been reported so just return
 
-  assert(Literal.isIntegerLiteral() && "IsNumberChar will only support 
digits");
+  assert(Literal.isIntegerLiteral() &&
+ "NumSpelling can only consist of digits");
 
   llvm::APSInt Val = llvm::APSInt(32, false);
   if (Literal.GetIntegerValue(Val)) {
 // Report that the value has overflowed
 PP.getDiagnostics().Report(CurToken.TokLoc,
diag::err_hlsl_number_literal_overflow)
-<< 0 << CurToken.NumSpelling;
+<< /*integer type*/ 0 << /*is signed*/ 0;
 return std::nullopt;
   }
 
   return Val.getExtValue();
 }
 
+std::optional RootSignatureParser::handleIntLiteral(bool Negated) {
+  // Parse the numeric value and do semantic checks on its specification
+  clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return std::nullopt; // Error has already been reported so just return
+
+  assert(Literal.isIntegerLiteral() &&
+ "NumSpelling can only consist of digits");
+
+  llvm::APSInt Val = llvm::APSInt(32, true);
+  if (Literal.GetIntegerValue(Val) || INT32_MAX < Val.getExtValue()) {

Icohedron wrote:

Why is the `|| INT32_MAX < Val.getExtValue()` necessary? Doesn't 
`Literal.GetIntegerValue(Val)` already return true if Val overflows?

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


[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement `ResourceRange` as an `IntervalMap` (PR #140957)

2025-05-23 Thread Deric C. via llvm-branch-commits


@@ -222,6 +222,67 @@ MDNode *MetadataBuilder::BuildDescriptorTableClause(
});
 }
 
+std::optional
+ResourceRange::getOverlapping(const RangeInfo &Info) const {
+  IMap::const_iterator Interval = Intervals.find(Info.LowerBound);
+  if (!Interval.valid() || Info.UpperBound < Interval.start())
+return std::nullopt;
+  return Interval.value();
+}
+
+const RangeInfo *ResourceRange::lookup(uint32_t X) const {
+  return Intervals.lookup(X, nullptr);
+}
+
+std::optional ResourceRange::insert(const RangeInfo &Info) {
+  uint32_t LowerBound = Info.LowerBound;
+  uint32_t UpperBound = Info.UpperBound;
+
+  std::optional Res = std::nullopt;
+  IMap::iterator Interval = Intervals.begin();
+
+  while (true) {
+if (UpperBound < LowerBound)
+  break;
+
+Interval.advanceTo(LowerBound);
+if (!Interval.valid()) // No interval found
+  break;
+
+// Let Interval = [x;y] and [LowerBound;UpperBound] = [a;b] and note that
+// a <= y implicitly from Intervals.find(LowerBound)

Icohedron wrote:

```suggestion
// a <= y implicitly from Interval.advanceTo(LowerBound)
```

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Track if a type is a template or builtin (PR #138067)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 73cdd50ae91dbb751d2d3d56c388bcca6227b137 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Wed, 30 Apr 2025 14:20:40 -0700
Subject: [PATCH] [clang-doc] Track if a type is a template or builtin

Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou 
---
 clang-tools-extra/clang-doc/Representation.h |  3 +++
 clang-tools-extra/clang-doc/Serialize.cpp| 17 -
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index 1673be496b7b2..a3a6217f76bbd 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -164,6 +164,9 @@ struct TypeInfo {
   bool operator==(const TypeInfo &Other) const { return Type == Other.Type; }
 
   Reference Type; // Referenced type in this info.
+
+  bool IsTemplate = false;
+  bool IsBuiltIn = false;
 };
 
 // Represents one template parameter.
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 7e56fe7236479..b6c76c31f0ae0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -405,9 +405,12 @@ static RecordDecl *getRecordDeclForType(const QualType &T) 
{
 static TypeInfo getTypeInfoForType(const QualType &T,
const PrintingPolicy &Policy) {
   const TagDecl *TD = getTagDeclForType(T);
-  if (!TD)
-return TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
-
+  if (!TD) {
+TypeInfo TI = TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
+TI.IsBuiltIn = T->isBuiltinType();
+TI.IsTemplate = T->isTemplateTypeParmType();
+return TI;
+  }
   InfoType IT;
   if (isa(TD)) {
 IT = InfoType::IT_enum;
@@ -416,8 +419,12 @@ static TypeInfo getTypeInfoForType(const QualType &T,
   } else {
 IT = InfoType::IT_default;
   }
-  return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
-T.getAsString(Policy), getInfoRelativePath(TD)));
+  Reference R = Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
+  T.getAsString(Policy), getInfoRelativePath(TD));
+  TypeInfo TI = TypeInfo(R);
+  TI.IsBuiltIn = T->isBuiltinType();
+  TI.IsTemplate = T->isTemplateTypeParmType();
+  return TI;
 }
 
 static bool isPublic(const clang::AccessSpecifier AS,

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Update clang-doc tool to enable mustache templates (PR #138066)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 3d478e150a4bb22b1561852dcddbaed1e24b Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 29 Apr 2025 18:08:03 -0700
Subject: [PATCH] [clang-doc] Update clang-doc tool to enable mustache
 templates

This patch adds a command line option and enables the Mustache template
HTML backend. This allows users to use the new, more flexible templates
over the old and cumbersome HTML output. Split from #133161.

Co-authored-by: Peter Chou 
---
 .../clang-doc/tool/ClangDocMain.cpp   |  80 +--
 .../clang-doc/basic-project.mustache.test | 481 ++
 2 files changed, 531 insertions(+), 30 deletions(-)
 create mode 100644 clang-tools-extra/test/clang-doc/basic-project.mustache.test

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 8e8f7053a8f87..41fbe87a713d9 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -18,20 +18,14 @@
 
//===--===//
 
 #include "BitcodeReader.h"
-#include "BitcodeWriter.h"
 #include "ClangDoc.h"
 #include "Generators.h"
 #include "Representation.h"
-#include "clang/AST/AST.h"
-#include "clang/AST/Decl.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "support/Utils.h"
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
-#include "clang/Driver/Options.h"
-#include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
@@ -110,22 +104,19 @@ static llvm::cl::opt 
RepositoryCodeLinePrefix(
 llvm::cl::desc("Prefix of line code for repository."),
 llvm::cl::cat(ClangDocCategory));
 
-enum OutputFormatTy {
-  md,
-  yaml,
-  html,
-};
-
-static llvm::cl::opt
-FormatEnum("format", llvm::cl::desc("Format for outputted docs."),
-   llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
-   "Documentation in YAML format."),
-clEnumValN(OutputFormatTy::md, "md",
-   "Documentation in MD format."),
-clEnumValN(OutputFormatTy::html, "html",
-   "Documentation in HTML format.")),
-   llvm::cl::init(OutputFormatTy::yaml),
-   llvm::cl::cat(ClangDocCategory));
+enum OutputFormatTy { md, yaml, html, mustache };
+
+static llvm::cl::opt FormatEnum(
+"format", llvm::cl::desc("Format for outputted docs."),
+llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
+"Documentation in YAML format."),
+ clEnumValN(OutputFormatTy::md, "md",
+"Documentation in MD format."),
+ clEnumValN(OutputFormatTy::html, "html",
+"Documentation in HTML format."),
+ clEnumValN(OutputFormatTy::mustache, "mustache",
+"Documentation in mustache HTML format")),
+llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory));
 
 static std::string getFormatString() {
   switch (FormatEnum) {
@@ -135,6 +126,8 @@ static std::string getFormatString() {
 return "md";
   case OutputFormatTy::html:
 return "html";
+  case OutputFormatTy::mustache:
+return "mustache";
   }
   llvm_unreachable("Unknown OutputFormatTy");
 }
@@ -178,13 +171,9 @@ static llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
-  llvm::SmallString<128> DefaultStylesheet;
-  llvm::sys::path::native(AssetsPath, DefaultStylesheet);
-  llvm::sys::path::append(DefaultStylesheet,
-  "clang-doc-default-stylesheet.css");
-  llvm::SmallString<128> IndexJS;
-  llvm::sys::path::native(AssetsPath, IndexJS);
-  llvm::sys::path::append(IndexJS, "index.js");
+  llvm::SmallString<128> DefaultStylesheet =
+  appendPathNative(AssetsPath, "clang-doc-default-stylesheet.css");
+  llvm::SmallString<128> IndexJS = appendPathNative(AssetsPath, "index.js");
 
   if (!llvm::sys::fs::is_regular_file(IndexJS))
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -215,6 +204,30 @@ static llvm::Error getHtmlAssetFiles(const char *Argv0,
   return getDefaultAssetFiles(Argv0, CDCtx);
 }
 
+static llvm::Error getMustacheHtmlFiles(const char *Argv0,
+clang::doc::ClangDocContext &CDCtx) {
+  bool IsDir = llvm::sys::fs::is_direct

[llvm-branch-commits] change GlobPattern:Prefix from stringref to string. (PR #141270)

2025-05-23 Thread Qinkun Bao via llvm-branch-commits

https://github.com/qinkunbao closed 
https://github.com/llvm/llvm-project/pull/141270
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 7deaf5aea3a20dc34f7eab13244e161da74a3148 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 29 Apr 2025 18:31:54 -0700
Subject: [PATCH] [clang-doc] Update serializer for improved template handling

This patch updates Serialize.cpp to serialize more data about C++
templates, which are supported by the new mustache HTML template.
Split from #133161.

Co-authored-by: Peter Chou 
---
 clang-tools-extra/clang-doc/Representation.h |   3 +
 clang-tools-extra/clang-doc/Serialize.cpp| 203 ++-
 2 files changed, 198 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a2e01719eb59e..1673be496b7b2 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -363,6 +363,9 @@ struct FunctionInfo : public SymbolInfo {
   // specializations.
   SmallString<16> FullName;
 
+  // Function Prototype
+  SmallString<256> Prototype;
+
   // When present, this function is a template or specialization.
   std::optional Template;
 };
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index fe4ef9c50cc12..7e56fe7236479 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -8,10 +8,10 @@
 
 #include "Serialize.h"
 #include "BitcodeWriter.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Comment.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/SHA1.h"
 
@@ -35,6 +35,169 @@ static void populateMemberTypeInfo(RecordInfo &I, 
AccessSpecifier &Access,
const DeclaratorDecl *D,
bool IsStatic = false);
 
+static void getTemplateParameters(const TemplateParameterList *TemplateParams,
+  llvm::raw_ostream &Stream) {
+  Stream << "template <";
+
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0)
+  Stream << ", ";
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename())
+Stream << "typename";
+  else
+Stream << "class";
+  if (TTP->isParameterPack())
+Stream << "...";
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP =
+   llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack())
+Stream << "...";
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD =
+   llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including
+// Full Decl
+static llvm::SmallString<256>
+getFunctionPrototype(const FunctionDecl *FuncDecl) {
+  llvm::SmallString<256> Result;
+  llvm::raw_svector_ostream Stream(Result);
+  const ASTContext &Ctx = FuncDecl->getASTContext();
+  const auto *Method = llvm::dyn_cast(FuncDecl);
+  // If it's a templated function, handle the template parameters
+  if (const auto *TmplDecl = FuncDecl->getDescribedTemplate())
+getTemplateParameters(TmplDecl->getTemplateParameters(), Stream);
+
+  // If it's a virtual method
+  if (Method && Method->isVirtual())
+Stream << "virtual ";
+
+  // Print return type
+  FuncDecl->getReturnType().print(Stream, Ctx.getPrintingPolicy());
+
+  // Print function name
+  Stream << " " << FuncDecl->getNameAsString() << "(";
+
+  // Print parameter list with types, names, and default values
+  for (unsigned I = 0; I < FuncDecl->getNumParams(); ++I) {
+if (I > 0)
+  Stream << ", ";
+const ParmVarDecl *ParamDecl = FuncDecl->getParamDecl(I);
+QualType ParamType = ParamDecl->getType();
+ParamType.print(Stream, Ctx.getPrintingPolicy());
+
+// Print parameter name if it has one
+if (!ParamDecl->getName().empty())
+  Stream << " " << ParamDecl->getNameAsString();
+
+// Print default argument if it exists
+if (ParamDecl->hasDefaultArg()) {
+  const Expr *DefaultArg = ParamDecl->getDefaultArg();
+  if (DefaultArg) {
+Stream << " = ";
+DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
+  }
+}
+  }
+
+  // If it is a variadic function, add '...'
+  if (FuncDecl->isVariadic()) {
+if (FuncDecl->getNumParams() > 0)
+  Stream << ", ";
+Stream << "...";
+  }
+
+  Stream << ")";
+
+  // If it's a const method, add 'const' qualifier
+  if (Method) {
+if (Method->size_overridden_methods())
+   

[llvm-branch-commits] [clang] CodeGen: Fix implementation of __builtin_trivially_relocate. (PR #140312)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/140312

>From 1399ec4fdf8fe08000b590844f4e24c31a310a01 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 21 May 2025 16:20:57 -0700
Subject: [PATCH] Add test with variable count

Created using spr 1.3.6-beta.1
---
 .../CodeGenCXX/cxx2c-trivially-relocatable.cpp | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp 
b/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
index 63f3ba8e74ed5..465e539d363e8 100644
--- a/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
+++ b/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++26 -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 
+typedef __SIZE_TYPE__ size_t;
+
 struct S trivially_relocatable_if_eligible {
 S(const S&);
 ~S();
@@ -8,9 +10,13 @@ struct S trivially_relocatable_if_eligible {
 };
 
 // CHECK: @_Z4testP1SS0_
-// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 8
-// CHECK-NOT: __builtin
-// CHECK: ret
-void test(S* source, S* dest) {
+void test(S* source, S* dest, size_t count) {
+// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 8
+// CHECK-NOT: __builtin
 __builtin_trivially_relocate(dest, source, 1);
+// CHECK: [[A:%.*]] = load i64, ptr %count.addr
+// CHECK: [[M:%.*]] = mul i64 [[A]], 8
+// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 [[M]]
+__builtin_trivially_relocate(dest, source, count);
+// CHECK: ret
 };

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


[llvm-branch-commits] [lld] ELF: Add branch-to-branch optimization. (PR #138366)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/138366

>From d67e152baaf8487e5cb049166ce61e905011171e Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 30 Apr 2025 18:25:54 -0700
Subject: [PATCH] ELF: Add branch-to-branch optimization.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When code calls a function which then immediately tail calls another
function there is no need to go via the intermediate function. By
branching directly to the target function we reduce the program's working
set for a slight increase in runtime performance.

Normally it is relatively uncommon to have functions that just tail call
another function, but with LLVM control flow integrity we have jump tables
that replace the function itself as the canonical address. As a result,
when a function address is taken and called directly, for example after
a compiler optimization resolves the indirect call, or if code built
without control flow integrity calls the function, the call will go via
the jump table.

The impact of this optimization was measured using a large internal
Google benchmark. The results were as follows:

CFI enabled:  +0.1% ± 0.05% queries per second
CFI disabled: +0.01% queries per second [not statistically significant]

The optimization is enabled by default at -O2 but may also be enabled
or disabled individually with --{,no-}branch-to-branch.

This optimization is implemented for AArch64 and X86_64 only.

lld's runtime performance (real execution time) after adding this
optimization was measured using firefox-x64 from lld-speed-test [1]
with ldflags "-O2 -S" on an Apple M2 Ultra. The results are as follows:

```
N   Min   MaxMedian   AvgStddev
x 512 1.2264546 1.3481076 1.2970261 1.2965788   0.018620888
+ 512 1.2561196 1.3839965 1.3214632 1.3209327   0.019443971
Difference at 95.0% confidence
0.0243538 +/- 0.00233202
1.87831% +/- 0.179859%
(Student's t, pooled s = 0.0190369)
```

[1] 
https://discourse.llvm.org/t/improving-the-reproducibility-of-linker-benchmarking/86057

Pull Request: https://github.com/llvm/llvm-project/pull/138366
---
 lld/ELF/Arch/AArch64.cpp| 59 +++
 lld/ELF/Arch/TargetImpl.h   | 94 
 lld/ELF/Arch/X86_64.cpp | 69 +
 lld/ELF/Config.h|  1 +
 lld/ELF/Driver.cpp  |  2 +
 lld/ELF/Options.td  |  4 +
 lld/ELF/Relocations.cpp |  8 +-
 lld/ELF/Target.h|  1 +
 lld/docs/ld.lld.1   |  8 +-
 lld/test/ELF/aarch64-branch-to-branch.s | 61 +++
 lld/test/ELF/x86-64-branch-to-branch.s  | 98 +
 11 files changed, 401 insertions(+), 4 deletions(-)
 create mode 100644 lld/ELF/Arch/TargetImpl.h
 create mode 100644 lld/test/ELF/aarch64-branch-to-branch.s
 create mode 100644 lld/test/ELF/x86-64-branch-to-branch.s

diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 9538dd4a70bae..5a3c86b209ea5 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -11,6 +11,7 @@
 #include "Symbols.h"
 #include "SyntheticSections.h"
 #include "Target.h"
+#include "TargetImpl.h"
 #include "lld/Common/ErrorHandler.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/Endian.h"
@@ -83,6 +84,7 @@ class AArch64 : public TargetInfo {
 uint64_t val) const override;
   RelExpr adjustTlsExpr(RelType type, RelExpr expr) const override;
   void relocateAlloc(InputSectionBase &sec, uint8_t *buf) const override;
+  void applyBranchToBranchOpt() const override;
 
 private:
   void relaxTlsGdToLe(uint8_t *loc, const Relocation &rel, uint64_t val) const;
@@ -975,6 +977,63 @@ void AArch64::relocateAlloc(InputSectionBase &sec, uint8_t 
*buf) const {
   }
 }
 
+static std::optional getControlTransferAddend(InputSection &is,
+Relocation &r) {
+  // Identify a control transfer relocation for the branch-to-branch
+  // optimization. A "control transfer relocation" means a B or BL
+  // target but it also includes relative vtable relocations for example.
+  //
+  // We require the relocation type to be JUMP26, CALL26 or PLT32. With a
+  // relocation type of PLT32 the value may be assumed to be used for branching
+  // directly to the symbol and the addend is only used to produce the 
relocated
+  // value (hence the effective addend is always 0). This is because if a PLT 
is
+  // needed the addend will be added to the address of the PLT, and it doesn't
+  // make sense to branch into the middle of a PLT. For example, relative 
vtable
+  // relocations use PLT32 and 0 or a positive value as the addend but still 
are
+  // used to branch to the symbol.
+  //
+  // With JUMP26 or CALL26 the only reasonable interpret

[llvm-branch-commits] [clang] CodeGen: Fix implementation of __builtin_trivially_relocate. (PR #140312)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/140312

>From 1399ec4fdf8fe08000b590844f4e24c31a310a01 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 21 May 2025 16:20:57 -0700
Subject: [PATCH] Add test with variable count

Created using spr 1.3.6-beta.1
---
 .../CodeGenCXX/cxx2c-trivially-relocatable.cpp | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp 
b/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
index 63f3ba8e74ed5..465e539d363e8 100644
--- a/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
+++ b/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++26 -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 
+typedef __SIZE_TYPE__ size_t;
+
 struct S trivially_relocatable_if_eligible {
 S(const S&);
 ~S();
@@ -8,9 +10,13 @@ struct S trivially_relocatable_if_eligible {
 };
 
 // CHECK: @_Z4testP1SS0_
-// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 8
-// CHECK-NOT: __builtin
-// CHECK: ret
-void test(S* source, S* dest) {
+void test(S* source, S* dest, size_t count) {
+// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 8
+// CHECK-NOT: __builtin
 __builtin_trivially_relocate(dest, source, 1);
+// CHECK: [[A:%.*]] = load i64, ptr %count.addr
+// CHECK: [[M:%.*]] = mul i64 [[A]], 8
+// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 [[M]]
+__builtin_trivially_relocate(dest, source, count);
+// CHECK: ret
 };

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Track if a type is a template or builtin (PR #138067)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From fae895bbea79cc8a7adbf7266f366ecbc205ed91 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Wed, 30 Apr 2025 14:20:40 -0700
Subject: [PATCH] [clang-doc] Track if a type is a template or builtin

Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou 
---
 clang-tools-extra/clang-doc/Representation.h |  3 +++
 clang-tools-extra/clang-doc/Serialize.cpp| 17 -
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index 1673be496b7b2..a3a6217f76bbd 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -164,6 +164,9 @@ struct TypeInfo {
   bool operator==(const TypeInfo &Other) const { return Type == Other.Type; }
 
   Reference Type; // Referenced type in this info.
+
+  bool IsTemplate = false;
+  bool IsBuiltIn = false;
 };
 
 // Represents one template parameter.
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 7e56fe7236479..b6c76c31f0ae0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -405,9 +405,12 @@ static RecordDecl *getRecordDeclForType(const QualType &T) 
{
 static TypeInfo getTypeInfoForType(const QualType &T,
const PrintingPolicy &Policy) {
   const TagDecl *TD = getTagDeclForType(T);
-  if (!TD)
-return TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
-
+  if (!TD) {
+TypeInfo TI = TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
+TI.IsBuiltIn = T->isBuiltinType();
+TI.IsTemplate = T->isTemplateTypeParmType();
+return TI;
+  }
   InfoType IT;
   if (isa(TD)) {
 IT = InfoType::IT_enum;
@@ -416,8 +419,12 @@ static TypeInfo getTypeInfoForType(const QualType &T,
   } else {
 IT = InfoType::IT_default;
   }
-  return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
-T.getAsString(Policy), getInfoRelativePath(TD)));
+  Reference R = Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
+  T.getAsString(Policy), getInfoRelativePath(TD));
+  TypeInfo TI = TypeInfo(R);
+  TI.IsBuiltIn = T->isBuiltinType();
+  TI.IsTemplate = T->isTemplateTypeParmType();
+  return TI;
 }
 
 static bool isPublic(const clang::AccessSpecifier AS,

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


[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement `ResourceRange` as an `IntervalMap` (PR #140957)

2025-05-23 Thread Deric C. via llvm-branch-commits

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


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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Implement setupTemplateValue for HTMLMustacheGenerator (PR #138064)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 011f2973a836c21b3ccc869fa96d64385c5b5b75 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Wed, 30 Apr 2025 08:13:46 -0700
Subject: [PATCH] [clang-doc] Implement setupTemplateValue for
 HTMLMustacheGenerator

This patch implements the business logic for setupTemplateValue, which
was split from #133161. The implementation configures the relative path
relationships between the various HTML components, and prepares them
prior to their use in the generator. The tests here are disabled by
default until we can use lit tests via tool support, since we cannot
read files in the unit tests.

Co-authored-by: Peter Chou 
---
 .../clang-doc/HTMLMustacheGenerator.cpp   |  27 ++-
 .../clang-doc/HTMLMustacheGeneratorTest.cpp   | 193 --
 2 files changed, 199 insertions(+), 21 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 18ee3b8d0fc43..65dc2e93582e8 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -397,7 +397,7 @@ static json::Value extractValue(const RecordInfo &I,
 
   maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
 
-  StringRef BasePath = I.getRelativeFilePath("");
+  SmallString<64> BasePath = I.getRelativeFilePath("");
   extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
   json::Value PublicMembers = Array();
   json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -431,8 +431,28 @@ static json::Value extractValue(const RecordInfo &I,
 
 static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
 Info *I) {
-  return createStringError(inconvertibleErrorCode(),
-   "setupTemplateValue is unimplemented");
+  V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
+  json::Value StylesheetArr = Array();
+  auto InfoPath = I->getRelativeFilePath("");
+  SmallString<128> RelativePath = computeRelativePath("", InfoPath);
+  sys::path::native(RelativePath, sys::path::Style::posix);
+  for (const auto &FilePath : CDCtx.UserStylesheets) {
+SmallString<128> StylesheetPath = RelativePath;
+sys::path::append(StylesheetPath, sys::path::Style::posix,
+  sys::path::filename(FilePath));
+StylesheetArr.getAsArray()->emplace_back(StylesheetPath);
+  }
+  V.getAsObject()->insert({"Stylesheets", StylesheetArr});
+
+  json::Value ScriptArr = Array();
+  for (auto Script : CDCtx.JsScripts) {
+SmallString<128> JsPath = RelativePath;
+sys::path::append(JsPath, sys::path::Style::posix,
+  sys::path::filename(Script));
+ScriptArr.getAsArray()->emplace_back(JsPath);
+  }
+  V.getAsObject()->insert({"Scripts", ScriptArr});
+  return Error::success();
 }
 
 Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -443,6 +463,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, 
raw_ostream &OS,
 extractValue(*static_cast(I), CDCtx);
 if (auto Err = setupTemplateValue(CDCtx, V, I))
   return Err;
+assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
 NamespaceTemplate->render(V, OS);
 break;
   }
diff --git 
a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp 
b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
index 4c8cf4fa7e460..95acd363a958e 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
@@ -20,10 +20,14 @@
 
 using namespace llvm;
 using namespace testing;
+using namespace clang;
 using namespace clang::doc;
 
-static const std::string ClangDocVersion =
-clang::getClangToolFullVersion("clang-doc");
+// FIXME: Don't enable unit tests that can read files. Remove once we can use
+// lit to test these properties.
+#define ENABLE_LOCAL_TEST 0
+
+static const std::string ClangDocVersion = 
getClangToolFullVersion("clang-doc");
 
 static std::unique_ptr getHTMLMustacheGenerator() {
   auto G = findGeneratorByName("mustache");
@@ -91,37 +95,190 @@ TEST(HTMLMustacheGeneratorTest, generateDocs) {
   unittest::TempDir RootTestDirectory("generateDocsTest", /*Unique=*/true);
   CDCtx.OutDirectory = RootTestDirectory.path();
 
+#if ENABLE_LOCAL_TEST
   // FIXME: We can't read files during unit tests. Migrate to lit once
   // tool support lands.
-  // getMustacheHtmlFiles(CLANG_DOC_TEST_ASSET_DIR, CDCtx);
+  getMustacheHtmlFiles(CLANG_DOC_TEST_ASSET_DIR, CDCtx);
 
+  EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
+Succeeded())
+  << "Failed to generate docs.";
+#else
   EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
 Failed())
   << "Failed to generate docs.";
+#endif
 }
 
-TEST(HTMLMustacheGenerat

[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement `ResourceRange` as an `IntervalMap` (PR #140957)

2025-05-23 Thread Deric C. via llvm-branch-commits


@@ -222,6 +222,67 @@ MDNode *MetadataBuilder::BuildDescriptorTableClause(
});
 }
 
+std::optional
+ResourceRange::getOverlapping(const RangeInfo &Info) const {
+  IMap::const_iterator Interval = Intervals.find(Info.LowerBound);
+  if (!Interval.valid() || Info.UpperBound < Interval.start())
+return std::nullopt;
+  return Interval.value();
+}
+
+const RangeInfo *ResourceRange::lookup(uint32_t X) const {
+  return Intervals.lookup(X, nullptr);
+}
+
+std::optional ResourceRange::insert(const RangeInfo &Info) {
+  uint32_t LowerBound = Info.LowerBound;
+  uint32_t UpperBound = Info.UpperBound;
+
+  std::optional Res = std::nullopt;
+  IMap::iterator Interval = Intervals.begin();
+
+  while (true) {
+if (UpperBound < LowerBound)
+  break;
+
+Interval.advanceTo(LowerBound);
+if (!Interval.valid()) // No interval found
+  break;
+
+// Let Interval = [x;y] and [LowerBound;UpperBound] = [a;b] and note that
+// a <= y implicitly from Intervals.find(LowerBound)
+if (UpperBound < Interval.start())
+  break; // found interval does not overlap with inserted one
+
+if (!Res.has_value()) // Update to be the first found intersection
+  Res = Interval.value();
+
+if (Interval.start() <= LowerBound && UpperBound <= Interval.stop()) {
+  // x <= a <= b <= y implies that [a;b] is covered by [x;y]
+  //  -> so we don't need to insert this, report an overlap
+  return Res;
+} else if (LowerBound <= Interval.start() &&
+   Interval.stop() <= UpperBound) {
+  // a <= x <= y <= b implies that [x;y] is covered by [a;b]
+  //  -> so remove the existing interval that we will cover with the
+  //  overwrite
+  Interval.erase();
+} else if (LowerBound < Interval.start() && UpperBound <= Interval.stop()) 
{
+  // a < x <= b <= y implies that [a; x] is not covered but [x;b] is
+  //  -> so set b = x - 1 such that [a;x-1] is now the interval to insert
+  UpperBound = Interval.start() - 1;
+} else if (Interval.start() <= LowerBound && Interval.stop() < UpperBound) 
{
+  // a < x <= b <= y implies that [y; b] is not covered but [a;y] is

Icohedron wrote:

```suggestion
  // x <= a <= y < b implies that [y; b] is not covered but [a;y] is
```

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


[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement `ResourceRange` as an `IntervalMap` (PR #140957)

2025-05-23 Thread Deric C. via llvm-branch-commits


@@ -0,0 +1,177 @@
+//===-- HLSLRootSignatureRangeTest.cpp - RootSignature Range tests 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+#include "gtest/gtest.h"
+
+using namespace llvm::hlsl::rootsig;
+
+namespace {
+
+TEST(HLSLRootSignatureTest, NoOverlappingInsertTests) {
+  // Ensures that there is never a reported overlap
+  ResourceRange::IMap::Allocator Allocator;
+  ResourceRange Range(Allocator);
+
+  RangeInfo A;
+  A.LowerBound = 0;
+  A.UpperBound = 3;
+  EXPECT_EQ(Range.insert(A), std::nullopt);
+
+  RangeInfo B;
+  B.LowerBound = 4;
+  B.UpperBound = 7;
+  EXPECT_EQ(Range.insert(B), std::nullopt);
+
+  RangeInfo C;
+  C.LowerBound = 10;
+  C.UpperBound = RangeInfo::Unbounded;
+  EXPECT_EQ(Range.insert(C), std::nullopt);
+
+  // A = [0;3]
+  EXPECT_EQ(Range.lookup(0), &A);
+  EXPECT_EQ(Range.lookup(2), &A);
+  EXPECT_EQ(Range.lookup(3), &A);
+
+  // B = [4;7]
+  EXPECT_EQ(Range.lookup(4), &B);
+  EXPECT_EQ(Range.lookup(5), &B);
+  EXPECT_EQ(Range.lookup(7), &B);
+
+  EXPECT_EQ(Range.lookup(8), nullptr);
+  EXPECT_EQ(Range.lookup(9), nullptr);
+
+  // C = [10;unbounded]
+  EXPECT_EQ(Range.lookup(10), &C);
+  EXPECT_EQ(Range.lookup(42), &C);
+  EXPECT_EQ(Range.lookup(98237423), &C);
+  EXPECT_EQ(Range.lookup(RangeInfo::Unbounded), &C);
+}
+
+TEST(HLSLRootSignatureTest, SingleOverlappingInsertTests) {
+  // Ensures that we correctly report an overlap when we insert a range that
+  // overlaps with one other range but does not cover (replace) it
+  ResourceRange::IMap::Allocator Allocator;
+  ResourceRange Range(Allocator);
+
+  RangeInfo A;
+  A.LowerBound = 1;
+  A.UpperBound = 5;
+  EXPECT_EQ(Range.insert(A), std::nullopt);
+
+  RangeInfo B;
+  B.LowerBound = 0;
+  B.UpperBound = 2;
+  EXPECT_EQ(Range.insert(B).value(), &A);
+
+  RangeInfo C;
+  C.LowerBound = 4;
+  C.UpperBound = RangeInfo::Unbounded;
+  EXPECT_EQ(Range.insert(C).value(), &A);
+
+  // A = [1;5]
+  EXPECT_EQ(Range.lookup(1), &A);
+  EXPECT_EQ(Range.lookup(2), &A);
+  EXPECT_EQ(Range.lookup(3), &A);
+  EXPECT_EQ(Range.lookup(4), &A);
+  EXPECT_EQ(Range.lookup(5), &A);
+
+  // B = [0;0]
+  EXPECT_EQ(Range.lookup(0), &B);
+
+  // C = [6; unbounded]

Icohedron wrote:

```suggestion
  // C = [6;unbounded]
```

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


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of floats for StaticSampler (PR #140181)

2025-05-23 Thread Deric C. via llvm-branch-commits


@@ -821,22 +873,110 @@ std::optional 
RootSignatureParser::handleUIntLiteral() {
   PP.getSourceManager(), PP.getLangOpts(),
   PP.getTargetInfo(), PP.getDiagnostics());
   if (Literal.hadError)
-return true; // Error has already been reported so just return
+return std::nullopt; // Error has already been reported so just return
 
-  assert(Literal.isIntegerLiteral() && "IsNumberChar will only support 
digits");
+  assert(Literal.isIntegerLiteral() &&
+ "NumSpelling can only consist of digits");
 
   llvm::APSInt Val = llvm::APSInt(32, false);
   if (Literal.GetIntegerValue(Val)) {
 // Report that the value has overflowed
 PP.getDiagnostics().Report(CurToken.TokLoc,
diag::err_hlsl_number_literal_overflow)
-<< 0 << CurToken.NumSpelling;
+<< /*integer type*/ 0 << /*is signed*/ 0;
 return std::nullopt;
   }
 
   return Val.getExtValue();
 }
 
+std::optional RootSignatureParser::handleIntLiteral(bool Negated) {
+  // Parse the numeric value and do semantic checks on its specification
+  clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return std::nullopt; // Error has already been reported so just return
+
+  assert(Literal.isIntegerLiteral() &&
+ "NumSpelling can only consist of digits");
+
+  llvm::APSInt Val = llvm::APSInt(32, true);
+  if (Literal.GetIntegerValue(Val) || INT32_MAX < Val.getExtValue()) {

Icohedron wrote:

nvm. I see why

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


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of floats for StaticSampler (PR #140181)

2025-05-23 Thread Deric C. via llvm-branch-commits

https://github.com/Icohedron edited 
https://github.com/llvm/llvm-project/pull/140181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of floats for StaticSampler (PR #140181)

2025-05-23 Thread Deric C. via llvm-branch-commits


@@ -821,22 +873,110 @@ std::optional 
RootSignatureParser::handleUIntLiteral() {
   PP.getSourceManager(), PP.getLangOpts(),
   PP.getTargetInfo(), PP.getDiagnostics());
   if (Literal.hadError)
-return true; // Error has already been reported so just return
+return std::nullopt; // Error has already been reported so just return
 
-  assert(Literal.isIntegerLiteral() && "IsNumberChar will only support 
digits");
+  assert(Literal.isIntegerLiteral() &&
+ "NumSpelling can only consist of digits");
 
   llvm::APSInt Val = llvm::APSInt(32, false);
   if (Literal.GetIntegerValue(Val)) {
 // Report that the value has overflowed
 PP.getDiagnostics().Report(CurToken.TokLoc,
diag::err_hlsl_number_literal_overflow)
-<< 0 << CurToken.NumSpelling;
+<< /*integer type*/ 0 << /*is signed*/ 0;
 return std::nullopt;
   }
 
   return Val.getExtValue();
 }
 
+std::optional RootSignatureParser::handleIntLiteral(bool Negated) {
+  // Parse the numeric value and do semantic checks on its specification
+  clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return std::nullopt; // Error has already been reported so just return
+
+  assert(Literal.isIntegerLiteral() &&
+ "NumSpelling can only consist of digits");
+
+  llvm::APSInt Val = llvm::APSInt(32, true);
+  if (Literal.GetIntegerValue(Val) || INT32_MAX < Val.getExtValue()) {

Icohedron wrote:

But this code wouldn't allow INT32_MIN to be parsed because `abs(INT32_MIN) > 
INT32_MAX`

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Track if a type is a template or builtin (PR #138067)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From fae895bbea79cc8a7adbf7266f366ecbc205ed91 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Wed, 30 Apr 2025 14:20:40 -0700
Subject: [PATCH] [clang-doc] Track if a type is a template or builtin

Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou 
---
 clang-tools-extra/clang-doc/Representation.h |  3 +++
 clang-tools-extra/clang-doc/Serialize.cpp| 17 -
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index 1673be496b7b2..a3a6217f76bbd 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -164,6 +164,9 @@ struct TypeInfo {
   bool operator==(const TypeInfo &Other) const { return Type == Other.Type; }
 
   Reference Type; // Referenced type in this info.
+
+  bool IsTemplate = false;
+  bool IsBuiltIn = false;
 };
 
 // Represents one template parameter.
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 7e56fe7236479..b6c76c31f0ae0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -405,9 +405,12 @@ static RecordDecl *getRecordDeclForType(const QualType &T) 
{
 static TypeInfo getTypeInfoForType(const QualType &T,
const PrintingPolicy &Policy) {
   const TagDecl *TD = getTagDeclForType(T);
-  if (!TD)
-return TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
-
+  if (!TD) {
+TypeInfo TI = TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
+TI.IsBuiltIn = T->isBuiltinType();
+TI.IsTemplate = T->isTemplateTypeParmType();
+return TI;
+  }
   InfoType IT;
   if (isa(TD)) {
 IT = InfoType::IT_enum;
@@ -416,8 +419,12 @@ static TypeInfo getTypeInfoForType(const QualType &T,
   } else {
 IT = InfoType::IT_default;
   }
-  return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
-T.getAsString(Policy), getInfoRelativePath(TD)));
+  Reference R = Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
+  T.getAsString(Policy), getInfoRelativePath(TD));
+  TypeInfo TI = TypeInfo(R);
+  TI.IsBuiltIn = T->isBuiltinType();
+  TI.IsTemplate = T->isTemplateTypeParmType();
+  return TI;
 }
 
 static bool isPublic(const clang::AccessSpecifier AS,

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Update clang-doc tool to enable mustache templates (PR #138066)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 5dd55e81bd0d4f18b880c450e21e9faefcd38327 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 29 Apr 2025 18:08:03 -0700
Subject: [PATCH] [clang-doc] Update clang-doc tool to enable mustache
 templates

This patch adds a command line option and enables the Mustache template
HTML backend. This allows users to use the new, more flexible templates
over the old and cumbersome HTML output. Split from #133161.

Co-authored-by: Peter Chou 
---
 .../clang-doc/tool/ClangDocMain.cpp   |  80 +--
 .../clang-doc/basic-project.mustache.test | 481 ++
 2 files changed, 531 insertions(+), 30 deletions(-)
 create mode 100644 clang-tools-extra/test/clang-doc/basic-project.mustache.test

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 8e8f7053a8f87..41fbe87a713d9 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -18,20 +18,14 @@
 
//===--===//
 
 #include "BitcodeReader.h"
-#include "BitcodeWriter.h"
 #include "ClangDoc.h"
 #include "Generators.h"
 #include "Representation.h"
-#include "clang/AST/AST.h"
-#include "clang/AST/Decl.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "support/Utils.h"
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
-#include "clang/Driver/Options.h"
-#include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
@@ -110,22 +104,19 @@ static llvm::cl::opt 
RepositoryCodeLinePrefix(
 llvm::cl::desc("Prefix of line code for repository."),
 llvm::cl::cat(ClangDocCategory));
 
-enum OutputFormatTy {
-  md,
-  yaml,
-  html,
-};
-
-static llvm::cl::opt
-FormatEnum("format", llvm::cl::desc("Format for outputted docs."),
-   llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
-   "Documentation in YAML format."),
-clEnumValN(OutputFormatTy::md, "md",
-   "Documentation in MD format."),
-clEnumValN(OutputFormatTy::html, "html",
-   "Documentation in HTML format.")),
-   llvm::cl::init(OutputFormatTy::yaml),
-   llvm::cl::cat(ClangDocCategory));
+enum OutputFormatTy { md, yaml, html, mustache };
+
+static llvm::cl::opt FormatEnum(
+"format", llvm::cl::desc("Format for outputted docs."),
+llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
+"Documentation in YAML format."),
+ clEnumValN(OutputFormatTy::md, "md",
+"Documentation in MD format."),
+ clEnumValN(OutputFormatTy::html, "html",
+"Documentation in HTML format."),
+ clEnumValN(OutputFormatTy::mustache, "mustache",
+"Documentation in mustache HTML format")),
+llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory));
 
 static std::string getFormatString() {
   switch (FormatEnum) {
@@ -135,6 +126,8 @@ static std::string getFormatString() {
 return "md";
   case OutputFormatTy::html:
 return "html";
+  case OutputFormatTy::mustache:
+return "mustache";
   }
   llvm_unreachable("Unknown OutputFormatTy");
 }
@@ -178,13 +171,9 @@ static llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
-  llvm::SmallString<128> DefaultStylesheet;
-  llvm::sys::path::native(AssetsPath, DefaultStylesheet);
-  llvm::sys::path::append(DefaultStylesheet,
-  "clang-doc-default-stylesheet.css");
-  llvm::SmallString<128> IndexJS;
-  llvm::sys::path::native(AssetsPath, IndexJS);
-  llvm::sys::path::append(IndexJS, "index.js");
+  llvm::SmallString<128> DefaultStylesheet =
+  appendPathNative(AssetsPath, "clang-doc-default-stylesheet.css");
+  llvm::SmallString<128> IndexJS = appendPathNative(AssetsPath, "index.js");
 
   if (!llvm::sys::fs::is_regular_file(IndexJS))
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -215,6 +204,30 @@ static llvm::Error getHtmlAssetFiles(const char *Argv0,
   return getDefaultAssetFiles(Argv0, CDCtx);
 }
 
+static llvm::Error getMustacheHtmlFiles(const char *Argv0,
+clang::doc::ClangDocContext &CDCtx) {
+  bool IsDir = llvm::sys::fs::is_direct

[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement `ResourceRange` as an `IntervalMap` (PR #140957)

2025-05-23 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/140957

>From a3240de319d3ef455b5db83b66b5bd601cecc0b3 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Tue, 20 May 2025 19:47:29 +
Subject: [PATCH 1/2] [HLSL][RootSignature] Implement resource register
 validation

---
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  56 ++
 llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp  |  61 ++
 llvm/unittests/Frontend/CMakeLists.txt|   1 +
 .../Frontend/HLSLRootSignatureRangesTest.cpp  | 177 ++
 4 files changed, 295 insertions(+)
 create mode 100644 llvm/unittests/Frontend/HLSLRootSignatureRangesTest.cpp

diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
index 98fa5f09429e3..3e5054566052b 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -15,6 +15,7 @@
 #define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntervalMap.h"
 #include "llvm/Support/DXILABI.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -198,6 +199,61 @@ class MetadataBuilder {
   SmallVector GeneratedMetadata;
 };
 
+// RangeInfo holds the information to correctly construct a ResourceRange
+// and retains this information to be used for displaying a better diagnostic
+struct RangeInfo {
+  const static uint32_t Unbounded = static_cast(-1);
+
+  uint32_t LowerBound;
+  uint32_t UpperBound;
+};
+
+class ResourceRange {
+public:
+  using IMap = llvm::IntervalMap>;
+
+private:
+  IMap Intervals;
+
+public:
+  ResourceRange(IMap::Allocator &Allocator) : Intervals(IMap(Allocator)) {}
+
+  // Returns a reference to the first RangeInfo that overlaps with
+  // [Info.LowerBound;Info.UpperBound], or, std::nullopt if there is no overlap
+  std::optional getOverlapping(const RangeInfo &Info) const;
+
+  // Return the mapped RangeInfo at X or nullptr if no mapping exists
+  const RangeInfo *lookup(uint32_t X) const;
+
+  // Insert the required (sub-)intervals such that the interval of [a;b] =
+  // [Info.LowerBound, Info.UpperBound] is covered and points to a valid
+  // RangeInfo &.
+  //
+  // For instance consider the following chain of inserting RangeInfos with the
+  // intervals denoting the Lower/Upper-bounds:
+  //
+  // A = [0;2]
+  //   insert(A) -> false
+  //   intervals: [0;2] -> &A
+  // B = [5;7]
+  //   insert(B) -> false
+  //   intervals: [0;2] -> &A, [5;7] -> &B
+  // C = [4;7]
+  //   insert(C) -> true
+  //   intervals: [0;2] -> &A, [4;7] -> &C
+  // D = [1;5]
+  //   insert(D) -> true
+  //   intervals: [0;2] -> &A, [3;3] -> &D, [4;7] -> &C
+  // E = [0;unbounded]
+  //   insert(E) -> true
+  //   intervals: [0;unbounded] -> E
+  //
+  // Returns if the first overlapping range when inserting
+  // (same return as getOverlapping)
+  std::optional insert(const RangeInfo &Info);
+};
+
 } // namespace rootsig
 } // namespace hlsl
 } // namespace llvm
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp 
b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index abf076944b273..76fe09e4dc3ee 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -222,6 +222,67 @@ MDNode *MetadataBuilder::BuildDescriptorTableClause(
});
 }
 
+std::optional
+ResourceRange::getOverlapping(const RangeInfo &Info) const {
+  IMap::const_iterator Interval = Intervals.find(Info.LowerBound);
+  if (!Interval.valid() || Info.UpperBound < Interval.start())
+return std::nullopt;
+  return Interval.value();
+}
+
+const RangeInfo *ResourceRange::lookup(uint32_t X) const {
+  return Intervals.lookup(X, nullptr);
+}
+
+std::optional ResourceRange::insert(const RangeInfo &Info) {
+  uint32_t LowerBound = Info.LowerBound;
+  uint32_t UpperBound = Info.UpperBound;
+
+  std::optional Res = std::nullopt;
+  IMap::iterator Interval = Intervals.begin();
+
+  while (true) {
+if (UpperBound < LowerBound)
+  break;
+
+Interval.advanceTo(LowerBound);
+if (!Interval.valid()) // No interval found
+  break;
+
+// Let Interval = [x;y] and [LowerBound;UpperBound] = [a;b] and note that
+// a <= y implicitly from Intervals.find(LowerBound)
+if (UpperBound < Interval.start())
+  break; // found interval does not overlap with inserted one
+
+if (!Res.has_value()) // Update to be the first found intersection
+  Res = Interval.value();
+
+if (Interval.start() <= LowerBound && UpperBound <= Interval.stop()) {
+  // x <= a <= b <= y implies that [a;b] is covered by [x;y]
+  //  -> so we don't need to insert this, report an overlap
+  return Res;
+} else if (LowerBound <= Interval.start() &&
+   Interval.stop() <= UpperBound) {
+  // a <= x <= y <= b implies that [x;y] is covered by [a;b]
+  //  -> so remove the existing interval that we will cover with the
+  //  overwrite
+  Interval.e

[llvm-branch-commits] [clang-tools-extra] [clang-doc] Update clang-doc tool to enable mustache templates (PR #138066)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 5dd55e81bd0d4f18b880c450e21e9faefcd38327 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 29 Apr 2025 18:08:03 -0700
Subject: [PATCH] [clang-doc] Update clang-doc tool to enable mustache
 templates

This patch adds a command line option and enables the Mustache template
HTML backend. This allows users to use the new, more flexible templates
over the old and cumbersome HTML output. Split from #133161.

Co-authored-by: Peter Chou 
---
 .../clang-doc/tool/ClangDocMain.cpp   |  80 +--
 .../clang-doc/basic-project.mustache.test | 481 ++
 2 files changed, 531 insertions(+), 30 deletions(-)
 create mode 100644 clang-tools-extra/test/clang-doc/basic-project.mustache.test

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 8e8f7053a8f87..41fbe87a713d9 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -18,20 +18,14 @@
 
//===--===//
 
 #include "BitcodeReader.h"
-#include "BitcodeWriter.h"
 #include "ClangDoc.h"
 #include "Generators.h"
 #include "Representation.h"
-#include "clang/AST/AST.h"
-#include "clang/AST/Decl.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "support/Utils.h"
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
-#include "clang/Driver/Options.h"
-#include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
@@ -110,22 +104,19 @@ static llvm::cl::opt 
RepositoryCodeLinePrefix(
 llvm::cl::desc("Prefix of line code for repository."),
 llvm::cl::cat(ClangDocCategory));
 
-enum OutputFormatTy {
-  md,
-  yaml,
-  html,
-};
-
-static llvm::cl::opt
-FormatEnum("format", llvm::cl::desc("Format for outputted docs."),
-   llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
-   "Documentation in YAML format."),
-clEnumValN(OutputFormatTy::md, "md",
-   "Documentation in MD format."),
-clEnumValN(OutputFormatTy::html, "html",
-   "Documentation in HTML format.")),
-   llvm::cl::init(OutputFormatTy::yaml),
-   llvm::cl::cat(ClangDocCategory));
+enum OutputFormatTy { md, yaml, html, mustache };
+
+static llvm::cl::opt FormatEnum(
+"format", llvm::cl::desc("Format for outputted docs."),
+llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
+"Documentation in YAML format."),
+ clEnumValN(OutputFormatTy::md, "md",
+"Documentation in MD format."),
+ clEnumValN(OutputFormatTy::html, "html",
+"Documentation in HTML format."),
+ clEnumValN(OutputFormatTy::mustache, "mustache",
+"Documentation in mustache HTML format")),
+llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory));
 
 static std::string getFormatString() {
   switch (FormatEnum) {
@@ -135,6 +126,8 @@ static std::string getFormatString() {
 return "md";
   case OutputFormatTy::html:
 return "html";
+  case OutputFormatTy::mustache:
+return "mustache";
   }
   llvm_unreachable("Unknown OutputFormatTy");
 }
@@ -178,13 +171,9 @@ static llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
-  llvm::SmallString<128> DefaultStylesheet;
-  llvm::sys::path::native(AssetsPath, DefaultStylesheet);
-  llvm::sys::path::append(DefaultStylesheet,
-  "clang-doc-default-stylesheet.css");
-  llvm::SmallString<128> IndexJS;
-  llvm::sys::path::native(AssetsPath, IndexJS);
-  llvm::sys::path::append(IndexJS, "index.js");
+  llvm::SmallString<128> DefaultStylesheet =
+  appendPathNative(AssetsPath, "clang-doc-default-stylesheet.css");
+  llvm::SmallString<128> IndexJS = appendPathNative(AssetsPath, "index.js");
 
   if (!llvm::sys::fs::is_regular_file(IndexJS))
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -215,6 +204,30 @@ static llvm::Error getHtmlAssetFiles(const char *Argv0,
   return getDefaultAssetFiles(Argv0, CDCtx);
 }
 
+static llvm::Error getMustacheHtmlFiles(const char *Argv0,
+clang::doc::ClangDocContext &CDCtx) {
+  bool IsDir = llvm::sys::fs::is_direct

[llvm-branch-commits] [clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 7deaf5aea3a20dc34f7eab13244e161da74a3148 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 29 Apr 2025 18:31:54 -0700
Subject: [PATCH] [clang-doc] Update serializer for improved template handling

This patch updates Serialize.cpp to serialize more data about C++
templates, which are supported by the new mustache HTML template.
Split from #133161.

Co-authored-by: Peter Chou 
---
 clang-tools-extra/clang-doc/Representation.h |   3 +
 clang-tools-extra/clang-doc/Serialize.cpp| 203 ++-
 2 files changed, 198 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a2e01719eb59e..1673be496b7b2 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -363,6 +363,9 @@ struct FunctionInfo : public SymbolInfo {
   // specializations.
   SmallString<16> FullName;
 
+  // Function Prototype
+  SmallString<256> Prototype;
+
   // When present, this function is a template or specialization.
   std::optional Template;
 };
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index fe4ef9c50cc12..7e56fe7236479 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -8,10 +8,10 @@
 
 #include "Serialize.h"
 #include "BitcodeWriter.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Comment.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/SHA1.h"
 
@@ -35,6 +35,169 @@ static void populateMemberTypeInfo(RecordInfo &I, 
AccessSpecifier &Access,
const DeclaratorDecl *D,
bool IsStatic = false);
 
+static void getTemplateParameters(const TemplateParameterList *TemplateParams,
+  llvm::raw_ostream &Stream) {
+  Stream << "template <";
+
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0)
+  Stream << ", ";
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename())
+Stream << "typename";
+  else
+Stream << "class";
+  if (TTP->isParameterPack())
+Stream << "...";
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP =
+   llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack())
+Stream << "...";
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD =
+   llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including
+// Full Decl
+static llvm::SmallString<256>
+getFunctionPrototype(const FunctionDecl *FuncDecl) {
+  llvm::SmallString<256> Result;
+  llvm::raw_svector_ostream Stream(Result);
+  const ASTContext &Ctx = FuncDecl->getASTContext();
+  const auto *Method = llvm::dyn_cast(FuncDecl);
+  // If it's a templated function, handle the template parameters
+  if (const auto *TmplDecl = FuncDecl->getDescribedTemplate())
+getTemplateParameters(TmplDecl->getTemplateParameters(), Stream);
+
+  // If it's a virtual method
+  if (Method && Method->isVirtual())
+Stream << "virtual ";
+
+  // Print return type
+  FuncDecl->getReturnType().print(Stream, Ctx.getPrintingPolicy());
+
+  // Print function name
+  Stream << " " << FuncDecl->getNameAsString() << "(";
+
+  // Print parameter list with types, names, and default values
+  for (unsigned I = 0; I < FuncDecl->getNumParams(); ++I) {
+if (I > 0)
+  Stream << ", ";
+const ParmVarDecl *ParamDecl = FuncDecl->getParamDecl(I);
+QualType ParamType = ParamDecl->getType();
+ParamType.print(Stream, Ctx.getPrintingPolicy());
+
+// Print parameter name if it has one
+if (!ParamDecl->getName().empty())
+  Stream << " " << ParamDecl->getNameAsString();
+
+// Print default argument if it exists
+if (ParamDecl->hasDefaultArg()) {
+  const Expr *DefaultArg = ParamDecl->getDefaultArg();
+  if (DefaultArg) {
+Stream << " = ";
+DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
+  }
+}
+  }
+
+  // If it is a variadic function, add '...'
+  if (FuncDecl->isVariadic()) {
+if (FuncDecl->getNumParams() > 0)
+  Stream << ", ";
+Stream << "...";
+  }
+
+  Stream << ")";
+
+  // If it's a const method, add 'const' qualifier
+  if (Method) {
+if (Method->size_overridden_methods())
+   

[llvm-branch-commits] [clang-tools-extra] [clang-doc] Implement setupTemplateValue for HTMLMustacheGenerator (PR #138064)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

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

>From 011f2973a836c21b3ccc869fa96d64385c5b5b75 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Wed, 30 Apr 2025 08:13:46 -0700
Subject: [PATCH] [clang-doc] Implement setupTemplateValue for
 HTMLMustacheGenerator

This patch implements the business logic for setupTemplateValue, which
was split from #133161. The implementation configures the relative path
relationships between the various HTML components, and prepares them
prior to their use in the generator. The tests here are disabled by
default until we can use lit tests via tool support, since we cannot
read files in the unit tests.

Co-authored-by: Peter Chou 
---
 .../clang-doc/HTMLMustacheGenerator.cpp   |  27 ++-
 .../clang-doc/HTMLMustacheGeneratorTest.cpp   | 193 --
 2 files changed, 199 insertions(+), 21 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 18ee3b8d0fc43..65dc2e93582e8 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -397,7 +397,7 @@ static json::Value extractValue(const RecordInfo &I,
 
   maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
 
-  StringRef BasePath = I.getRelativeFilePath("");
+  SmallString<64> BasePath = I.getRelativeFilePath("");
   extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
   json::Value PublicMembers = Array();
   json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -431,8 +431,28 @@ static json::Value extractValue(const RecordInfo &I,
 
 static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
 Info *I) {
-  return createStringError(inconvertibleErrorCode(),
-   "setupTemplateValue is unimplemented");
+  V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
+  json::Value StylesheetArr = Array();
+  auto InfoPath = I->getRelativeFilePath("");
+  SmallString<128> RelativePath = computeRelativePath("", InfoPath);
+  sys::path::native(RelativePath, sys::path::Style::posix);
+  for (const auto &FilePath : CDCtx.UserStylesheets) {
+SmallString<128> StylesheetPath = RelativePath;
+sys::path::append(StylesheetPath, sys::path::Style::posix,
+  sys::path::filename(FilePath));
+StylesheetArr.getAsArray()->emplace_back(StylesheetPath);
+  }
+  V.getAsObject()->insert({"Stylesheets", StylesheetArr});
+
+  json::Value ScriptArr = Array();
+  for (auto Script : CDCtx.JsScripts) {
+SmallString<128> JsPath = RelativePath;
+sys::path::append(JsPath, sys::path::Style::posix,
+  sys::path::filename(Script));
+ScriptArr.getAsArray()->emplace_back(JsPath);
+  }
+  V.getAsObject()->insert({"Scripts", ScriptArr});
+  return Error::success();
 }
 
 Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -443,6 +463,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, 
raw_ostream &OS,
 extractValue(*static_cast(I), CDCtx);
 if (auto Err = setupTemplateValue(CDCtx, V, I))
   return Err;
+assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
 NamespaceTemplate->render(V, OS);
 break;
   }
diff --git 
a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp 
b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
index 4c8cf4fa7e460..95acd363a958e 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
@@ -20,10 +20,14 @@
 
 using namespace llvm;
 using namespace testing;
+using namespace clang;
 using namespace clang::doc;
 
-static const std::string ClangDocVersion =
-clang::getClangToolFullVersion("clang-doc");
+// FIXME: Don't enable unit tests that can read files. Remove once we can use
+// lit to test these properties.
+#define ENABLE_LOCAL_TEST 0
+
+static const std::string ClangDocVersion = 
getClangToolFullVersion("clang-doc");
 
 static std::unique_ptr getHTMLMustacheGenerator() {
   auto G = findGeneratorByName("mustache");
@@ -91,37 +95,190 @@ TEST(HTMLMustacheGeneratorTest, generateDocs) {
   unittest::TempDir RootTestDirectory("generateDocsTest", /*Unique=*/true);
   CDCtx.OutDirectory = RootTestDirectory.path();
 
+#if ENABLE_LOCAL_TEST
   // FIXME: We can't read files during unit tests. Migrate to lit once
   // tool support lands.
-  // getMustacheHtmlFiles(CLANG_DOC_TEST_ASSET_DIR, CDCtx);
+  getMustacheHtmlFiles(CLANG_DOC_TEST_ASSET_DIR, CDCtx);
 
+  EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
+Succeeded())
+  << "Failed to generate docs.";
+#else
   EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
 Failed())
   << "Failed to generate docs.";
+#endif
 }
 
-TEST(HTMLMustacheGenerat

[llvm-branch-commits] [clang-tools-extra] [clang-doc] Implement setupTemplateValue for HTMLMustacheGenerator (PR #138064)

2025-05-23 Thread Petr Hosek via llvm-branch-commits

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


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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] Implement setupTemplateValue for HTMLMustacheGenerator (PR #138064)

2025-05-23 Thread Paul Kirth via llvm-branch-commits

ilovepi wrote:

### Merge activity

* **May 23, 10:52 PM UTC**: A user started a stack merge that includes this 
pull request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/138064).


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


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits


@@ -7538,6 +7538,14 @@ static bool IsEligibleForTrivialRelocation(Sema &SemaRef,
 if (!SemaRef.IsCXXTriviallyRelocatableType(Field->getType()))
   return false;
   }
+
+  // FIXME: PFP should not affect trivial relocatability, instead it should
+  // affect the implementation of std::trivially_relocate. See:
+  // 
https://discourse.llvm.org/t/rfc-structure-protection-a-family-of-uaf-mitigation-techniques/8/16?u=pcc
+  if (!SemaRef.Context.arePFPFieldsTriviallyRelocatable(D) &&

pcc wrote:

Looking at the code again: `IsCXXTriviallyRelocatableType(QualType Type)` is 
already returning false as a result of this change because it calls 
`IsCXXTriviallyRelocatableType(Sema &S, const CXXRecordDecl *RD)` if the base 
type is determined to be a record type. That function will call 
`CheckCXX2CRelocatableAndReplaceable` if the result is not cached. 
`CheckCXX2CRelocatableAndReplaceable` will use the code that I am modifying to 
set `CXXRecordDeclRelocationInfo::IsRelocatable` which will become the return 
value of  `IsCXXTriviallyRelocatableType(Sema &S, const CXXRecordDecl *RD)`. So 
I think this is the right place to make the change and PAuth ABI should likely 
move to the same place if it wants to cache the result.

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


[llvm-branch-commits] [llvm] a169f5c - Correct position of CFI Instruction for Pointer Authentication"

2025-05-23 Thread Tom Stellard via llvm-branch-commits

Author: Daniel Kiss
Date: 2025-05-23T18:16:24-07:00
New Revision: a169f5ca4e4fdd3e55baef9e69a3fa92e79d7b4a

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

LOG: Correct position of CFI Instruction for Pointer Authentication"

This a partial of reverts commit 0b73b5af60f2c544892b9dd68b4fa43eeff52fc1.
Fixes #137802

Added: 


Modified: 
llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll

llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-diff-scope-same-key.ll
llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-non-leaf.ll
llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-regsave.mir

llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-diff-key.ll
llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-sp-mod.mir
llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-subtarget.ll
llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-thunk.ll
llvm/test/CodeGen/AArch64/pacbti-llvm-generated-funcs-2.ll
llvm/test/CodeGen/AArch64/sign-return-address-cfi-negate-ra-state.ll
llvm/test/CodeGen/AArch64/sign-return-address.ll
llvm/test/CodeGen/MIR/AArch64/return-address-signing.mir

Removed: 




diff  --git a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp 
b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
index c3bc70ad6f427..aba84574c7526 100644
--- a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
+++ b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
@@ -152,12 +152,15 @@ void AArch64PointerAuth::signLR(MachineFunction &MF,
 ->setPreInstrSymbol(MF, MFnI.getSigningInstrLabel());
   } else {
 BuildPACM(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameSetup);
-emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameSetup, EmitCFI);
+if (MFnI.branchProtectionPAuthLR())
+  emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameSetup, EmitCFI);
 BuildMI(MBB, MBBI, DL,
 TII->get(MFnI.shouldSignWithBKey() ? AArch64::PACIBSP
: AArch64::PACIASP))
 .setMIFlag(MachineInstr::FrameSetup)
 ->setPreInstrSymbol(MF, MFnI.getSigningInstrLabel());
+if (!MFnI.branchProtectionPAuthLR())
+  emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameSetup, EmitCFI);
   }
 
   if (!EmitCFI && NeedsWinCFI) {
@@ -220,11 +223,15 @@ void AArch64PointerAuth::authenticateLR(
   .setMIFlag(MachineInstr::FrameDestroy);
 } else {
   BuildPACM(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy, PACSym);
-  emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy,
- EmitAsyncCFI);
+  if (MFnI->branchProtectionPAuthLR())
+emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy,
+   EmitAsyncCFI);
   BuildMI(MBB, MBBI, DL,
   TII->get(UseBKey ? AArch64::AUTIBSP : AArch64::AUTIASP))
   .setMIFlag(MachineInstr::FrameDestroy);
+  if (!MFnI->branchProtectionPAuthLR())
+emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy,
+   EmitAsyncCFI);
 }
 
 if (NeedsWinCFI) {

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll 
b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
index e7de54036245a..4bbbe40176313 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
@@ -9,9 +9,9 @@ define void @a() "sign-return-address"="all" 
"sign-return-address-key"="b_key" {
 ; CHECK-LABEL: a: // @a
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:  .cfi_b_key_frame
-; CHECK-NEXT:  .cfi_negate_ra_state
 ; V8A-NEXT:hint #27
 ; V83A-NEXT:   pacibsp
+; CHECK-NEXT:  .cfi_negate_ra_state
   %1 = alloca i32, align 4
   %2 = alloca i32, align 4
   %3 = alloca i32, align 4

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-
diff -scope-same-key.ll 
b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-
diff -scope-same-key.ll
index a26dda1d5c1f1..6a11bef08c740 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-
diff -scope-same-key.ll
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-
diff -scope-same-key.ll
@@ -5,9 +5,9 @@
 
 define void @a() "sign-return-address"="all" {
 ; CHECK-LABEL:  a: // @a
-; CHECK:  .cfi_negate_ra_state
-; V8A-NEXT:  hint #25
-; V83A-NEXT: paciasp
+; V8A:  hint #25
+; V83A: paciasp
+; CHECK-NEXT:  .cfi_negate_ra_state
   %1 = alloca i32, align 4
   %2 = alloca i32, align 4
   %3 = alloca i32, 

[llvm-branch-commits] [AArch64] Correct position of CFI Instruction for Pointer Authentication (PR #137800)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

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


[llvm-branch-commits] [AArch64] Correct position of CFI Instruction for Pointer Authentication (PR #137800)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/137800


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


[llvm-branch-commits] [AArch64] Correct position of CFI Instruction for Pointer Authentication (PR #137800)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

Merged as a169f5ca4e4fdd3e55baef9e69a3fa92e79d7b4a.

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


[llvm-branch-commits] LowerTypeTests: Set small code model on imported globals. (PR #141324)

2025-05-23 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Peter Collingbourne (pcc)


Changes

This is either a vtable (in .data.rel.ro) or a jump table (in .text).
Either way it's expected to be in the low 2 GiB, so set the small
code model.


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


2 Files Affected:

- (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+8-2) 
- (modified) llvm/test/Transforms/LowerTypeTests/import.ll (+7-7) 


``diff
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp 
b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 51667038575cc..428c4641a7f56 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1019,8 +1019,14 @@ LowerTypeTestsModule::importTypeId(StringRef TypeId) {
 return C;
   };
 
-  if (TIL.TheKind != TypeTestResolution::Unsat)
-TIL.OffsetedGlobal = ImportGlobal("global_addr");
+  if (TIL.TheKind != TypeTestResolution::Unsat) {
+auto *GV = ImportGlobal("global_addr");
+// This is either a vtable (in .data.rel.ro) or a jump table (in .text).
+// Either way it's expected to be in the low 2 GiB, so set the small code
+// model.
+GV->setCodeModel(CodeModel::Small);
+TIL.OffsetedGlobal = GV;
+  }
 
   if (TIL.TheKind == TypeTestResolution::ByteArray ||
   TIL.TheKind == TypeTestResolution::Inline ||
diff --git a/llvm/test/Transforms/LowerTypeTests/import.ll 
b/llvm/test/Transforms/LowerTypeTests/import.ll
index 1eff4df97..c6566b84a4361 100644
--- a/llvm/test/Transforms/LowerTypeTests/import.ll
+++ b/llvm/test/Transforms/LowerTypeTests/import.ll
@@ -6,29 +6,29 @@ target datalayout = "e-p:64:64"
 
 declare i1 @llvm.type.test(ptr %ptr, metadata %bitset) nounwind readnone
 
-; CHECK-DAG: @__typeid_single_global_addr = external hidden global [0 x i8]
-; CHECK-DAG: @__typeid_inline6_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_single_global_addr = external hidden global [0 x i8], 
code_model "small"
+; CHECK-DAG: @__typeid_inline6_global_addr = external hidden global [0 x i8], 
code_model "small"
 ; X86-DAG: @__typeid_inline6_align = external hidden global [0 x i8], 
!absolute_symbol !0
 ; X86-DAG: @__typeid_inline6_size_m1 = external hidden global [0 x i8], 
!absolute_symbol !1
 ; X86-DAG: @__typeid_inline6_inline_bits = external hidden global [0 x i8], 
!absolute_symbol !2
-; CHECK-DAG: @__typeid_inline5_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_inline5_global_addr = external hidden global [0 x i8], 
code_model "small"
 ; X86-DAG: @__typeid_inline5_align = external hidden global [0 x i8], 
!absolute_symbol !0
 ; X86-DAG: @__typeid_inline5_size_m1 = external hidden global [0 x i8], 
!absolute_symbol !3
 ; X86-DAG: @__typeid_inline5_inline_bits = external hidden global [0 x i8], 
!absolute_symbol !4
-; CHECK-DAG: @__typeid_bytearray32_global_addr = external hidden global [0 x 
i8]
+; CHECK-DAG: @__typeid_bytearray32_global_addr = external hidden global [0 x 
i8], code_model "small"
 ; X86-DAG: @__typeid_bytearray32_align = external hidden global [0 x i8], 
!absolute_symbol !0
 ; X86-DAG: @__typeid_bytearray32_size_m1 = external hidden global [0 x i8], 
!absolute_symbol !4
 ; CHECK-DAG: @__typeid_bytearray32_byte_array = external hidden global [0 x i8]
 ; X86-DAG: @__typeid_bytearray32_bit_mask = external hidden global [0 x i8], 
!absolute_symbol !0
-; CHECK-DAG: @__typeid_bytearray7_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_bytearray7_global_addr = external hidden global [0 x 
i8], code_model "small"
 ; X86-DAG: @__typeid_bytearray7_align = external hidden global [0 x i8], 
!absolute_symbol !0
 ; X86-DAG: @__typeid_bytearray7_size_m1 = external hidden global [0 x i8], 
!absolute_symbol !5
 ; CHECK-DAG: @__typeid_bytearray7_byte_array = external hidden global [0 x i8]
 ; X86-DAG: @__typeid_bytearray7_bit_mask = external hidden global [0 x i8], 
!absolute_symbol !0
-; CHECK-DAG: @__typeid_allones32_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_allones32_global_addr = external hidden global [0 x 
i8], code_model "small"
 ; X86-DAG: @__typeid_allones32_align = external hidden global [0 x i8], 
!absolute_symbol !0
 ; X86-DAG: @__typeid_allones32_size_m1 = external hidden global [0 x i8], 
!absolute_symbol !4
-; CHECK-DAG: @__typeid_allones7_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_allones7_global_addr = external hidden global [0 x i8], 
code_model "small"
 ; X86-DAG: @__typeid_allones7_align = external hidden global [0 x i8], 
!absolute_symbol !0
 ; X86-DAG: @__typeid_allones7_size_m1 = external hidden global [0 x i8], 
!absolute_symbol !5
 

``




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


[llvm-branch-commits] Transforms: Have CSE/GVN/LICM check isProfitableToHoist() before hoisting. (PR #141325)

2025-05-23 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Peter Collingbourne (pcc)


Changes

LICM hoists instructions into the preheader, and CSE and GVN
can effectively perform a hoist by replacing an instruction with
one from another basic block, all of which can lead to the same
kinds of pessimizations that isProfitableToHoist() is intended to
prevent. Therefore, call the hook from all these passes.

This will be tested in the subsequent change that adds a previously
hoistable case and verifies that no optimization pass hoists it.


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


5 Files Affected:

- (modified) llvm/include/llvm/Transforms/Scalar/GVN.h (+4-1) 
- (modified) llvm/include/llvm/Transforms/Utils/LoopUtils.h (+4-4) 
- (modified) llvm/lib/Transforms/Scalar/EarlyCSE.cpp (+10) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+18-2) 
- (modified) llvm/lib/Transforms/Scalar/LICM.cpp (+11-10) 


``diff
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h 
b/llvm/include/llvm/Transforms/Scalar/GVN.h
index 25b042eebf664..b7a2ced3a7a21 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -53,6 +53,7 @@ class NonLocalDepResult;
 class OptimizationRemarkEmitter;
 class PHINode;
 class TargetLibraryInfo;
+class TargetTransformInfo;
 class Value;
 /// A private "module" namespace for types and utilities used by GVN. These
 /// are implementation details and should not be used by clients.
@@ -226,6 +227,7 @@ class GVNPass : public PassInfoMixin {
   MemoryDependenceResults *MD = nullptr;
   DominatorTree *DT = nullptr;
   const TargetLibraryInfo *TLI = nullptr;
+  const TargetTransformInfo *TTI = nullptr;
   AssumptionCache *AC = nullptr;
   SetVector DeadBlocks;
   OptimizationRemarkEmitter *ORE = nullptr;
@@ -318,7 +320,8 @@ class GVNPass : public PassInfoMixin {
   using UnavailBlkVect = SmallVector;
 
   bool runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
-   const TargetLibraryInfo &RunTLI, AAResults &RunAA,
+   const TargetLibraryInfo &RunTLI,
+   const TargetTransformInfo &RunTTI, AAResults &RunAA,
MemoryDependenceResults *RunMD, LoopInfo &LI,
OptimizationRemarkEmitter *ORE, MemorySSA *MSSA = nullptr);
 
diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h 
b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 416a0a70325d1..4fa8445ce5cc8 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -175,10 +175,10 @@ bool sinkRegionForLoopNest(DomTreeNode *, AAResults *, 
LoopInfo *,
 /// \p AllowSpeculation is whether values should be hoisted even if they are 
not
 /// guaranteed to execute in the loop, but are safe to speculatively execute.
 bool hoistRegion(DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *,
- AssumptionCache *, TargetLibraryInfo *, Loop *,
- MemorySSAUpdater &, ScalarEvolution *, ICFLoopSafetyInfo *,
- SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *, bool,
- bool AllowSpeculation);
+ AssumptionCache *, TargetLibraryInfo *, TargetTransformInfo *,
+ Loop *, MemorySSAUpdater &, ScalarEvolution *,
+ ICFLoopSafetyInfo *, SinkAndHoistLICMFlags &,
+ OptimizationRemarkEmitter *, bool, bool AllowSpeculation);
 
 /// Return true if the induction variable \p IV in a Loop whose latch is
 /// \p LatchBlock would become dead if the exit test \p Cond were removed.
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp 
b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 1e378369166c0..16faf72c488fe 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -1534,6 +1534,16 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
   }
   // See if the instruction has an available value.  If so, use it.
   if (Value *V = AvailableValues.lookup(&Inst)) {
+// If this CSE would effectively hoist the instruction and that's known
+// to be unprofitable, don't do it. Remember the instruction so that it
+// can be used by other instructions in the same block.
+if (auto *ReplI = dyn_cast(V)) {
+  if (ReplI->getParent() != Inst.getParent() &&
+  !TTI.isProfitableToHoist(&Inst)) {
+AvailableValues.insert(&Inst, &Inst);
+continue;
+  }
+}
 LLVM_DEBUG(dbgs() << "EarlyCSE CSE: " << Inst << "  to: " << *V
   << '\n');
 if (!DebugCounter::shouldExecute(CSECounter)) {
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 77ca14f88a834..0cb38bcfff2d4 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/

[llvm-branch-commits] LowerTypeTests: Set small code model on imported globals. (PR #141324)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/141324

This is either a vtable (in .data.rel.ro) or a jump table (in .text).
Either way it's expected to be in the low 2 GiB, so set the small
code model.



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


[llvm-branch-commits] X86: Add X86TargetLowering::isProfitableToHoist hook for immediate operands. (PR #141326)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/141326

Casts taking a constant expression (generally derived from a global
variable address) as an operand are not profitable to CSE because they
appear as subexpressions in the instruction sequence generated by the
LowerTypeTests pass which is expected to pattern match to the rotate
instruction. These casts are expected to be code generated into the
instruction's immediate operand, so there is no benefit to hoisting
them anyway.



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


[llvm-branch-commits] Transforms: Have CSE/GVN/LICM check isProfitableToHoist() before hoisting. (PR #141325)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/141325

LICM hoists instructions into the preheader, and CSE and GVN
can effectively perform a hoist by replacing an instruction with
one from another basic block, all of which can lead to the same
kinds of pessimizations that isProfitableToHoist() is intended to
prevent. Therefore, call the hook from all these passes.

This will be tested in the subsequent change that adds a previously
hoistable case and verifies that no optimization pass hoists it.



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


[llvm-branch-commits] Add SimplifyTypeTests pass. (PR #141327)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/141327

This pass figures out whether inlining has exposed a constant address to
a lowered type test, and remove the test if so and the address is known
to pass the test. Unfortunately this pass ends up needing to reverse
engineer what LowerTypeTests did; this is currently inherent to the design
of ThinLTO importing where LowerTypeTests needs to run at the start.

TODO: Add tests.



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


[llvm-branch-commits] Add SimplifyTypeTests pass. (PR #141327)

2025-05-23 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Peter Collingbourne (pcc)


Changes

This pass figures out whether inlining has exposed a constant address to
a lowered type test, and remove the test if so and the address is known
to pass the test. Unfortunately this pass ends up needing to reverse
engineer what LowerTypeTests did; this is currently inherent to the design
of ThinLTO importing where LowerTypeTests needs to run at the start.

TODO: Add tests.


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


4 Files Affected:

- (modified) llvm/include/llvm/Transforms/IPO/LowerTypeTests.h (+5) 
- (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+2) 
- (modified) llvm/lib/Passes/PassRegistry.def (+1) 
- (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+61) 


``diff
diff --git a/llvm/include/llvm/Transforms/IPO/LowerTypeTests.h 
b/llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
index 02adcd8bfd45d..40f2d2c4fadf7 100644
--- a/llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
+++ b/llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
@@ -223,6 +223,11 @@ class LowerTypeTestsPass : public 
PassInfoMixin {
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
 };
 
+class SimplifyTypeTestsPass : public PassInfoMixin {
+public:
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+
 } // end namespace llvm
 
 #endif // LLVM_TRANSFORMS_IPO_LOWERTYPETESTS_H
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index f3654600c5abb..e3adceed7d70a 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1464,6 +1464,8 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
   if (!LTOPreLink)
 MPM.addPass(EliminateAvailableExternallyPass());
 
+  MPM.addPass(SimplifyTypeTestsPass());
+
   // Do RPO function attribute inference across the module to forward-propagate
   // attributes where applicable.
   // FIXME: Is this really an optimization rather than a canonicalization?
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 94dabe290213d..35ad73738d71d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -100,6 +100,7 @@ MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
 MODULE_PASS("lower-emutls", LowerEmuTLSPass())
 MODULE_PASS("lower-global-dtors", LowerGlobalDtorsPass())
 MODULE_PASS("lower-ifunc", LowerIFuncPass())
+MODULE_PASS("simplify-type-tests", SimplifyTypeTestsPass())
 MODULE_PASS("lowertypetests", LowerTypeTestsPass())
 MODULE_PASS("fatlto-cleanup", FatLtoCleanup())
 MODULE_PASS("pgo-force-function-attrs", PGOForceFunctionAttrsPass(PGOOpt ? 
PGOOpt->ColdOptType : PGOOptions::ColdFuncOpt::Default))
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp 
b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 428c4641a7f56..344ac9f5a8f95 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2456,3 +2456,64 @@ PreservedAnalyses LowerTypeTestsPass::run(Module &M,
 return PreservedAnalyses::all();
   return PreservedAnalyses::none();
 }
+
+PreservedAnalyses SimplifyTypeTestsPass::run(Module &M,
+ ModuleAnalysisManager &AM) {
+  bool Changed = false;
+  // Figure out whether inlining has exposed a constant address to a lowered
+  // type test, and remove the test if so and the address is known to pass the
+  // test. Unfortunately this pass ends up needing to reverse engineer what
+  // LowerTypeTests did; this is currently inherent to the design of ThinLTO
+  // importing where LowerTypeTests needs to run at the start.
+  for (auto &GV : M.globals()) {
+if (!GV.getName().starts_with("__typeid_") ||
+!GV.getName().ends_with("_global_addr"))
+  continue;
+auto *MD = MDString::get(M.getContext(),
+ GV.getName().substr(9, GV.getName().size() - 21));
+auto MaySimplify = [&](Value *Op) {
+  auto *PtrAsInt = dyn_cast(Op);
+  if (!PtrAsInt || PtrAsInt->getOpcode() != Instruction::PtrToInt)
+return false;
+  auto *Ptr = PtrAsInt->getOperand(0);
+  if (auto *GV = dyn_cast(Ptr))
+if (auto *CFIGV = M.getNamedValue((GV->getName() + ".cfi").str()))
+  Ptr = CFIGV;
+  return isKnownTypeIdMember(MD, M.getDataLayout(), Ptr, 0);
+};
+for (User *U : GV.users()) {
+  auto *CE = dyn_cast(U);
+  if (!CE || CE->getOpcode() != Instruction::PtrToInt)
+continue;
+  for (Use &U : make_early_inc_range(CE->uses())) {
+auto *CE = dyn_cast(U.getUser());
+if (U.getOperandNo() == 1 && CE &&
+CE->getOpcode() == Instruction::Sub &&
+MaySimplify(CE->getOperand(0))) {
+  // This is a computation of PtrOffset as generated by
+  // LowerTypeTestsModule::lowerTypeTestCall above. If
+  // isKnownTypeIdM

[llvm-branch-commits] X86: Add X86TargetLowering::isProfitableToHoist hook for immediate operands. (PR #141326)

2025-05-23 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-llvm-transforms

Author: Peter Collingbourne (pcc)


Changes

Casts taking a constant expression (generally derived from a global
variable address) as an operand are not profitable to CSE because they
appear as subexpressions in the instruction sequence generated by the
LowerTypeTests pass which is expected to pattern match to the rotate
instruction. These casts are expected to be code generated into the
instruction's immediate operand, so there is no benefit to hoisting
them anyway.


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


4 Files Affected:

- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+13) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.h (+2) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+2-2) 
- (added) llvm/test/Other/inhibit-zext-constant-hoist.ll (+179) 


``diff
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 6b4b4beb97ca5..ec252bcd9577a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -62119,3 +62119,16 @@ Align 
X86TargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
 return Align(1ULL << ExperimentalPrefInnermostLoopAlignment);
   return TargetLowering::getPrefLoopAlignment();
 }
+
+bool X86TargetLowering::isProfitableToHoist(Instruction *I) const {
+  // Casts taking a constant expression (generally derived from a global
+  // variable address) as an operand are not profitable to CSE because they
+  // appear as subexpressions in the instruction sequence generated by the
+  // LowerTypeTests pass which is expected to pattern match to the rotate
+  // instruction. These casts are expected to be code generated into the
+  // instruction's immediate operand, so there is no benefit to hoisting them
+  // anyway.
+  if (isa(I) && isa(I->getOperand(0)))
+return false;
+  return true;
+}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.h 
b/llvm/lib/Target/X86/X86ISelLowering.h
index 662552a972249..302121e3ced5a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.h
+++ b/llvm/lib/Target/X86/X86ISelLowering.h
@@ -1669,6 +1669,8 @@ namespace llvm {
 
 Align getPrefLoopAlignment(MachineLoop *ML) const override;
 
+bool isProfitableToHoist(Instruction *I) const override;
+
 EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const override {
   if (VT == MVT::f80)
 return EVT::getIntegerVT(Context, 96);
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 0cb38bcfff2d4..1a72e3b48105d 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2724,7 +2724,7 @@ bool GVNPass::processInstruction(Instruction *I) {
   // If this GVN would effectively hoist the instruction and that's known to be
   // unprofitable, don't do it. Remember the instruction so that it can be used
   // by other instructions in the same block.
-  if (auto *ReplI = dyn_cast(I)) {
+  if (auto *ReplI = dyn_cast(Repl)) {
 if (ReplI->getParent() != I->getParent() && !TTI->isProfitableToHoist(I)) {
   LeaderTable.insert(Num, I, I->getParent());
   return false;
@@ -2891,7 +2891,7 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
   if (isa(CurInst) || CurInst->isTerminator() ||
   isa(CurInst) || CurInst->getType()->isVoidTy() ||
   CurInst->mayReadFromMemory() || CurInst->mayHaveSideEffects() ||
-  isa(CurInst))
+  isa(CurInst) || !TTI->isProfitableToHoist(CurInst))
 return false;
 
   // Don't do PRE on compares. The PHI would prevent CodeGenPrepare from
diff --git a/llvm/test/Other/inhibit-zext-constant-hoist.ll 
b/llvm/test/Other/inhibit-zext-constant-hoist.ll
new file mode 100644
index 0..eaad0b8a04e81
--- /dev/null
+++ b/llvm/test/Other/inhibit-zext-constant-hoist.ll
@@ -0,0 +1,179 @@
+; REQUIRES: x86-registered-target
+; Make sure that optimizations do not hoist zext(const).
+
+; This IR is normally generated by LowerTypeTests during ThinLTO importing
+; so it will go through the ThinLTO pass pipeline.
+; RUN: opt -passes='thinlto' -S < %s | FileCheck %s
+; RUN: opt -passes='thinlto' -S < %s | FileCheck %s
+; RUN: opt -passes='thinlto' -S < %s | FileCheck %s
+; RUN: opt -passes='thinlto' -S < %s | FileCheck %s
+
+; Also check the regular pipelines for completeness.
+; RUN: opt -O0 -S < %s | FileCheck %s
+; RUN: opt -O1 -S < %s | FileCheck %s
+; RUN: opt -O2 -S < %s | FileCheck %s
+; RUN: opt -O3 -S < %s | FileCheck %s
+; RUN: opt -Os -S < %s | FileCheck %s
+; RUN: opt -Oz -S < %s | FileCheck %s
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@__typeid__ZTS1S_global_addr = external hidden global [0 x i8], code_model 
"small"
+@__typeid__ZTS1S_align = external hidden global [0 x i8], !absolute_symbol !0
+@__typeid__ZTS1S_size_m1 = externa

[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134197


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


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


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


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/132857


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


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/132857
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Add IR and codegen support for deactivation symbols. (PR #133536)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133536


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


[llvm-branch-commits] MachineInstrBuilder: Introduce copyMIMetadata() function. (PR #133535)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133535


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


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-05-23 Thread via llvm-branch-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- 
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
llvm/lib/Target/AArch64/AArch64Subtarget.cpp 
llvm/lib/Target/AArch64/AArch64Subtarget.h 
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 80924c485..d8d029928 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -2153,8 +2153,7 @@ void AArch64AsmPrinter::emitPtrauthAuthResign(
 
   // Compute pac discriminator into x17
   assert(isUInt<16>(PACDisc));
-  Register PACDiscReg =
-  emitPtrauthDiscriminator(PACDisc, PACAddrDisc, Scratch);
+  Register PACDiscReg = emitPtrauthDiscriminator(PACDisc, PACAddrDisc, 
Scratch);
   bool PACZero = PACDiscReg == AArch64::XZR;
   unsigned PACOpc = getPACOpcodeForKey(*PACKey, PACZero);
 

``




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


[llvm-branch-commits] Add IR and codegen support for deactivation symbols. (PR #133536)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133536


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


[llvm-branch-commits] Add deactivation symbol operand to ConstantPtrAuth. (PR #133537)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133537


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


[llvm-branch-commits] Add deactivation symbol operand to ConstantPtrAuth. (PR #133537)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133537


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


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133538


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


[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133538


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


[llvm-branch-commits] MachineInstrBuilder: Introduce copyMIMetadata() function. (PR #133535)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133535


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


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

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


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

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


[llvm-branch-commits] [lld] ELF: Introduce R_AARCH64_FUNCINIT64 relocation type. (PR #133531)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531

>From 96e7da9a083888683c2ba00d97f886fd748ea10b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 9 Apr 2025 20:30:57 -0700
Subject: [PATCH] Undo unnecessary change

Created using spr 1.3.6-beta.1
---
 lld/ELF/SyntheticSections.cpp | 2 +-
 lld/ELF/SyntheticSections.h   | 2 +-
 lld/ELF/Writer.cpp| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8cab71c4c8d94..106749e90a82b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1696,7 +1696,7 @@ void 
RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
  sym, 0, R_ABS, addendRelType);
 }
 
-void RelocationBaseSection::mergeRels(Ctx &ctx) {
+void RelocationBaseSection::mergeRels() {
   size_t newSize = relocs.size();
   for (const auto &v : relocsVec)
 newSize += v.size();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7a85906e8601d..2dd4b80eb85bf 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -553,7 +553,7 @@ class RelocationBaseSection : public SyntheticSection {
   }
   size_t getSize() const override { return relocs.size() * this->entsize; }
   size_t getRelativeRelocCount() const { return numRelativeRelocs; }
-  void mergeRels(Ctx &ctx);
+  void mergeRels();
   void partitionRels();
   void finalizeContents() override;
 
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 67004055f1af5..28b24f90716b8 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2076,7 +2076,7 @@ template  void 
Writer::finalizeSections() {
 // symbol table section (dynSymTab) must be the first one.
 for (Partition &part : ctx.partitions) {
   if (part.relaDyn) {
-part.relaDyn->mergeRels(ctx);
+part.relaDyn->mergeRels();
 // Compute DT_RELACOUNT to be used by part.dynamic.
 part.relaDyn->partitionRels();
 finalizeSynthetic(ctx, part.relaDyn.get());

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


[llvm-branch-commits] [lld] ELF: Introduce R_AARCH64_FUNCINIT64 relocation type. (PR #133531)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531

>From 96e7da9a083888683c2ba00d97f886fd748ea10b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 9 Apr 2025 20:30:57 -0700
Subject: [PATCH] Undo unnecessary change

Created using spr 1.3.6-beta.1
---
 lld/ELF/SyntheticSections.cpp | 2 +-
 lld/ELF/SyntheticSections.h   | 2 +-
 lld/ELF/Writer.cpp| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8cab71c4c8d94..106749e90a82b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1696,7 +1696,7 @@ void 
RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
  sym, 0, R_ABS, addendRelType);
 }
 
-void RelocationBaseSection::mergeRels(Ctx &ctx) {
+void RelocationBaseSection::mergeRels() {
   size_t newSize = relocs.size();
   for (const auto &v : relocsVec)
 newSize += v.size();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7a85906e8601d..2dd4b80eb85bf 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -553,7 +553,7 @@ class RelocationBaseSection : public SyntheticSection {
   }
   size_t getSize() const override { return relocs.size() * this->entsize; }
   size_t getRelativeRelocCount() const { return numRelativeRelocs; }
-  void mergeRels(Ctx &ctx);
+  void mergeRels();
   void partitionRels();
   void finalizeContents() override;
 
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 67004055f1af5..28b24f90716b8 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2076,7 +2076,7 @@ template  void 
Writer::finalizeSections() {
 // symbol table section (dynSymTab) must be the first one.
 for (Partition &part : ctx.partitions) {
   if (part.relaDyn) {
-part.relaDyn->mergeRels(ctx);
+part.relaDyn->mergeRels();
 // Compute DT_RELACOUNT to be used by part.dynamic.
 part.relaDyn->partitionRels();
 finalizeSynthetic(ctx, part.relaDyn.get());

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


[llvm-branch-commits] ELF: Add support for R_AARCH64_INST32 relocation. (PR #133534)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133534


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


[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

I thought about it some more and decided to go with your suggested approach 
anyway. Among other things, #133536 will mean that deactivation symbol support 
will be needed for the pseudo instruction in order to avoid deactivation symbol 
relocations being silently dropped, so it's best if everything goes through the 
same code path.

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


[llvm-branch-commits] CodeGen: Optionally emit PAuth relocations as IRELATIVE relocations. (PR #133533)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133533


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


[llvm-branch-commits] CodeGen: Optionally emit PAuth relocations as IRELATIVE relocations. (PR #133533)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133533


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


[llvm-branch-commits] ELF: Add support for R_AARCH64_INST32 relocation. (PR #133534)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133534


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


[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-05-23 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134197


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


[llvm-branch-commits] [clang] 070cf62 - [Clang] Demote mixed enumeration arithmetic error to a warning (#131811)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

Author: cor3ntin
Date: 2025-05-23T20:59:40-07:00
New Revision: 070cf62530eab91d68521787e08418343b9ca28b

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

LOG: [Clang] Demote mixed enumeration arithmetic error to a warning (#131811)

In C++, defaulted to an error.

C++ removed these features but the removal negatively impacts users.

Fixes #92340

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2c-enum-compare.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2f43dc4021fd8..774a00b4feef5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -314,6 +314,9 @@ C++2c Feature Support
 
 - Implemented `P3176R1 The Oxford variadic comma `_
 
+- The error produced when doing arithmetic operations on enums of 
diff erent types
+  can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
+
 C++23 Feature Support
 ^
 - Removed the restriction to literal types in constexpr functions in C++23 
mode.

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ec2a140e04d5b..7180447e250ce 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "
diff erent enumeration types%
diff { ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "
diff erent enumeration types%
diff { ($ and $)|}1,2">;
+def _warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;
 
 def warn_arith_conv_mixed_anon_enum_types : Warning<
   warn_arith_conv_mixed_enum_types.Summary>,

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e253e3a17328f..23d0f9532d4f8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1519,7 +1519,7 @@ static void checkEnumArithmeticConversions(Sema &S, Expr 
*LHS, Expr *RHS,
 // In C++ 26, usual arithmetic conversions between 2 
diff erent enum types
 // are ill-formed.
 if (S.getLangOpts().CPlusPlus26)
-  DiagID = diag::err_conv_mixed_enum_types_cxx26;
+  DiagID = diag::_warn_conv_mixed_enum_types_cxx26;
 else if (!L->castAs()->getDecl()->hasNameForLinkage() ||
  !R->castAs()->getDecl()->hasNameForLinkage()) {
   // If either enumeration type is unnamed, it's less likely that the

diff  --git a/clang/test/SemaCXX/cxx2c-enum-compare.cpp 
b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
index f47278a60725e..96fbd368b1696 100644
--- a/clang/test/SemaCXX/cxx2c-enum-compare.cpp
+++ b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,expected
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both 
-Wno-enum-enum-conversion
 
 enum E1 { e };
 enum E2 { f };
 void test() {
-int b = e <= 3.7; // expected-error {{invalid comparison of enumeration 
type 'E1' with floating-point type 'double'}}
+int b = e <= 3.7; // both-error {{invalid comparison of enumeration type 
'E1' with floating-point type 'double'}}
 int k = f - e; // expected-error {{invalid arithmetic between 
diff erent enumeration types ('E2' and 'E1')}}
 int x = 1 ? e : f; // expected-error {{invalid conditional expression 
between 
diff erent enumeration types ('E1' and 'E2')}}
 }



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


[llvm-branch-commits] [clang] [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr (PR #139909)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/139909

>From 8a36b8e3ab46d69ee1798ded75038715b2080f83 Mon Sep 17 00:00:00 2001
From: Fangyi Zhou 
Date: Thu, 17 Apr 2025 23:02:37 +0100
Subject: [PATCH] [clang][analyzer] Handle CXXParenInitListExpr alongside
 InitListExpr

As reported in #135665, C++20 parenthesis initializer list expressions
are not handled correctly and were causing crashes. This commit attempts
to fix the issue by handing parenthesis initializer lists along side
existing initializer lists.

(cherry picked from commit 5dc9d55eb04d94c01dba0364b51a509f975e542a)
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 .../Checkers/DynamicTypePropagation.cpp   |  6 +++---
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 10 ++
 clang/test/Analysis/PR135665.cpp  | 19 +++
 4 files changed, 31 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Analysis/PR135665.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 774a00b4feef5..7b84210fddab3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1472,6 +1472,9 @@ Crash and bug fixes
 - The ``unix.BlockInCriticalSection`` now recognizes the ``lock()`` member 
function
   as expected, even if it's inherited from a base class. Fixes (#GH104241).
 
+- Fixed a crash when C++20 parenthesized initializer lists are used. This issue
+  was causing a crash in clang-tidy. (#GH136041)
+
 Improvements
 
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
index a0bf776b11f53..e58329817d7cd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -379,9 +379,9 @@ void DynamicTypePropagation::checkPostCall(const CallEvent 
&Call,
 // aggregates, and in such case no top-frame constructor will be 
called.
 // Figure out if we need to do anything in this case.
 // FIXME: Instead of relying on the ParentMap, we should have the
-// trigger-statement (InitListExpr in this case) available in this
-// callback, ideally as part of CallEvent.
-if (isa_and_nonnull(
+// trigger-statement (InitListExpr or CXXParenListInitExpr in this 
case)
+// available in this callback, ideally as part of CallEvent.
+if (isa_and_nonnull(
 LCtx->getParentMap().getParent(Ctor->getOriginExpr(
   return;
 
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index f7020da2e6da2..30839a40389ba 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -637,9 +637,10 @@ void ExprEngine::handleConstructor(const Expr *E,
 // FIXME: For now this code essentially bails out. We need to find the
 // correct target region and set it.
 // FIXME: Instead of relying on the ParentMap, we should have the
-// trigger-statement (InitListExpr in this case) passed down from CFG or
-// otherwise always available during construction.
-if (isa_and_nonnull(LCtx->getParentMap().getParent(E))) {
+// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
+// passed down from CFG or otherwise always available during construction.
+if (isa_and_nonnull(
+LCtx->getParentMap().getParent(E))) {
   MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
   Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
   CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true;
@@ -1010,7 +1011,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, 
ExplodedNode *Pred,
   // values are properly placed inside the required region, however if an
   // initializer list is used, this doesn't happen automatically.
   auto *Init = CNE->getInitializer();
-  bool isInitList = isa_and_nonnull(Init);
+  bool isInitList =
+  isa_and_nonnull(Init);
 
   QualType ObjTy =
   isInitList ? Init->getType() : CNE->getType()->getPointeeType();
diff --git a/clang/test/Analysis/PR135665.cpp b/clang/test/Analysis/PR135665.cpp
new file mode 100644
index 0..124b8c9b97b04
--- /dev/null
+++ b/clang/test/Analysis/PR135665.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+template
+struct overload : public F...
+{
+  using F::operator()...;
+};
+
+template
+overload(F&&...) -> overload;
+
+int main()
+{
+  const auto l = overload([](const int* i) {});
+
+  return 0;
+}

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


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/139396

>From 070cf62530eab91d68521787e08418343b9ca28b Mon Sep 17 00:00:00 2001
From: cor3ntin 
Date: Tue, 18 Mar 2025 16:45:37 +0100
Subject: [PATCH] [Clang] Demote mixed enumeration arithmetic error to a
 warning (#131811)

In C++, defaulted to an error.

C++ removed these features but the removal negatively impacts users.

Fixes #92340
---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +-
 clang/lib/Sema/SemaExpr.cpp  | 2 +-
 clang/test/SemaCXX/cxx2c-enum-compare.cpp| 5 +++--
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2f43dc4021fd8..774a00b4feef5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -314,6 +314,9 @@ C++2c Feature Support
 
 - Implemented `P3176R1 The Oxford variadic comma `_
 
+- The error produced when doing arithmetic operations on enums of different 
types
+  can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
+
 C++23 Feature Support
 ^
 - Removed the restriction to literal types in constexpr functions in C++23 
mode.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ec2a140e04d5b..7180447e250ce 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def _warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;
 
 def warn_arith_conv_mixed_anon_enum_types : Warning<
   warn_arith_conv_mixed_enum_types.Summary>,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e253e3a17328f..23d0f9532d4f8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1519,7 +1519,7 @@ static void checkEnumArithmeticConversions(Sema &S, Expr 
*LHS, Expr *RHS,
 // In C++ 26, usual arithmetic conversions between 2 different enum types
 // are ill-formed.
 if (S.getLangOpts().CPlusPlus26)
-  DiagID = diag::err_conv_mixed_enum_types_cxx26;
+  DiagID = diag::_warn_conv_mixed_enum_types_cxx26;
 else if (!L->castAs()->getDecl()->hasNameForLinkage() ||
  !R->castAs()->getDecl()->hasNameForLinkage()) {
   // If either enumeration type is unnamed, it's less likely that the
diff --git a/clang/test/SemaCXX/cxx2c-enum-compare.cpp 
b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
index f47278a60725e..96fbd368b1696 100644
--- a/clang/test/SemaCXX/cxx2c-enum-compare.cpp
+++ b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,expected
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both 
-Wno-enum-enum-conversion
 
 enum E1 { e };
 enum E2 { f };
 void test() {
-int b = e <= 3.7; // expected-error {{invalid comparison of enumeration 
type 'E1' with floating-point type 'double'}}
+int b = e <= 3.7; // both-error {{invalid comparison of enumeration type 
'E1' with floating-point type 'double'}}
 int k = f - e; // expected-error {{invalid arithmetic between different 
enumeration types ('E2' and 'E1')}}
 int x = 1 ? e : f; // expected-error {{invalid conditional expression 
between different enumeration types ('E1' and 'E2')}}
 }

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


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

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


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-23 Thread via llvm-branch-commits

github-actions[bot] wrote:

@cor3ntin (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

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


[llvm-branch-commits] [clang] 8a36b8e - [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr

2025-05-23 Thread Tom Stellard via llvm-branch-commits

Author: Fangyi Zhou
Date: 2025-05-23T21:03:00-07:00
New Revision: 8a36b8e3ab46d69ee1798ded75038715b2080f83

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

LOG: [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr

As reported in #135665, C++20 parenthesis initializer list expressions
are not handled correctly and were causing crashes. This commit attempts
to fix the issue by handing parenthesis initializer lists along side
existing initializer lists.

(cherry picked from commit 5dc9d55eb04d94c01dba0364b51a509f975e542a)

Added: 
clang/test/Analysis/PR135665.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 774a00b4feef5..7b84210fddab3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1472,6 +1472,9 @@ Crash and bug fixes
 - The ``unix.BlockInCriticalSection`` now recognizes the ``lock()`` member 
function
   as expected, even if it's inherited from a base class. Fixes (#GH104241).
 
+- Fixed a crash when C++20 parenthesized initializer lists are used. This issue
+  was causing a crash in clang-tidy. (#GH136041)
+
 Improvements
 
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
index a0bf776b11f53..e58329817d7cd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -379,9 +379,9 @@ void DynamicTypePropagation::checkPostCall(const CallEvent 
&Call,
 // aggregates, and in such case no top-frame constructor will be 
called.
 // Figure out if we need to do anything in this case.
 // FIXME: Instead of relying on the ParentMap, we should have the
-// trigger-statement (InitListExpr in this case) available in this
-// callback, ideally as part of CallEvent.
-if (isa_and_nonnull(
+// trigger-statement (InitListExpr or CXXParenListInitExpr in this 
case)
+// available in this callback, ideally as part of CallEvent.
+if (isa_and_nonnull(
 LCtx->getParentMap().getParent(Ctor->getOriginExpr(
   return;
 

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index f7020da2e6da2..30839a40389ba 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -637,9 +637,10 @@ void ExprEngine::handleConstructor(const Expr *E,
 // FIXME: For now this code essentially bails out. We need to find the
 // correct target region and set it.
 // FIXME: Instead of relying on the ParentMap, we should have the
-// trigger-statement (InitListExpr in this case) passed down from CFG or
-// otherwise always available during construction.
-if (isa_and_nonnull(LCtx->getParentMap().getParent(E))) {
+// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
+// passed down from CFG or otherwise always available during construction.
+if (isa_and_nonnull(
+LCtx->getParentMap().getParent(E))) {
   MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
   Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
   CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true;
@@ -1010,7 +1011,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, 
ExplodedNode *Pred,
   // values are properly placed inside the required region, however if an
   // initializer list is used, this doesn't happen automatically.
   auto *Init = CNE->getInitializer();
-  bool isInitList = isa_and_nonnull(Init);
+  bool isInitList =
+  isa_and_nonnull(Init);
 
   QualType ObjTy =
   isInitList ? Init->getType() : CNE->getType()->getPointeeType();

diff  --git a/clang/test/Analysis/PR135665.cpp 
b/clang/test/Analysis/PR135665.cpp
new file mode 100644
index 0..124b8c9b97b04
--- /dev/null
+++ b/clang/test/Analysis/PR135665.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+template
+struct overload : public F...
+{
+  using F::operator()...;
+};
+
+template
+overload(F&&...) -> overload;
+
+int main()
+{
+  const auto l = overload([](const int* i) {});
+
+  return 0;
+}



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


[llvm-branch-commits] [clang] [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr (PR #139909)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

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


[llvm-branch-commits] [llvm] release/20.x: [SDAG] Ensure load is included in output chain of sincos expansion (#140525) (PR #140703)

2025-05-23 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/140703

>From 9b0832508ede38397c8ebb7a348d50ce1517af4a Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Tue, 20 May 2025 10:43:50 +0100
Subject: [PATCH] [SDAG] Ensure load is included in output chain of sincos
 expansion (#140525)

The load not being included in the chain meant that it could materialize
after a `@llvm.lifetime.end` annotation on the pointer. This could
result in miscompiles if the stack slot is reused for another value.

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

(cherry picked from commit c9d62491981fe720c1b3255fa2f9ddf744590c65)
---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp |  9 ++-
 .../CodeGen/X86/pr140491-sincos-lifetimes.ll  | 70 +++
 2 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index b416c0efbbc4f..eecfb41c2d319 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2660,16 +2660,19 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
   continue;
 }
 MachinePointerInfo PtrInfo;
+SDValue LoadResult =
+getLoad(Node->getValueType(ResNo), DL, CallChain, ResultPtr, PtrInfo);
+SDValue OutChain = LoadResult.getValue(1);
+
 if (StoreSDNode *ST = ResultStores[ResNo]) {
   // Replace store with the library call.
-  ReplaceAllUsesOfValueWith(SDValue(ST, 0), CallChain);
+  ReplaceAllUsesOfValueWith(SDValue(ST, 0), OutChain);
   PtrInfo = ST->getPointerInfo();
 } else {
   PtrInfo = MachinePointerInfo::getFixedStack(
   getMachineFunction(), cast(ResultPtr)->getIndex());
 }
-SDValue LoadResult =
-getLoad(Node->getValueType(ResNo), DL, CallChain, ResultPtr, PtrInfo);
+
 Results.push_back(LoadResult);
   }
 
diff --git a/llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll 
b/llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll
new file mode 100644
index 0..2ca99bdc4b316
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll
@@ -0,0 +1,70 @@
+; RUN: llc < %s | FileCheck %s
+
+; This test is reduced from https://github.com/llvm/llvm-project/issues/140491.
+; It checks that when `@llvm.sincos.f32` is expanded to a call to
+; `sincosf(float, float* out_sin, float* out_cos)` and the store of `%cos` to
+; `%computed` is folded into the `sincosf` call. The use of `%cos`in the later
+; `fneg %cos` -- which expands to a load of `%computed`, will perform the load
+; before the `@llvm.lifetime.end.p0(%computed)` to ensure the correct value is
+; taken for `%cos`.
+
+target triple = "x86_64-sie-ps5"
+
+declare void @use_ptr(ptr readonly)
+
+define i32 @sincos_stack_slot_with_lifetime(float %in)  {
+; CHECK-LABEL: sincos_stack_slot_with_lifetime:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:pushq %rbx
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:subq $32, %rsp
+; CHECK-NEXT:.cfi_def_cfa_offset 48
+; CHECK-NEXT:.cfi_offset %rbx, -16
+; CHECK-NEXT:leaq 12(%rsp), %rdi
+; CHECK-NEXT:leaq 8(%rsp), %rbx
+; CHECK-NEXT:movq %rbx, %rsi
+; CHECK-NEXT:callq sincosf@PLT
+; CHECK-NEXT:movss 8(%rsp), %xmm0 # xmm0 = mem[0],zero,zero,zero
+; CHECK-NEXT:movaps %xmm0, 16(%rsp) # 16-byte Spill
+; CHECK-NEXT:movq %rbx, %rdi
+; CHECK-NEXT:callq use_ptr
+; CHECK-NEXT:movss 12(%rsp), %xmm0 # xmm0 = mem[0],zero,zero,zero
+; CHECK-NEXT:xorps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; CHECK-NEXT:movss %xmm0, 8(%rsp)
+; CHECK-NEXT:leaq 8(%rsp), %rdi
+; CHECK-NEXT:callq use_ptr
+; CHECK-NEXT:movaps 16(%rsp), %xmm0 # 16-byte Reload
+; CHECK-NEXT:xorps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; CHECK-NEXT:movss %xmm0, 8(%rsp)
+; CHECK-NEXT:leaq 8(%rsp), %rdi
+; CHECK-NEXT:callq use_ptr
+; CHECK-NEXT:xorl %eax, %eax
+; CHECK-NEXT:addq $32, %rsp
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:popq %rbx
+; CHECK-NEXT:.cfi_def_cfa_offset 8
+; CHECK-NEXT:retq
+entry:
+  %computed = alloca float, align 4
+  %computed1 = alloca float, align 4
+  %computed3 = alloca float, align 4
+  %sincos = tail call { float, float } @llvm.sincos.f32(float %in)
+  %sin = extractvalue { float, float } %sincos, 0
+  %cos = extractvalue { float, float } %sincos, 1
+  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %computed)
+  store float %cos, ptr %computed, align 4
+  call void @use_ptr(ptr nonnull %computed)
+  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %computed)
+  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %computed1)
+  %fneg_sin = fneg float %sin
+  store float %fneg_sin, ptr %computed1, align 4
+  call void @use_ptr(ptr nonnull %computed1)
+  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %computed1)
+  call void @llvm.lifetime.start.p

  1   2   >