[PATCH] D116835: Use sha256 for source file debug info checksums with MSVC compat >= 1930

2022-01-10 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D116835#3228296 , @arlosi wrote:

> I submitted a change last year to hook up the /ZH option, but it was never 
> completed. https://reviews.llvm.org/D98438

I just put some comments on that. I'm happy to provide review if you think you 
have time to complete it?

(I'll break out the toHex() related changes here and try to get those landed 
separately.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116835/new/

https://reviews.llvm.org/D116835

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116835: Use sha256 for source file debug info checksums with MSVC compat >= 1930

2022-01-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I think it's worth taking the time to hook up /ZH. Sorry we missed the patch 
last March.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116835/new/

https://reviews.llvm.org/D116835

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116835: Use sha256 for source file debug info checksums with MSVC compat >= 1930

2022-01-07 Thread Arlo Siemsen via Phabricator via cfe-commits
arlosi added a comment.

I submitted a change last year to hook up the /ZH option, but it was never 
completed. https://reviews.llvm.org/D98438


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116835/new/

https://reviews.llvm.org/D116835

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116835: Use sha256 for source file debug info checksums with MSVC compat >= 1930

2022-01-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

After sending this, I realized we should probably have a test to make sure it 
gets all the way into the .o and .pdb files correctly...

And, maybe we should hook up the /ZH flag? 
(https://docs.microsoft.com/en-us/cpp/build/reference/zh?view=msvc-170=true
 still says MD5 is default, but I guess that's just out of date)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116835/new/

https://reviews.llvm.org/D116835

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116835: Use sha256 for source file debug info checksums with MSVC compat >= 1930

2022-01-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added reviewers: thakis, rnk, arlosi.
Herald added subscribers: dexonsmith, hiraditya.
hans requested review of this revision.
Herald added projects: clang, LLVM.

>From the VS2022 release notes, it sounds like newer MSVC versions are using 
>SHA256 for these checksums: (search for "SHA-256" in 
>https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes#17.0.0)

Since D75785  laid the groundwork, let's hook 
it up.

While here, I noticed llvm::SHA256 doesn't have a method to get the hash as a 
hex string, like llvm::MD5. But we can use llvm::toHex() and actually that 
could be made more efficient and llvm::MD5 could use that too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116835

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/debug-info-file-checksum.c
  llvm/include/llvm/ADT/StringExtras.h
  llvm/include/llvm/Support/MD5.h
  llvm/lib/Support/MD5.cpp

Index: llvm/lib/Support/MD5.cpp
===
--- llvm/lib/Support/MD5.cpp
+++ llvm/lib/Support/MD5.cpp
@@ -40,10 +40,9 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Endian.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -281,14 +280,12 @@
 
 SmallString<32> MD5::MD5Result::digest() const {
   SmallString<32> Str;
-  raw_svector_ostream Res(Str);
-  for (int i = 0; i < 16; ++i)
-Res << format("%.2x", Bytes[i]);
+  toHex(Bytes, /*LowerCase*/ true, Str);
   return Str;
 }
 
-void MD5::stringifyResult(MD5Result , SmallString<32> ) {
-  Str = Result.digest();
+void MD5::stringifyResult(MD5Result , SmallVectorImpl ) {
+  toHex(Result.Bytes, /*LowerCase*/ true, Str);
 }
 
 std::array MD5::hash(ArrayRef Data) {
Index: llvm/include/llvm/Support/MD5.h
===
--- llvm/include/llvm/Support/MD5.h
+++ llvm/include/llvm/Support/MD5.h
@@ -88,7 +88,7 @@
 
   /// Translates the bytes in \p Res to a hex string that is
   /// deposited into \p Str. The result will be of length 32.
-  static void stringifyResult(MD5Result , SmallString<32> );
+  static void stringifyResult(MD5Result , SmallVectorImpl );
 
   /// Computes the hash for a given bytes.
   static std::array hash(ArrayRef Data);
Index: llvm/include/llvm/ADT/StringExtras.h
===
--- llvm/include/llvm/ADT/StringExtras.h
+++ llvm/include/llvm/ADT/StringExtras.h
@@ -162,21 +162,26 @@
   return std::string(BufPtr, std::end(Buffer));
 }
 
-/// Convert buffer \p Input to its hexadecimal representation.
-/// The returned string is double the size of \p Input.
-inline std::string toHex(StringRef Input, bool LowerCase = false) {
+inline void toHex(ArrayRef Input, bool LowerCase,
+  SmallVectorImpl ) {
   static const char *const LUT = "0123456789ABCDEF";
   const uint8_t Offset = LowerCase ? 32 : 0;
   size_t Length = Input.size();
+  Output.resize_for_overwrite(Length * 2);
 
-  std::string Output;
-  Output.reserve(2 * Length);
   for (size_t i = 0; i < Length; ++i) {
-const unsigned char c = Input[i];
-Output.push_back(LUT[c >> 4] | Offset);
-Output.push_back(LUT[c & 15] | Offset);
+const uint8_t c = Input[i];
+Output[i * 2] = LUT[c >> 4] | Offset;
+Output[i * 2 + 1] = LUT[c & 15] | Offset;
   }
-  return Output;
+}
+
+/// Convert buffer \p Input to its hexadecimal representation.
+/// The returned string is double the size of \p Input.
+inline std::string toHex(StringRef Input, bool LowerCase = false) {
+  SmallString<16> Output;
+  toHex(arrayRefFromStringRef(Input), LowerCase, Output);
+  return std::string(Output);
 }
 
 inline std::string toHex(ArrayRef Input, bool LowerCase = false) {
Index: clang/test/CodeGen/debug-info-file-checksum.c
===
--- clang/test/CodeGen/debug-info-file-checksum.c
+++ clang/test/CodeGen/debug-info-file-checksum.c
@@ -16,3 +16,7 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-line.cpp -o - | FileCheck %s --check-prefix CHECKSUM
 
 // CHECKSUM: !DIFile(filename: "{{.*}}debug-info-file-checksum-line.cpp", directory:{{.*}}, checksumkind: CSK_MD5, checksum: "7b568574d0e3c56c28e5e0234d1f4a06")
+
+// Later MSVC versions use SHA256.
+// RUN: %clang -target i686-pc-windows-msvc19.30.0 -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-line.cpp -o - | FileCheck %s --check-prefix SHA256
+// SHA256: !DIFile(filename: "{{.*}}debug-info-file-checksum-line.cpp", directory:{{.*}}, checksumkind: CSK_SHA256, checksum: