Issue 169296
Summary ASAN: detect ODR violation in templates/types
Labels new issue
Assignees
Reporter segoon
    ODR violation detector in ASAN is great. However, it doesn't catch all possible ODRs. One painful ODR violation is due to different template instantiation in multiple translation units. E.g. with old versions of fmt (https://fmt.dev/latest/syntax/) it was possible to get different formatting template impls dependending on previous `<fmt/ostream.h>` header inclusion. 

`TString` is a string-like type that can be implicitly casted to `const std::string&` and can be serialized to `std::ostream`. Depending on `<fmt/ostream.h>` previous inclusion, `fmt::format` can use either of two methods of stringifying `TString`. The following example shows ODR violation because it leads to inconsistent inline code and code instantiated from non-inline methods of template classes.

```
--- taxi/uservices/userver/core/src/utils/fmt_tstring2_test.cpp (d796f294f01d81270921865625b36ff228293e76)
+++ taxi/uservices/userver/core/src/utils/fmt_tstring2_test.cpp (4fae94450ad73e330ba5b034716ddf8130047664)
@@ -0,0 +1,10 @@
+#include <fmt/format.h>
+#include <util/generic/string.h>
+
+#include <fmt/ostream.h>
+#include <gtest/gtest.h>
+
+TEST(Fmt, CoreDump2) {
+ TString token("123123123123123123123123123123132");
+ (void)fmt::vformat("some string '{}'", fmt::make_format_args(token));
+}
--- taxi/uservices/userver/core/src/utils/fmt_tstring_test.cpp (d796f294f01d81270921865625b36ff228293e76)
+++ taxi/uservices/userver/core/src/utils/fmt_tstring_test.cpp (4fae94450ad73e330ba5b034716ddf8130047664)
@@ -0,0 +1,9 @@
+#include <fmt/format.h>
+#include <util/generic/string.h>
+
+#include <gtest/gtest.h>
+
+TEST(Fmt, CoreDump1) {
+    TString token("123123123123123123123123123123132");
+    (void)fmt::vformat("some string '{}'", fmt::make_format_args(token));
+}
```

It would be great if such type of ODR violation could be automatically detected by ASAN. It was VERY painful to debug this specific case for hours of manual digging into fmt metaprogramming and includes bisecting.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to