[PATCH] D65267: [MachineCopyPropagation] Remove redundant copies after TailDup via machine-cp
Dmitri Gribenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 09:45:35 PDT 2019
gribozavr added a comment.
Hi,
Unfortunately, with this patch the following program (that I believe to be valid C++) fails under MSan:
#include <set>
#include <string>
#include <vector>
struct Inner {
__attribute__((noinline)) int Opaque1(int, char) const { return -1; }
__attribute__((noinline)) void Opaque2(int, char, int) {}
std::vector<std::set<const std::string*> > output;
int next = 1;
};
struct Outer {
__attribute__((noinline)) void Enter(const std::string&);
Inner* inner;
};
void Outer::Enter(const std::string& str) {
int state = 0;
int j = 0;
for (; j < str.size(); j++) {
int next_state = inner->Opaque1(state, str[j]);
if (next_state == -1)
break;
else
state = next_state;
}
for (; j < str.size(); j++) {
inner->Opaque2(state, str[j], inner->next);
state = inner->next;
inner->next++;
}
inner->output[state].insert(&str);
}
__attribute__((noinline))
void fault(const std::set<const std::string*>& x) {
for (const std::string *xx : x) {
std::string copy = *xx;
}
}
int main() {
std::string TheString = "a";
Outer outer;
outer.inner = new Inner;
outer.inner->output.resize(2);
outer.Enter(TheString);
const std::set<const std::string*>& x = outer.inner->output[1];
fault(x);
}
==8166==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x7f20d47060e0 in std::__msan::basic_string<char, std::__msan::char_traits<char>, std::__msan::allocator<char> >::__is_long() const include/string:1420:39
#1 0x7f20d47060e0 in std::__msan::basic_string<char, std::__msan::char_traits<char>, std::__msan::allocator<char> >::basic_string(std::__msan::basic_string<char, std::__msan::char_traits<char>, std::__msan::allocator<char> > const&) include/string:1835:16
#2 0x7f20d58209ad in fault(std::__msan::set<std::__msan::basic_string<char, std::__msan::char_traits<char>, std::__msan::allocator<char> > const*, std::__msan::less<std::__msan::basic_string<char, std::__msan::char_traits<char>, std::__msan::allocator<char> > const*>, std::__msan::allocator<std::__msan::basic_string<char, std::__msan::char_traits<char>, std::__msan::allocator<char> > const*> > const&) test.cc:38:24
#3 0x7f20d5820b21 in main test.cc:49:3
#4 0x7f20d3e6dbbc in __libc_start_main
#5 0x563387ed2d08 in _start
I'm suspecting a miscompile in `Outer::Enter`. I have verified that the program works without this patch, and fails with this patch. Please let me know if I could help more you to reproduce the problem.
I'm reverting this patch for now, sorry (r371421).
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65267/new/
https://reviews.llvm.org/D65267
More information about the llvm-commits
mailing list