[ASan] Improve ODR-violation error reports.
authorAlexey Samsonov <vonosmas@gmail.com>
Fri, 11 Jul 2014 23:34:26 +0000 (23:34 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Fri, 11 Jul 2014 23:34:26 +0000 (23:34 +0000)
Demangle names of involved globals. Print a more consistent summary line.

llvm-svn: 212857

compiler-rt/lib/asan/asan_report.cc
compiler-rt/test/asan/TestCases/Linux/odr-violation.cc

index cee0db5..d45e027 100644 (file)
@@ -768,8 +768,10 @@ void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
   InternalScopedString g1_loc(256), g2_loc(256);
   PrintGlobalLocation(&g1_loc, *g1);
   PrintGlobalLocation(&g2_loc, *g2);
-  Printf("  [1] size=%zd %s %s\n", g1->size, g1->name, g1_loc.data());
-  Printf("  [2] size=%zd %s %s\n", g2->size, g2->name, g2_loc.data());
+  Printf("  [1] size=%zd '%s' %s\n", g1->size,
+         MaybeDemangleGlobalName(g1->name), g1_loc.data());
+  Printf("  [2] size=%zd '%s' %s\n", g2->size,
+         MaybeDemangleGlobalName(g2->name), g2_loc.data());
   if (stack_id1 && stack_id2) {
     Printf("These globals were registered at these points:\n");
     Printf("  [1]:\n");
@@ -782,7 +784,10 @@ void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
   }
   Report("HINT: if you don't care about these warnings you may set "
          "ASAN_OPTIONS=detect_odr_violation=0\n");
-  ReportErrorSummary("odr-violation", g1_loc.data(), 0, g1->name);
+  InternalScopedString error_msg(256);
+  error_msg.append("odr-violation: global '%s' at %s",
+                   MaybeDemangleGlobalName(g1->name), g1_loc.data());
+  ReportErrorSummary(error_msg.data());
 }
 
 // ----------------------- CheckForInvalidPointerPair ----------- {{{1
index 48e0907..ddc68a2 100644 (file)
 #endif
 
 #if BUILD_SO
-char G[SZ];
+namespace foo { char G[SZ]; }
 #else
 #include <stdio.h>
-char G[100];
+namespace foo { char G[100]; }
+// CHECK: ERROR: AddressSanitizer: odr-violation
+// CHECK: size=100 'foo::G' {{.*}}odr-violation.cc:[[@LINE-2]]:22
+// CHECK: size={{4|100}} 'foo::G'
 int main(int argc, char **argv) {
-  printf("PASS: %p\n", &G);
+  printf("PASS: %p\n", &foo::G);
 }
 #endif
 
-// CHECK: ERROR: AddressSanitizer: odr-violation
-// CHECK: size=100 G
-// CHECK: size={{4|100}} G
 // CHECK: These globals were registered at these points:
 // CHECK: ODR-EXE
 // CHECK: ODR-SO
+// CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cc
 // DISABLED: PASS