Skip to content

Commit 434aec2

Browse files
committed
Fix for opt-remarks
The output of opt-remarks is non-deterministic because it checks the output while iterating over a DenseMap. To fix this issue, we can replace DenseMap with MapVector.
1 parent aed73c6 commit 434aec2

9 files changed

+14
-14
lines changed

clang/test/BoundsSafety/CodeGen/opt-remarks/bounds-safety-missed-binop-overflow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -fbounds-safety -Os %s -triple arm64-apple-iphoneos -emit-llvm -o %t-Os.s -opt-record-file %t-Os.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-Os.opt.yaml --check-prefixes OPT-REM %s

clang/test/BoundsSafety/CodeGen/opt-remarks/bounds-safety-missed-ptr-induction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -fbounds-safety -Os %s -triple arm64-apple-iphoneos -emit-llvm -o %t-Os.s -opt-record-file %t-Os.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-Os.opt.yaml --check-prefixes OPT-REM %s

clang/test/BoundsSafety/CodeGen/opt-remarks/bounds-safety-ptr-conversion-O0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -triple x86_64-apple-macos -Wno-bounds-safety-init-list -fbounds-safety -O0 %s -emit-llvm -o %t-O0.s -opt-record-file %t-O0.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-O0.s --check-prefixes IR %s

clang/test/BoundsSafety/CodeGen/opt-remarks/bounds-safety-ptr-conversion-O2.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int main(int argc, char **argv) {
106106
// OPT-REM-NEXT: Pass: annotation-remarks
107107
// OPT-REM-NEXT: Name: BoundsSafetyCheck
108108
// OPT-REM-NEXT: DebugLoc: { File: '{{.*}}bounds-safety-ptr-conversion-O2.c',
109-
// OPT-REM-NEXT: Line: 0, Column: 0 }
109+
// OPT-REM-NEXT: Line: 12, Column: 25 }
110110
// OPT-REM-NEXT: Function: main
111111
// OPT-REM-NEXT: Args:
112112
// OPT-REM-NEXT: - String: 'Inserted '
@@ -115,20 +115,20 @@ int main(int argc, char **argv) {
115115
// OPT-REM-NEXT: - String: s
116116
// OPT-REM-NEXT: - String: "\n"
117117
// OPT-REM-NEXT: - String: "used for:\n"
118-
// OPT-REM-NEXT: - String: bounds-safety-generic, bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
118+
// OPT-REM-NEXT: - String: bounds-safety-check-ptr-neq-null
119119
// OPT-REM-NEXT: - String: |
120120
// OPT-REM-NEXT: {{^[ ]+$}}
121121
// OPT-REM-NEXT: {{^[ ]+$}}
122122
// OPT-REM-NEXT: instructions:
123123
// OPT-REM-EMPTY:
124-
// OPT-REM-NEXT: - String: "trap (LLVM IR 'call')\nother (LLVM IR 'unreachable')"
124+
// OPT-REM-NEXT: - String: "cmp eq (LLVM IR 'icmp')\ncond branch (LLVM IR 'br')"
125125
// OPT-REM-NEXT: ...
126126

127127
// OPT-REM-NEXT: --- !Analysis
128128
// OPT-REM-NEXT: Pass: annotation-remarks
129129
// OPT-REM-NEXT: Name: BoundsSafetyCheck
130130
// OPT-REM-NEXT: DebugLoc: { File: '{{.*}}bounds-safety-ptr-conversion-O2.c',
131-
// OPT-REM-NEXT: Line: 12, Column: 25 }
131+
// OPT-REM-NEXT: Line: 0, Column: 0 }
132132
// OPT-REM-NEXT: Function: main
133133
// OPT-REM-NEXT: Args:
134134
// OPT-REM-NEXT: - String: 'Inserted '
@@ -137,13 +137,13 @@ int main(int argc, char **argv) {
137137
// OPT-REM-NEXT: - String: s
138138
// OPT-REM-NEXT: - String: "\n"
139139
// OPT-REM-NEXT: - String: "used for:\n"
140-
// OPT-REM-NEXT: - String: bounds-safety-check-ptr-neq-null
140+
// OPT-REM-NEXT: - String: bounds-safety-generic, bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
141141
// OPT-REM-NEXT: - String: |
142142
// OPT-REM-NEXT: {{^[ ]+$}}
143143
// OPT-REM-NEXT: {{^[ ]+$}}
144144
// OPT-REM-NEXT: instructions:
145145
// OPT-REM-EMPTY:
146-
// OPT-REM-NEXT: - String: "cmp eq (LLVM IR 'icmp')\ncond branch (LLVM IR 'br')"
146+
// OPT-REM-NEXT: - String: "trap (LLVM IR 'call')\nother (LLVM IR 'unreachable')"
147147
// OPT-REM-NEXT: ...
148148

149149
// OPT-REM-NOT: --- !Analysis

clang/test/BoundsSafety/CodeGen/opt-remarks/ptr-bounds-argc-O0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -fbounds-safety -O0 %s -emit-llvm -o %t-O0.s -opt-record-file %t-O0.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-O0.s --check-prefixes IR %s

clang/test/BoundsSafety/CodeGen/opt-remarks/ptr-bounds-const-O0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -fbounds-safety -O0 %s -emit-llvm -o %t-O0.s -opt-record-file %t-O0.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-O0.s --check-prefixes IR %s

clang/test/BoundsSafety/CodeGen/opt-remarks/ptr-count-assignment-argc-O0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -triple x86_64-apple-macos -fbounds-safety -O0 %s -emit-llvm -o %t-O0.s -opt-record-file %t-O0.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-O0.s --check-prefixes IR %s

clang/test/BoundsSafety/CodeGen/opt-remarks/ptr-count-assignment-const-O0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: *
1+
22

33
// RUN: %clang_cc1 -triple x86_64-apple-macos -fbounds-safety -O0 %s -emit-llvm -o %t-O0.s -opt-record-file %t-O0.opt.yaml -opt-record-format yaml
44
// RUN: FileCheck --input-file %t-O0.s --check-prefixes IR %s

llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void runImpl(Function &F, const TargetLibraryInfo &TLI) {
133133
return;
134134

135135
// Track all annotated instructions aggregated based on their debug location.
136-
DenseMap<MDNode *, SmallVector<Instruction *, 4>> DebugLoc2Annotated;
136+
MapVector<MDNode *, SmallVector<Instruction *, 4>> DebugLoc2Annotated;
137137

138138
OptimizationRemarkEmitter ORE(&F);
139139
// First, generate a summary of the annotated instructions.

0 commit comments

Comments
 (0)