Skip to content

Conversation

@aaupov
Copy link
Contributor

@aaupov aaupov commented Jun 3, 2025

#140196 introduced UB by using uninitialized misprediction count for
pre-aggregated traces. Fix by zero initializing both counters.

Test Plan: updated entry-point-fallthru.s

aaupov added 2 commits June 3, 2025 16:55
Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2025

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

Changes

pre-aggregated traces. Fix by zero initializing both counters.

Test Plan: updated entry-point-fallthru.s


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

2 Files Affected:

  • (modified) bolt/lib/Profile/DataAggregator.cpp (+1-1)
  • (modified) bolt/test/X86/entry-point-fallthru.s (+4)
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index f51d4ae2799e2..134c9324603b2 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -1220,7 +1220,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
   // Storage for parsed fields.
   StringRef EventName;
   std::optional<Location> Addr[3];
-  int64_t Counters[2];
+  int64_t Counters[2] = {0};
 
   while (Type == INVALID || Type == EVENT_NAME) {
     while (checkAndConsumeFS()) {
diff --git a/bolt/test/X86/entry-point-fallthru.s b/bolt/test/X86/entry-point-fallthru.s
index edf14247b0c43..850247b97d27e 100644
--- a/bolt/test/X86/entry-point-fallthru.s
+++ b/bolt/test/X86/entry-point-fallthru.s
@@ -6,6 +6,10 @@
 # RUN: link_fdata %s %t %t.preagg PREAGG
 # RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata | FileCheck %s
 # CHECK: traces mismatching disassembled function contents: 0
+# RUN: FileCheck %s --check-prefix=CHECK-FDATA --input-file %t.fdata
+# CHECK-FDATA:      1 main 0 1 main 6 0 1
+# CHECK-FDATA-NEXT: 1 main e 1 main 11 0 1
+# CHECK-FDATA-NEXT: 1 main 11 1 main 0 0 1
 
 	.globl main
 main:

preames and others added 2 commits June 3, 2025 20:49
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@aaupov aaupov requested a review from paschalis-mpeis as a code owner June 4, 2025 03:49
@aaupov aaupov changed the base branch from users/aaupov/spr/main.bolt-zero-initialize-pre-aggregated-counters to main June 4, 2025 03:50
@aaupov aaupov merged commit dc513fa into main Jun 4, 2025
8 of 15 checks passed
@aaupov aaupov deleted the users/aaupov/spr/bolt-zero-initialize-pre-aggregated-counters branch June 4, 2025 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants