[PATCH] D90714: [clang]Fix length threshold for MicrosoftMangle md5 hash

Melanie Blower via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 10:38:46 PST 2020


mibintc updated this revision to Diff 302902.
mibintc added a comment.

Add lit test case, based on test case in bug report


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90714

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-ms-md5.cpp


Index: clang/test/CodeGenCXX/mangle-ms-md5.cpp
===================================================================
--- clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple i686-pc-win32 %s | FileCheck %s
+// RUN: %clang_cc1 -DNEED_MD5=1 -emit-llvm -o - -triple i686-pc-win32 %s | FileCheck --check-prefix=CHECK-MD5 %s
+// RUN: %clang_cc1 -emit-llvm -o - -triple i686-pc-win32 %s | FileCheck --check-prefix=CHECK-NOMD5 %s
 int xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
 // CHECK-DAG: @"??@bf7ea7b95f260b0b24e7f1e8fc8370ab@" = dso_local global i32 0, align 4
 
@@ -24,3 +26,39 @@
 // HAVECTOR: "_CT??@c14087f0ec22b387aea7c59083f4f546@??@4ef4f8979c81f9d2224b32bf327e6bdf at 4"
 }
 #endif
+
+// Verify the threshold where md5 mangling kicks in
+namespace std {
+inline namespace __cxx11 {}
+template < typename > class allocator;
+template < class > struct char_traits;
+inline namespace __cxx11 {
+template < typename _CharT, typename = char_traits< _CharT >,
+           typename = allocator< _CharT > >
+class basic_string;
+}
+template < typename , typename > struct pair;
+template < typename > struct Les ;
+template < typename _Key, typename _Tp, typename = Les< _Key >,
+           typename = allocator< pair< const _Key, _Tp > > >
+class map {};
+} class Feld;
+#if NEED_MD5
+#define FUN xxxxxxxxxxfoo
+// CHECK-MD5: @"??@43018eb4005fb11f14a17af7788d1764@"
+#else
+#define FUN xxxxxxxxxfoo
+// CHECK-NOMD5: call {{.*}}xxxfoo
+#endif
+void FUN(
+    std::map< std::basic_string< char >,
+              std::map< std::basic_string< char >,
+                        std::map< std::basic_string< char >,
+                                  std::map< std::basic_string< char >,
+                                            Feld > > > >);
+std::map< std::basic_string< char >,
+          std::map< std::basic_string< char >,
+                    std::map< std::basic_string< char >,
+                              std::map< std::basic_string< char >,
+                                        Feld > > > > obj;
+int main(){FUN(obj); }
Index: clang/lib/AST/MicrosoftMangle.cpp
===================================================================
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -50,7 +50,7 @@
     bool StartsWithEscape = MangledName.startswith("\01");
     if (StartsWithEscape)
       MangledName = MangledName.drop_front(1);
-    if (MangledName.size() <= 4096) {
+    if (MangledName.size() < 4096) {
       OS << str();
       return;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90714.302902.patch
Type: text/x-patch
Size: 6632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201104/083a18ab/attachment-0001.bin>


More information about the cfe-commits mailing list