[llvm-branch-commits] [llvm] workflows/release-binaries: Run tests on the same runner as the build (#162421) (PR #162926)

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

llvmbot wrote:




@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)


Changes

Also, ignore the test results since they almost always fail. This allows us to 
simplify the build process and skip uploading and downloading the build and 
source directories which are huge.

(cherry picked from commit 9f0f6e8dda5a3f87458acbb4daf09c2bfbac25f2)

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


3 Files Affected:

- (removed) .github/workflows/release-binaries-save-stage/action.yml (-44) 
- (removed) .github/workflows/release-binaries-setup-stage/action.yml (-59) 
- (modified) .github/workflows/release-binaries.yml (+21-65) 


``diff
diff --git a/.github/workflows/release-binaries-save-stage/action.yml 
b/.github/workflows/release-binaries-save-stage/action.yml
deleted file mode 100644
index f08088c7bc56f..0
--- a/.github/workflows/release-binaries-save-stage/action.yml
+++ /dev/null
@@ -1,44 +0,0 @@
-name: Save Stage
-description: >-
-  Upload the source and binary directories from a build stage so that they
-  can be re-used in the next stage.  This action is used to the release
-  binaries workflow into multiple stages to avoid the 6 hour timeout on
-  the GitHub hosted runners.
-inputs:
-  build-prefix:
-description: "Directory containing the build directory."
-required: true
-type: 'string'
-
-permissions:
-  contents: read
-
-runs:
-  using: "composite"
-  steps:
-# We need to create an archive of the build directory, because it has too
-# many files to upload.
-- name: Package Build and Source Directories
-  shell: bash
-  run: |
-# Remove .git/config to avoid leaking GITHUB_TOKEN stored there.
-# See 
https://unit42.paloaltonetworks.com/github-repo-artifacts-leak-tokens/
-rm -Rf .git/config
-# Windows does not support symlinks, so we need to dereference them.
-tar --exclude build/ ${{ (runner.os == 'Windows' && '-h') || '' }} -c 
. | zstd -T0 -c > ../llvm-project.tar.zst
-mv ../llvm-project.tar.zst .
-tar -C ${{ inputs.build-prefix }} -c build/ | zstd -T0 -c > 
build.tar.zst
-
-- name: Upload Stage 1 Source
-  uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 
#v4.3.0
-  with:
-name: ${{ runner.os }}-${{ runner.arch }}-${{ github.job }}-source
-path: llvm-project.tar.zst
-retention-days: 2
-
-- name: Upload Stage 1 Build Dir
-  uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 
#v4.3.0
-  with:
-name: ${{ runner.os}}-${{ runner.arch }}-${{ github.job }}-build
-path: build.tar.zst
-retention-days: 2
diff --git a/.github/workflows/release-binaries-setup-stage/action.yml 
b/.github/workflows/release-binaries-setup-stage/action.yml
deleted file mode 100644
index f5e5db27e6595..0
--- a/.github/workflows/release-binaries-setup-stage/action.yml
+++ /dev/null
@@ -1,59 +0,0 @@
-name: Setup Stage
-description: >-
-  Setup the next stage of the release binaries workflow.  This sets up the
-  environment correctly for a new stage of the release binaries workflow
-  and also restores the source and build directory from the previous stage.
-
-inputs:
-  previous-artifact:
-description: >-
-  A unique descriptor for the artifact from the previous stage.  This will
-  be used to construct the final artifact pattern, which is:
-  $RUNNER_OS-$RUNNER_ARCH-$PREVIOUS_ARTIFACT-*
-required: false
-type: 'string'
-
-outputs:
-  build-prefix:
-description: "Directory containing the build directory."
-value: ${{ steps.build-prefix.outputs.build-prefix }}
-
-runs:
-  using: "composite"
-  steps:
-- name: Install Ninja
-  uses: 
llvm/actions/install-ninja@22e9f909d35b50bd1181709564bfe816eaeaae81 # main
-   
-- name: Setup Windows
-  if: startsWith(runner.os, 'Windows')
-  uses: llvm/actions/setup-windows@main
-  with:
-arch: amd64
-
-- name: Set Build Prefix
-  id: build-prefix
-  shell: bash
-  run: |
-build_prefix=`pwd`
-if [ "${{ runner.os }}" = "Linux" ]; then
-  sudo chown $USER:$USER /mnt/
-  build_prefix=/mnt/
-fi
-echo "build-prefix=$build_prefix" >> $GITHUB_OUTPUT
-
-- name: Download Previous Stage Artifact
-  if: ${{ inputs.previous-artifact }}
-  id: download
-  uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 
# v4.1.1
-  with:
-pattern: ${{ runner.os }}-${{ runner.arch }}-${{ 
inputs.previous-artifact }}-*
-merge-multiple: true
-
-- name: Unpack Artifact
-  if: ${{ steps.download.outputs.download-path }}
-  shell: bash
-  run: |
-tar --zstd -xf llvm-project.tar.zst
-rm llvm-project.tar.zst
-tar --zstd -C ${{ steps.build-prefix.outputs.build-prefix}} -xf 
build.tar.zst
-rm build.tar.zst
diff --git a/.github/workflows/

[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-10 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/162806

Backport 51eee2010d3184f21502d12d69c0234549ee3fb4

Requested by: @brad0

>From 74e4a11f70091006067c20d48b04895e02168bc8 Mon Sep 17 00:00:00 2001
From: yingopq <[email protected]>
Date: Fri, 10 Oct 2025 16:40:22 +0800
Subject: [PATCH] [Mips] Fix clang crashes when assembling invalid MIPS beql
 instructions with --arch=mips (#156413)

>From clang version 4, mips append new instruction BeqImm and
BEQLImm, the second operand format of instruction is imm64:$imm.

1.When Mips process `beql $t0, ($t0), 1`, it think the second operand
was an imm, so match success. Then mips backend process expandBranchImm,
check the second operand `$t0` was not imm, reported asserts.
We can strengthen the second operand matching restrictions.

2.Similarly, when Mips process `beql $t0, (1), 1`, it think the second
was an imm. so match success. Then mips backend process expandBranchImm,
check the third operand `1` was not expression, reported asserts. Permit
the third operand of `beql`  to be imm.

Fixes #151453.

(cherry picked from commit 51eee2010d3184f21502d12d69c0234549ee3fb4)
---
 llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp |  2 +-
 llvm/lib/Target/Mips/MipsInstrInfo.td| 16 +---
 llvm/test/MC/Mips/branch-pseudos-bad.s   |  8 
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp 
b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 01e4d17f6236d..602b89a117595 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -3676,7 +3676,7 @@ bool MipsAsmParser::expandBranchImm(MCInst &Inst, SMLoc 
IDLoc, MCStreamer &Out,
   Out, STI))
   return true;
 
-if (IsLikely) {
+if (IsLikely && MemOffsetOp.isExpr()) {
   TOut.emitRRX(OpCode, DstRegOp.getReg(), ATReg,
   MCOperand::createExpr(MemOffsetOp.getExpr()), IDLoc, STI);
   TOut.emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.td 
b/llvm/lib/Target/Mips/MipsInstrInfo.td
index b6125b972717a..255fd838a72a2 100644
--- a/llvm/lib/Target/Mips/MipsInstrInfo.td
+++ b/llvm/lib/Target/Mips/MipsInstrInfo.td
@@ -858,6 +858,16 @@ def calltarget  : Operand {
 
 def imm64: Operand;
 
+def ConstantImmAsmOperandClass : AsmOperandClass {
+  let Name = "ConstantImm";
+  let PredicateMethod = "isConstantImm";
+  let RenderMethod = "addImmOperands";
+}
+
+def ConstantImm64: Operand {
+  let ParserMatchClass = ConstantImmAsmOperandClass;
+}
+
 def simm19_lsl2 : Operand {
   let EncoderMethod = "getSimm19Lsl2Encoding";
   let DecoderMethod = "DecodeSimm19Lsl2";
@@ -2950,10 +2960,10 @@ def : MipsInstAlias<"nor\t$rs, $imm", (NORImm 
GPR32Opnd:$rs, GPR32Opnd:$rs,
 
 let hasDelaySlot = 1, isCTI = 1 in {
 def BneImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt),
-   (ins imm64:$imm64, brtarget:$offset),
+   (ins ConstantImm64:$imm64, brtarget:$offset),
"bne\t$rt, $imm64, $offset">;
 def BeqImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt),
-   (ins imm64:$imm64, brtarget:$offset),
+   (ins ConstantImm64:$imm64, brtarget:$offset),
"beq\t$rt, $imm64, $offset">;
 
 class CondBranchPseudo :
@@ -2981,7 +2991,7 @@ def BGTUL: CondBranchPseudo<"bgtul">, 
ISA_MIPS2_NOT_32R6_64R6;
 
 let isCTI = 1 in
 class CondBranchImmPseudo :
-  MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, imm64:$imm, brtarget:$offset),
+  MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, ConstantImm64:$imm, 
brtarget:$offset),
 !strconcat(instr_asm, "\t$rs, $imm, $offset")>;
 
 def BEQLImmMacro : CondBranchImmPseudo<"beql">, ISA_MIPS2_NOT_32R6_64R6;
diff --git a/llvm/test/MC/Mips/branch-pseudos-bad.s 
b/llvm/test/MC/Mips/branch-pseudos-bad.s
index c23164d904619..9633414d84f4a 100644
--- a/llvm/test/MC/Mips/branch-pseudos-bad.s
+++ b/llvm/test/MC/Mips/branch-pseudos-bad.s
@@ -1,5 +1,13 @@
 # RUN: not llvm-mc %s -triple=mips -mcpu=mips32 2>&1 | FileCheck %s
 
+# CHECK: error: invalid operand for instruction
+  beql $t0, ($t0), 1
+# CHECK: error: invalid operand for instruction
+  bne $t0, ($t0), 1
+# CHECK: error: invalid operand for instruction
+  beq $t0, ($t0), 1
+
+
 # Check for errors when using conditional branch pseudos after .set noat.
   .set noat
 local_label:

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


[llvm-branch-commits] [llvm] CodeGen: Make target overrides of PointerLikeRegClass mandatory (PR #159882)

2025-10-10 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> Hi @arsenm ,
> 
> I haven't followed the discussion on all that. What's the rationale for all 
> that stuff?
> 
> Cheers, -Quentin

I want to eliminate getPointerRegClass. It's a layering violation. We should be 
able to interpret an MCOperandInfo without codegen throughout MC. This only 
depends on the MCInstrInfo and HwMode/Subtarget. Each target's InstrInfo table 
defines copies of all of the common pseudo instructions anyway, so this series 
of patches just swaps out the operand definitions to use the correct register 
class for the pointer types 

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


[llvm-branch-commits] [llvm] AMDGPU: Remove override of TargetInstrInfo::getRegClass (PR #159886)

2025-10-10 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/159886

>From 70ed5e89ee0bcfa8a0213a9ab7948e6557351e0b Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 18 Sep 2025 08:54:13 +0900
Subject: [PATCH] AMDGPU: Remove override of TargetInstrInfo::getRegClass

This should not be overridable and the special case hacks
have been replaced with RegClassByHwMode
---
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 13 -
 llvm/lib/Target/AMDGPU/SIInstrInfo.h   |  4 
 2 files changed, 17 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp 
b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index f2ad8886b3871..751dc6f2cfe93 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -6031,19 +6031,6 @@ SIInstrInfo::getWholeWaveFunctionSetup(MachineFunction 
&MF) const {
   llvm_unreachable("Couldn't find SI_SETUP_WHOLE_WAVE_FUNC instruction");
 }
 
-// FIXME: This should not be an overridable function. All subtarget dependent
-// operand modifications should go through isLookupRegClassByHwMode in the
-// generic handling.
-const TargetRegisterClass *
-SIInstrInfo::getRegClass(const MCInstrDesc &TID, unsigned OpNum,
- const TargetRegisterInfo *TRI) const {
-  if (OpNum >= TID.getNumOperands())
-return nullptr;
-  const MCOperandInfo &OpInfo = TID.operands()[OpNum];
-  int16_t RegClass = getOpRegClassID(OpInfo);
-  return RegClass < 0 ? nullptr : RI.getRegClass(RegClass);
-}
-
 const TargetRegisterClass *SIInstrInfo::getOpRegClass(const MachineInstr &MI,
   unsigned OpNo) const {
   const MCInstrDesc &Desc = get(MI.getOpcode());
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h 
b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index e979eeb0bdf3a..475d439b2ac35 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1562,10 +1562,6 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
   /// Return true if this opcode should not be used by codegen.
   bool isAsmOnlyOpcode(int MCOp) const;
 
-  const TargetRegisterClass *
-  getRegClass(const MCInstrDesc &TID, unsigned OpNum,
-  const TargetRegisterInfo *TRI) const override;
-
   void fixImplicitOperands(MachineInstr &MI) const;
 
   MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,

___
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-10 Thread Paul Kirth via llvm-branch-commits

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

>From 98082984b1808471a721853ec5ae124e48ef0005 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] [clang-tools-extra] [clang-doc] create namespace names according to their paths (PR #162886)

2025-10-10 Thread Erick Velez via llvm-branch-commits

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


[llvm-branch-commits] Prepare libcxx and libcxxabi for pointer field protection. (PR #151651)

2025-10-10 Thread Nikolas Klauser via llvm-branch-commits

https://github.com/philnik777 commented:

More generally, I feel like PFP needs its own `__config_site` instead of the 
ad-hoc annotations all around. @ldionne any thoughts?

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] create namespace names according to their paths (PR #162886)

2025-10-10 Thread Erick Velez via llvm-branch-commits

https://github.com/evelez7 updated 
https://github.com/llvm/llvm-project/pull/162886

>From 816782582637b8f0e3fde6aeb990eaa412fe8ffa Mon Sep 17 00:00:00 2001
From: Erick Velez 
Date: Fri, 10 Oct 2025 09:52:49 -0700
Subject: [PATCH] [clang-doc] create namespace names according to their paths

Namespace filenames didn't consider their paths, so foo::tools would use
the same file as bar::tools. Now we consider their paths to avoid that
problem.
---
 clang-tools-extra/clang-doc/JSONGenerator.cpp | 10 +-
 .../clang-doc/json/multiple-namespaces.cpp| 20 +++
 .../test/clang-doc/json/nested-namespace.cpp  |  2 +-
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp

diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 6fba2114b8c38..b17cc80bdba34 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -584,12 +584,20 @@ static SmallString<16> determineFileName(Info *I, 
SmallString<128> &Path) {
 FileName = RecordSymbolInfo->MangledName;
   } else if (I->USR == GlobalNamespaceID)
 FileName = "index";
-  else
+  else if (I->IT == InfoType::IT_namespace) {
+for (const auto &NS : I->Namespace) {
+  FileName += NS.Name;
+  FileName += "_";
+}
+FileName += I->Name;
+  } else
 FileName = I->Name;
   sys::path::append(Path, FileName + ".json");
   return FileName;
 }
 
+// FIXME: Revert back to creating nested directories for namespaces instead of
+// putting everything in a flat directory structure.
 Error JSONGenerator::generateDocs(
 StringRef RootDir, llvm::StringMap> Infos,
 const ClangDocContext &CDCtx) {
diff --git a/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp 
b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
new file mode 100644
index 0..04fcfc1dc0a85
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO
+// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR
+
+namespace foo {
+  namespace tools {
+class FooTools {};
+  } // namespace tools
+} // namespace foo
+
+namespace bar {
+  namespace tools {
+class BarTools {};
+  } // namespace tools
+} // namespace bar
+
+// CHECK-FOO: "Name": "tools"
+
+// CHECK-BAR: "Name": "tools"
diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp 
b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
index b19afc1885104..cf19e1e34a818 100644
--- a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t && mkdir -p %t
 // RUN: clang-doc --output=%t --format=json --executor=standalone %s
 // RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
-// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER
+// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER
 
 namespace nested {
   int Global;

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


[llvm-branch-commits] [clang-tools-extra] [clang-doc] create namespace names according to their paths (PR #162886)

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

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


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


[llvm-branch-commits] [llvm] [StaticDataLayout] Factor out a helper function for section prefix eligibility and use it in both optimizer and codegen (PR #162348)

2025-10-10 Thread Mingming Liu via llvm-branch-commits

https://github.com/mingmingl-llvm updated 
https://github.com/llvm/llvm-project/pull/162348

>From f68b06f65609078d7e1c788e95d78fab397e4966 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Tue, 7 Oct 2025 11:59:13 -0700
Subject: [PATCH 01/10] [nfc][StaticDataLayout]Add helper functions to tell the
 eligibility status of a global variable for section prefix annotation

---
 .../llvm/Analysis/StaticDataProfileInfo.h | 18 +
 llvm/lib/Analysis/StaticDataProfileInfo.cpp   | 37 +++
 llvm/lib/CodeGen/StaticDataAnnotator.cpp  | 15 +---
 .../Transforms/Instrumentation/MemProfUse.cpp | 30 ---
 4 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/llvm/include/llvm/Analysis/StaticDataProfileInfo.h 
b/llvm/include/llvm/Analysis/StaticDataProfileInfo.h
index fa21eba1377df..f06e7ceaa74ce 100644
--- a/llvm/include/llvm/Analysis/StaticDataProfileInfo.h
+++ b/llvm/include/llvm/Analysis/StaticDataProfileInfo.h
@@ -10,6 +10,24 @@
 
 namespace llvm {
 
+namespace memprof {
+// Represents the eligibility status of a global variable for section prefix
+// annotation. Other than AnnotationOk, each enum value indicates a specific
+// reason for ineligibility.
+enum class AnnotationKind : uint8_t {
+  AnnotationOK,
+  DeclForLinker,
+  ExplicitSection,
+  ReservedName,
+};
+/// Returns the annotation kind of the global variable \p GV.
+AnnotationKind getAnnotationKind(const GlobalVariable &GV);
+
+/// Returns true if the annotation kind of the global variable \p GV is
+/// AnnotationOK.
+bool IsAnnotationOK(const GlobalVariable &GV);
+} // namespace memprof
+
 /// A class that holds the constants that represent static data and their
 /// profile information and provides methods to operate on them.
 class StaticDataProfileInfo {
diff --git a/llvm/lib/Analysis/StaticDataProfileInfo.cpp 
b/llvm/lib/Analysis/StaticDataProfileInfo.cpp
index b036b2dde770e..ff4582ca7eeb1 100644
--- a/llvm/lib/Analysis/StaticDataProfileInfo.cpp
+++ b/llvm/lib/Analysis/StaticDataProfileInfo.cpp
@@ -6,6 +6,43 @@
 #include "llvm/ProfileData/InstrProf.h"
 
 using namespace llvm;
+
+namespace llvm {
+namespace memprof {
+// Returns true iff the global variable has custom section either by
+// __attribute__((section("name")))
+// 
(https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate)
+// or #pragma clang section directives
+// 
(https://clang.llvm.org/docs/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section).
+static bool hasExplicitSectionName(const GlobalVariable &GVar) {
+  if (GVar.hasSection())
+return true;
+
+  auto Attrs = GVar.getAttributes();
+  if (Attrs.hasAttribute("bss-section") || Attrs.hasAttribute("data-section") 
||
+  Attrs.hasAttribute("relro-section") ||
+  Attrs.hasAttribute("rodata-section"))
+return true;
+  return false;
+}
+
+AnnotationKind getAnnotationKind(const GlobalVariable &GV) {
+  if (GV.isDeclarationForLinker())
+return AnnotationKind::DeclForLinker;
+  StringRef Name = GV.getName();
+  if (Name.starts_with("llvm."))
+return AnnotationKind::ReservedName;
+  if (hasExplicitSectionName(GV))
+return AnnotationKind::ExplicitSection;
+  return AnnotationKind::AnnotationOK;
+}
+
+bool IsAnnotationOK(const GlobalVariable &GV) {
+  return getAnnotationKind(GV) == AnnotationKind::AnnotationOK;
+}
+} // namespace memprof
+} // namespace llvm
+
 void StaticDataProfileInfo::addConstantProfileCount(
 const Constant *C, std::optional Count) {
   if (!Count) {
diff --git a/llvm/lib/CodeGen/StaticDataAnnotator.cpp 
b/llvm/lib/CodeGen/StaticDataAnnotator.cpp
index 53a9ab4dbda02..9a68ee96ab056 100644
--- a/llvm/lib/CodeGen/StaticDataAnnotator.cpp
+++ b/llvm/lib/CodeGen/StaticDataAnnotator.cpp
@@ -75,22 +75,11 @@ bool StaticDataAnnotator::runOnModule(Module &M) {
 
   bool Changed = false;
   for (auto &GV : M.globals()) {
-if (GV.isDeclarationForLinker())
+if (!llvm::memprof::IsAnnotationOK(GV))
   continue;
 
-// The implementation below assumes prior passes don't set section 
prefixes,
-// and specifically do 'assign' rather than 'update'. So report error if a
-// section prefix is already set.
-if (auto maybeSectionPrefix = GV.getSectionPrefix();
-maybeSectionPrefix && !maybeSectionPrefix->empty())
-  llvm::report_fatal_error("Global variable " + GV.getName() +
-   " already has a section prefix " +
-   *maybeSectionPrefix);
-
 StringRef SectionPrefix = SDPI->getConstantSectionPrefix(&GV, PSI);
-if (SectionPrefix.empty())
-  continue;
-
+// setSectionPrefix returns true if the section prefix is changed.
 Changed |= GV.setSectionPrefix(SectionPrefix);
   }
 
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp 
b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
index d86fcf268ce4f..ca2af1a9534d3 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
+++ b/

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

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

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

>From e816ed160ed53ff8d9d9039b778c41ecad8a7da2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 6 Aug 2025 17:12:25 -0700
Subject: [PATCH 1/2] Add tests and documentation

Created using spr 1.3.6-beta.1
---
 clang/docs/StructureProtection.rst   |  32 +++-
 clang/docs/index.rst |   1 +
 clang/lib/CodeGen/CGCall.cpp |  21 ++-
 clang/test/CodeGenCXX/pfp-coerce.cpp | 220 +++
 clang/test/CodeGenCXX/pfp-null-init.cpp  |  13 +-
 clang/test/CodeGenCXX/pfp-struct-gep.cpp |  29 ++-
 6 files changed, 296 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pfp-coerce.cpp

diff --git a/clang/docs/StructureProtection.rst 
b/clang/docs/StructureProtection.rst
index 06187f270d49a..6db01cc579b8e 100644
--- a/clang/docs/StructureProtection.rst
+++ b/clang/docs/StructureProtection.rst
@@ -9,11 +9,12 @@ Structure Protection
 Introduction
 
 
-Structure protection is an experimental mitigation against use-after-free
-vulnerabilities. For more details, please see the original `RFC
+Structure protection is an *experimental* mitigation
+against use-after-free vulnerabilities. For
+more information, please see the original `RFC
 
`_.
-An independent set of documentation will be added here when the feature
-is promoted to non-experimental.
+An independent set of documentation will be contributed when the feature
+is promoted to stable.
 
 Usage
 =
@@ -24,9 +25,30 @@ To use structure protection, build your program using one of 
the flags:
   field protection with untagged pointers.
 
 - ``-fexperimental-pointer-field-protection=tagged``: Enable pointer
-  field protection with heap pointers assumed to be tagged by the allocator:
+  field protection with heap pointers assumed to be tagged by the allocator.
 
 The entire C++ part of the program must be built with a consistent
 ``-fexperimental-pointer-field-protection`` flag, and the C++ standard
 library must also be built with the same flag and statically linked into
 the program.
+
+To build libc++ with pointer field protection support, pass the following
+CMake flags:
+
+.. code-block:: console
+ 
+"-DRUNTIMES_${triple}_LIBCXXABI_ENABLE_SHARED=OFF" \
+"-DRUNTIMES_${triple}_LIBCXX_USE_COMPILER_RT=ON" \
+"-DRUNTIMES_${triple}_LIBCXX_PFP=untagged" \
+"-DRUNTIMES_${triple}_LIBCXX_ENABLE_SHARED=OFF" \
+"-DRUNTIMES_${triple}_LIBCXX_TEST_CONFIG=llvm-libc++-static.cfg.in" \
+"-DRUNTIMES_${triple}_LIBUNWIND_ENABLE_SHARED=OFF" \
+
+where ``${triple}`` is your target triple, such as
+``aarch64-unknown-linux``.
+
+The resulting toolchain may then be used to build programs
+with pointer field protection by passing ``-stdlib=libc++
+-fexperimental-pointer-field-protection=untagged`` at compile time
+and ``-Wl,-Bstatic -lc++ -lc++abi -Wl,-Bdynamic -lm -fuse-ld=lld
+-static-libstdc++`` at link time.
diff --git a/clang/docs/index.rst b/clang/docs/index.rst
index 4871d05e932ae..e267c66af1e1d 100644
--- a/clang/docs/index.rst
+++ b/clang/docs/index.rst
@@ -47,6 +47,7 @@ Using Clang as a Compiler
LTOVisibility
SafeStack
ShadowCallStack
+   StructureProtection
SourceBasedCodeCoverage
StandardCPlusPlusModules
Modules
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index f7fca42cd7a07..c26d51c28f305 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3538,6 +3538,13 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
   if (SrcSize > DstSize) {
 Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize);
   }
+
+  // Structures with PFP fields require a coerced store to add any
+  // pointer signatures.
+  if (getContext().hasPFPFields(Ty)) {
+llvm::Value *Struct = Builder.CreateLoad(Ptr);
+CreatePFPCoercedStore(Struct, Ty, Ptr, *this);
+  }
 }
   } else {
 // Simple case, just do a coerced store of the argument into the 
alloca.
@@ -5717,15 +5724,25 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 } else {
   uint64_t SrcSize = SrcTypeSize.getFixedValue();
   uint64_t DstSize = DstTypeSize.getFixedValue();
+  bool HasPFPFields = getContext().hasPFPFields(I->Ty);
 
   // If the source type is smaller than the destination type of the
   // coerce-to logic, copy the source value into a temp alloca the size
   // of the destination type to allow loading all of it. The bits past
   // the source value are left undef.
-  if (SrcSize < DstSize) {
+  if (HasPFPFields || SrcSize < DstSize) {
 Address TempAlloca = CreateTempAlloca(STy, Src.getAlignment(),
  

[llvm-branch-commits] [libc++] Add build and CI support for pointer field protection (PR #152414)

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

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


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


[llvm-branch-commits] [libc++] Add build and CI support for pointer field protection (PR #152414)

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

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


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


[llvm-branch-commits] [libc] Use UMAXV.4S to reduce bcmp result. (PR #99260)

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

pcc wrote:

Ping

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