Skip to content

Commit 4226b60

Browse files
kyulee-comjuliannagele
authored andcommitted
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. (cherry picked from commit 434aec2)
1 parent 82a1be7 commit 4226b60

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

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: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,6 @@ int main(int argc, char **argv) {
102102
// OPT-REM-NEXT: - type: bounds-safety-total-summary
103103
// OPT-REM-NEXT: ...
104104

105-
// OPT-REM-NEXT: --- !Analysis
106-
// // OPT-REM-NEXT: Pass: annotation-remarks
107-
// // OPT-REM-NEXT: Name: BoundsSafetyCheck
108-
// // OPT-REM-NEXT: DebugLoc: { File: '{{.*}}bounds-safety-ptr-conversion-O2.c',
109-
// // OPT-REM-NEXT: Line: 0, Column: 0 }
110-
// // OPT-REM-NEXT: Function: main
111-
// // OPT-REM-NEXT: Args:
112-
// // OPT-REM-NEXT: - String: 'Inserted '
113-
// // OPT-REM-NEXT: - count: '2'
114-
// // OPT-REM-NEXT: - String: ' LLVM IR instruction'
115-
// // OPT-REM-NEXT: - String: s
116-
// // OPT-REM-NEXT: - String: "\n"
117-
// // 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
119-
// // OPT-REM-NEXT: - String: |
120-
// // OPT-REM-NEXT: {{^[ ]+$}}
121-
// // OPT-REM-NEXT: {{^[ ]+$}}
122-
// // OPT-REM-NEXT: instructions:
123-
// // OPT-REM-EMPTY:
124-
// // OPT-REM-NEXT: - String: "trap (LLVM IR 'call')\nother (LLVM IR 'unreachable')"
125-
// // OPT-REM-NEXT: ...
126-
//
127105
// OPT-REM-NEXT: --- !Analysis
128106
// OPT-REM-NEXT: Pass: annotation-remarks
129107
// OPT-REM-NEXT: Name: BoundsSafetyCheck
@@ -146,4 +124,26 @@ int main(int argc, char **argv) {
146124
// OPT-REM-NEXT: - String: "cmp eq (LLVM IR 'icmp')\ncond branch (LLVM IR 'br')"
147125
// OPT-REM-NEXT: ...
148126

127+
// OPT-REM-NEXT: --- !Analysis
128+
// OPT-REM-NEXT: Pass: annotation-remarks
129+
// OPT-REM-NEXT: Name: BoundsSafetyCheck
130+
// OPT-REM-NEXT: DebugLoc: { File: '{{.*}}bounds-safety-ptr-conversion-O2.c',
131+
// OPT-REM-NEXT: Line: 0, Column: 0 }
132+
// OPT-REM-NEXT: Function: main
133+
// OPT-REM-NEXT: Args:
134+
// OPT-REM-NEXT: - String: 'Inserted '
135+
// OPT-REM-NEXT: - count: '2'
136+
// OPT-REM-NEXT: - String: ' LLVM IR instruction'
137+
// OPT-REM-NEXT: - String: s
138+
// OPT-REM-NEXT: - String: "\n"
139+
// OPT-REM-NEXT: - String: "used for:\n"
140+
// OPT-REM-NEXT: - String: bounds-safety-generic, bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
141+
// OPT-REM-NEXT: - String: |
142+
// OPT-REM-NEXT: {{^[ ]+$}}
143+
// OPT-REM-NEXT: {{^[ ]+$}}
144+
// OPT-REM-NEXT: instructions:
145+
// OPT-REM-EMPTY:
146+
// OPT-REM-NEXT: - String: "trap (LLVM IR 'call')\nother (LLVM IR 'unreachable')"
147+
// OPT-REM-NEXT: ...
148+
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)