Skip to content

Commit aa972f6

Browse files
committed
-fsanitize=function,MicrosoftMangle: Switch to xxh3_64bits
Following recent changes switching from xxh64 to xxh32 for better hashing performance (e.g., D154813). These particular instances likely have negligible time, but this change moves us toward removing xxHash64. The type hash for -fsanitize=function will change, following a recent change D148785 (not in any release yet) to the type hash scheme, though sanitizers don't sign up for cross-version compatibility anyway. The MicrosoftMangle instance is for internal symbols that need no compatibility guarantee, as emphasized by the comment.
1 parent a6302b6 commit aa972f6

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ MicrosoftMangleContextImpl::MicrosoftMangleContextImpl(ASTContext &Context,
485485
SourceManager &SM = Context.getSourceManager();
486486
if (const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID())) {
487487
// Truncate the hash so we get 8 characters of hexadecimal.
488-
uint32_t TruncatedHash = uint32_t(xxHash64(FE->getName()));
488+
uint32_t TruncatedHash = uint32_t(xxh3_64bits(FE->getName()));
489489
AnonymousNamespaceHash = llvm::utohexstr(TruncatedHash);
490490
} else {
491491
// If we don't have a path to the main file, we'll just use 0.

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
577577
std::string Mangled;
578578
llvm::raw_string_ostream Out(Mangled);
579579
CGM.getCXXABI().getMangleContext().mangleTypeName(Ty, Out, false);
580-
return llvm::ConstantInt::get(CGM.Int32Ty,
581-
static_cast<uint32_t>(llvm::xxHash64(Mangled)));
580+
return llvm::ConstantInt::get(
581+
CGM.Int32Ty, static_cast<uint32_t>(llvm::xxh3_64bits(Mangled)));
582582
}
583583

584584
void CodeGenFunction::EmitKernelMetadata(const FunctionDecl *FD,

clang/test/CodeGen/ubsan-function.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void fun() {}
1717
// CHECK: [[LABEL1]]:
1818
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 1, !nosanitize
1919
// CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
20-
// CHECK: icmp eq i32 {{.*}}, -1522505972, !nosanitize
20+
// CHECK: icmp eq i32 {{.*}}, 905068220, !nosanitize
2121
// CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], {{.*}}!nosanitize
2222
// CHECK: [[LABEL2]]:
2323
// 64: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], i64 %[[#]]) #[[#]], !nosanitize
@@ -32,4 +32,4 @@ void fun() {}
3232
// CHECK-NEXT: ret void
3333
void caller(void (*f)()) { f(); }
3434

35-
// CHECK: ![[FUNCSAN]] = !{i32 -1056584962, i32 -1522505972}
35+
// CHECK: ![[FUNCSAN]] = !{i32 -1056584962, i32 905068220}

clang/test/CodeGenCXX/catch-undef-behavior.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void indirect_function_call(void (*p)(int)) {
405405
// CalleeTypeHash check
406406
// CHECK: [[CalleeTypeHashPtr:%.+]] = getelementptr <{ i32, i32 }>, ptr [[PTR]], i32 -1, i32 1
407407
// CHECK-NEXT: [[CalleeTypeHash:%.+]] = load i32, ptr [[CalleeTypeHashPtr]]
408-
// CHECK-NEXT: [[CalleeTypeHashMatch:%.+]] = icmp eq i32 [[CalleeTypeHash]], 27004076
408+
// CHECK-NEXT: [[CalleeTypeHashMatch:%.+]] = icmp eq i32 [[CalleeTypeHash]], -1988405058
409409
// CHECK-NEXT: br i1 [[CalleeTypeHashMatch]]
410410

411411
p(42);
@@ -740,4 +740,4 @@ void ThisAlign::this_align_lambda_2() {
740740

741741
// CHECK: attributes [[NR_NUW]] = { noreturn nounwind }
742742

743-
// CHECK-FUNCSAN: ![[FUNCSAN]] = !{i32 -1056584962, i32 -1302768377}
743+
// CHECK-FUNCSAN: ![[FUNCSAN]] = !{i32 -1056584962, i32 -1000226989}

0 commit comments

Comments
 (0)