[clang] 6644975 - [CodeGen] Use MapVector to stabilize iteration order
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 15:10:58 PDT 2024
Author: Fangrui Song
Date: 2024-06-28T15:10:53-07:00
New Revision: 664497557ae7e726b424d325533cdce8104b3337
URL: https://github.com/llvm/llvm-project/commit/664497557ae7e726b424d325533cdce8104b3337
DIFF: https://github.com/llvm/llvm-project/commit/664497557ae7e726b424d325533cdce8104b3337.diff
LOG: [CodeGen] Use MapVector to stabilize iteration order
Otherwise clang/test/CodeGenCXX/attr-annotate.cpp
output could fail when llvm::hash_value(StringRef) changes
(#96282).
EmitGlobalAnnotations iterates over DeferredAnnotations.
Added:
Modified:
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGenCXX/attr-annotate.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 22b2b314c316c..4796d421aaa69 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -435,7 +435,7 @@ class CodeGenModule : public CodeGenTypeCache {
// Store deferred function annotations so they can be emitted at the end with
// most up to date ValueDecl that will have all the inherited annotations.
- llvm::DenseMap<StringRef, const ValueDecl *> DeferredAnnotations;
+ llvm::MapVector<StringRef, const ValueDecl *> DeferredAnnotations;
/// Map used to get unique annotation strings.
llvm::StringMap<llvm::Constant*> AnnotationStrings;
diff --git a/clang/test/CodeGenCXX/attr-annotate.cpp b/clang/test/CodeGenCXX/attr-annotate.cpp
index 64627a6b83e11..ce284c7d19982 100644
--- a/clang/test/CodeGenCXX/attr-annotate.cpp
+++ b/clang/test/CodeGenCXX/attr-annotate.cpp
@@ -3,9 +3,9 @@
//CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata"
//CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1
//CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
-//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
-//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
-//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS2:.*]] }]
+//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
+//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
+//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @.str.6, ptr @.str.1, i32 23, ptr @.args.7 }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @.args.8 }], section "llvm.metadata"
constexpr const char* str() {
return "abc";
More information about the cfe-commits
mailing list