diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -747,8 +747,11 @@ return Working; // Check for remaining work in Working. - if (Working) - MD5.update(Working); + if (Working) { + using namespace llvm::support; + uint64_t Swapped = endian::byte_swap(Working); + MD5.update(llvm::makeArrayRef((uint8_t *)&Swapped, sizeof(Swapped))); + } // Finalize the MD5 and return the hash. llvm::MD5::MD5Result Result; diff --git a/clang/test/Profile/c-collision.c b/clang/test/Profile/c-collision.c new file mode 100644 --- /dev/null +++ b/clang/test/Profile/c-collision.c @@ -0,0 +1,26 @@ +// Test that a slight change in the code leads to a different hash. +// RUN: %clang_cc1 -UEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=llvm | FileCheck %s --check-prefix=CHECK-NOEXTRA +// RUN: %clang_cc1 -DEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=llvm | FileCheck %s --check-prefix=CHECK-EXTRA + +// CHECK-NOEXTRA: @__profd_main = private global { {{.*}} } { i64 -2624081020897602054, i64 88870893692, +// CHECK-EXTRA: @__profd_main = private global { {{.*}} } { i64 -2624081020897602054, i64 101970072141, + +int main(int n, char **v) { + if (n) + n += 1; + if (n) + n += 1; + if (n) + n += 1; + if (n) + n += 1; + if (n) + n += 1; + if (n) + n += 1; +#ifdef EXTRA + if (n) + n += 1; +#endif + return n; +}