[llvm-branch-commits] [llvm] release/21.x: [Mips] Fix clang crashes when assembling invalid MIPS beql instructions with --arch=mips (#156413) (PR #162806)

2025-10-11 Thread via llvm-branch-commits

llvmbot wrote:

@arsenm What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/162806
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [NFC][SpecialCaseList] Hide more details in private section (PR #162302)

2025-10-11 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/162302


___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Extend Inliner to work on functions with Pointer Autentication (PR #162458)

2025-10-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Gergely Bálint (bgergely0)


Changes

The inliner uses DirectSP to check if a function has instructions that
modify the SP. Exceptions are stack Push and Pop instructions.

We can also allow pointer signing and authentication instructions.

The inliner removes the Return instructions from the inlined functions.
If it is a fused pointer-authentication-and-return (e.g. RETAA), we have
to generate a new authentication instruction in place of the Return.

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


4 Files Affected:

- (modified) bolt/include/bolt/Core/MCPlusBuilder.h (+6) 
- (modified) bolt/lib/Passes/Inliner.cpp (+18) 
- (modified) bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp (+29) 
- (added) bolt/test/AArch64/inline-armv8.3-returns.s (+45) 


``diff
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h 
b/bolt/include/bolt/Core/MCPlusBuilder.h
index 2772de73081d1..ba28016a234fb 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -632,6 +632,12 @@ class MCPlusBuilder {
 return false;
   }
 
+  /// Generate the matching pointer authentication instruction from a fused
+  /// pauth-and-return instruction.
+  virtual void createMatchingAuth(const MCInst &AuthAndRet, MCInst &Auth) {
+llvm_unreachable("not implemented");
+  }
+
   /// Returns the register used as a return address. Returns std::nullopt if
   /// not applicable, such as reading the return address from a system register
   /// or from the stack.
diff --git a/bolt/lib/Passes/Inliner.cpp b/bolt/lib/Passes/Inliner.cpp
index 9b28c7efde5bf..913ff3d554a5b 100644
--- a/bolt/lib/Passes/Inliner.cpp
+++ b/bolt/lib/Passes/Inliner.cpp
@@ -195,6 +195,13 @@ InliningInfo getInliningInfo(const BinaryFunction &BF) {
 if (BC.MIB->isPush(Inst) || BC.MIB->isPop(Inst))
   continue;
 
+// Pointer signing and authenticatin instructions are used around
+// Push and Pop. These are also straightforward to handle.
+if (BC.isAArch64() &&
+(BC.MIB->isPSignOnLR(Inst) || BC.MIB->isPAuthOnLR(Inst) ||
+ BC.MIB->isPAuthAndRet(Inst)))
+  continue;
+
 DirectSP |= BC.MIB->hasDefOfPhysReg(Inst, SPReg) ||
 BC.MIB->hasUseOfPhysReg(Inst, SPReg);
   }
@@ -338,6 +345,17 @@ Inliner::inlineCall(BinaryBasicBlock &CallerBB,
 BC.Ctx.get());
   }
 
+  // Handling fused authentication and return instructions (Armv8.3-A):
+  // if the Return here is RETA(A|B), we have to keep the authentication
+  // part.
+  // RETAA -> AUTIASP + RET
+  // RETAB -> AUTIBSP + RET
+  if (BC.isAArch64() && BC.MIB->isPAuthAndRet(Inst)) {
+MCInst Auth;
+BC.MIB->createMatchingAuth(Inst, Auth);
+InsertII =
+std::next(InlinedBB->insertInstruction(InsertII, std::move(Auth)));
+  }
   if (CSIsTailCall || (!MIB.isCall(Inst) && !MIB.isReturn(Inst))) {
 InsertII =
 std::next(InlinedBB->insertInstruction(InsertII, std::move(Inst)));
diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp 
b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
index df4f42128605e..5fb1d7458a4bc 100644
--- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
+++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
@@ -266,6 +266,35 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
Inst.getOpcode() == AArch64::RETABSPPCr;
   }
 
+  void createMatchingAuth(const MCInst &AuthAndRet, MCInst &Auth) override {
+assert(isPAuthAndRet(AuthAndRet) &&
+   "Not a fused pauth-and-return instruction");
+
+Auth.clear();
+switch (AuthAndRet.getOpcode()) {
+case AArch64::RETAA:
+  Auth.setOpcode(AArch64::AUTIASP);
+  break;
+case AArch64::RETAB:
+  Auth.setOpcode(AArch64::AUTIBSP);
+  break;
+case AArch64::RETAASPPCi:
+  Auth.setOpcode(AArch64::AUTIASPPCi);
+  break;
+case AArch64::RETABSPPCi:
+  Auth.setOpcode(AArch64::AUTIBSPPCi);
+  break;
+case AArch64::RETAASPPCr:
+  Auth.setOpcode(AArch64::AUTIASPPCr);
+  break;
+case AArch64::RETABSPPCr:
+  Auth.setOpcode(AArch64::AUTIBSPPCr);
+  break;
+default:
+  llvm_unreachable("Unhandled fused pauth-and-return instruction");
+}
+  }
+
   std::optional getSignedReg(const MCInst &Inst) const override {
 switch (Inst.getOpcode()) {
 case AArch64::PACIA:
diff --git a/bolt/test/AArch64/inline-armv8.3-returns.s 
b/bolt/test/AArch64/inline-armv8.3-returns.s
new file mode 100644
index 0..055b589476caf
--- /dev/null
+++ b/bolt/test/AArch64/inline-armv8.3-returns.s
@@ -0,0 +1,45 @@
+# This test checks that inlining functions with fused pointer-auth-and-return
+# instructions is properly handled by BOLT.
+
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown -mattr=+v8.3a %s 
-o %t.o
+# R

[llvm-branch-commits] [llvm] [AllocToken, Clang] Implement __builtin_infer_alloc_token() and llvm.alloc.token.id (PR #156842)

2025-10-11 Thread Marco Elver via llvm-branch-commits

https://github.com/melver updated 
https://github.com/llvm/llvm-project/pull/156842

>From 48227c8f7712b2dc807b252d18353c91905b1fb5 Mon Sep 17 00:00:00 2001
From: Marco Elver 
Date: Mon, 8 Sep 2025 17:19:04 +0200
Subject: [PATCH] fixup!

Created using spr 1.3.8-beta.1
---
 llvm/lib/Transforms/Instrumentation/AllocToken.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/AllocToken.cpp 
b/llvm/lib/Transforms/Instrumentation/AllocToken.cpp
index d5ac3035df71b..3a28705d87523 100644
--- a/llvm/lib/Transforms/Instrumentation/AllocToken.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AllocToken.cpp
@@ -151,7 +151,8 @@ STATISTIC(NumAllocations, "Allocations found");
 /// Expected format is: !{, }
 MDNode *getAllocTokenHintMetadata(const CallBase &CB) {
   MDNode *Ret = nullptr;
-  if (auto *II = dyn_cast(&CB)) {
+  if (auto *II = dyn_cast(&CB);
+  II && II->getIntrinsicID() == Intrinsic::alloc_token_id) {
 auto *MDV = cast(II->getArgOperand(0));
 Ret = cast(MDV->getMetadata());
 // If the intrinsic has an empty MDNode, type inference failed.
@@ -358,7 +359,7 @@ bool AllocToken::instrumentFunction(Function &F) {
   // Collect all allocation calls to avoid iterator invalidation.
   for (Instruction &I : instructions(F)) {
 // Collect all alloc_token_* intrinsics.
-if (IntrinsicInst *II = dyn_cast(&I);
+if (auto *II = dyn_cast(&I);
 II && II->getIntrinsicID() == Intrinsic::alloc_token_id) {
   IntrinsicInsts.emplace_back(II);
   continue;

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc++] Annotate classes with _LIBCPP_PFP to enable pointer field protection (PR #151652)

2025-10-11 Thread Peter Collingbourne via llvm-branch-commits

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


___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm][mustache] Avoid redundant saves in accessor splitting (PR #159197)

2025-10-11 Thread Paul Kirth via llvm-branch-commits

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

>From ee5218891cb24fb08ec0df1e8adb39199dee9bc4 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 16 Sep 2025 00:11:47 -0700
Subject: [PATCH] [llvm][mustache] Avoid redundant saves in accessor splitting

The splitMustacheString function was saving StringRefs that
were already backed by an arena-allocated string. This was
unnecessary work. This change removes the redundant
Ctx.Saver.save() call.

This optimization provides a small but measurable performance
improvement on top of the single-pass tokenizer, most notably
reducing branch misses.

  Metric | Baseline | Optimized | Change
  -- |  | - | ---
  Time (ms)  | 35.77| 35.57 | -0.56%
  Cycles | 35.16M   | 34.91M| -0.71%
  Instructions   | 85.77M   | 85.54M| -0.27%
  Branch Misses  | 113.9K   | 111.9K| -1.76%
  Cache Misses   | 237.7K   | 242.1K| +1.85%
---
 llvm/lib/Support/Mustache.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 13fbc61ca94e4..6089b41def163 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -51,7 +51,7 @@ static Accessor splitMustacheString(StringRef Str, 
MustacheContext &Ctx) {
   std::tie(Part, Str) = Str.split('.');
   // Each part of the accessor needs to be saved to the arena
   // to ensure it has a stable address.
-  Tokens.push_back(Ctx.Saver.save(Part.trim()));
+  Tokens.push_back(Part.trim());
 }
   }
   // Now, allocate memory for the array of StringRefs in the arena.

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2025-10-11 Thread Peter Collingbourne via llvm-branch-commits

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

>From e728f3444624a5f47f0af84c21fb3a584f3e05b7 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 1 Aug 2025 17:27:41 -0700
Subject: [PATCH 1/6] Add verifier check

Created using spr 1.3.6-beta.1
---
 llvm/lib/IR/Verifier.cpp   | 5 +
 llvm/test/Verifier/ptrauth-constant.ll | 6 ++
 2 files changed, 11 insertions(+)
 create mode 100644 llvm/test/Verifier/ptrauth-constant.ll

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 3ff9895e161c4..3478c2c450ae7 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2627,6 +2627,11 @@ void Verifier::visitConstantPtrAuth(const 
ConstantPtrAuth *CPA) {
 
   Check(CPA->getDiscriminator()->getBitWidth() == 64,
 "signed ptrauth constant discriminator must be i64 constant integer");
+
+  Check(isa(CPA->getDeactivationSymbol()) ||
+CPA->getDeactivationSymbol()->isNullValue(),
+"signed ptrauth constant deactivation symbol must be a global value "
+"or null");
 }
 
 bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) {
diff --git a/llvm/test/Verifier/ptrauth-constant.ll 
b/llvm/test/Verifier/ptrauth-constant.ll
new file mode 100644
index 0..fdd6352cf8469
--- /dev/null
+++ b/llvm/test/Verifier/ptrauth-constant.ll
@@ -0,0 +1,6 @@
+; RUN: not opt -passes=verify < %s 2>&1 | FileCheck %s
+
+@g = external global i8
+
+; CHECK: signed ptrauth constant deactivation symbol must be a global variable 
or null
+@ptr = global ptr ptrauth (ptr @g, i32 0, i64 65535, ptr null, ptr inttoptr 
(i64 16 to ptr))

>From 60e836e71bf9aabe9dade2bda1ca38107f76b599 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Mon, 8 Sep 2025 17:34:59 -0700
Subject: [PATCH 2/6] Address review comment

Created using spr 1.3.6-beta.1
---
 llvm/lib/IR/Constants.cpp | 1 +
 llvm/test/Assembler/invalid-ptrauth-const6.ll | 6 ++
 2 files changed, 7 insertions(+)
 create mode 100644 llvm/test/Assembler/invalid-ptrauth-const6.ll

diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 5eacc7af1269b..53b292f90c03d 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2082,6 +2082,7 @@ ConstantPtrAuth::ConstantPtrAuth(Constant *Ptr, 
ConstantInt *Key,
   assert(Key->getBitWidth() == 32);
   assert(Disc->getBitWidth() == 64);
   assert(AddrDisc->getType()->isPointerTy());
+  assert(DeactivationSymbol->getType()->isPointerTy());
   setOperand(0, Ptr);
   setOperand(1, Key);
   setOperand(2, Disc);
diff --git a/llvm/test/Assembler/invalid-ptrauth-const6.ll 
b/llvm/test/Assembler/invalid-ptrauth-const6.ll
new file mode 100644
index 0..6e8e1d386acc8
--- /dev/null
+++ b/llvm/test/Assembler/invalid-ptrauth-const6.ll
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+@var = global i32 0
+
+; CHECK: error: constant ptrauth deactivation symbol must be a pointer
+@ptr = global ptr ptrauth (ptr @var, i32 0, i64 65535, ptr null, i64 0)

>From a780d181fa69236d5909759a24a1134b50313980 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Tue, 9 Sep 2025 17:18:49 -0700
Subject: [PATCH 3/6] Address review comment

Created using spr 1.3.6-beta.1
---
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 3 +++
 llvm/lib/IR/Verifier.cpp  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 045ed204620fb..04fe4c57af6ed 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1613,6 +1613,9 @@ Expected 
BitcodeReader::materializeValue(unsigned StartValID,
   ConstOps.size() > 4 ? ConstOps[4]
   : ConstantPointerNull::get(cast(
 ConstOps[3]->getType()));
+  if (DeactivationSymbol->getType()->isPointerTy())
+return error(
+"ptrauth deactivation symbol operand must be a pointer");
 
   C = ConstantPtrAuth::get(ConstOps[0], Key, Disc, ConstOps[3],
DeactivationSymbol);
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 9e44dfb387615..a53ba17e26011 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2632,6 +2632,9 @@ void Verifier::visitConstantPtrAuth(const ConstantPtrAuth 
*CPA) {
   Check(CPA->getDiscriminator()->getBitWidth() == 64,
 "signed ptrauth constant discriminator must be i64 constant integer");
 
+  Check(CPA->getDeactivationSymbol()->getType()->isPointerTy(),
+"signed ptrauth constant deactivation symbol must be a pointer");
+
   Check(isa(CPA->getDeactivationSymbol()) ||
 CPA->getDeactivationSymbol()->isNullValue(),
 "signed ptrauth constant deactivation symbol must be a global value "

>From 51c353bbde24f940e3dfd7488aec0682dbef260b Mon Se