https://bugs.llvm.org/show_bug.cgi?id=34266
Bug ID: 34266
Summary: [maybe regression]: undefined behavior due to
misaligned access to aligned lambda
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangb...@nondot.org
Reporter: gonzalob...@gmail.com
CC: dgre...@apple.com, llvm-bugs@lists.llvm.org
When compiling the following code with: clang++ -fsanitize=undefined -std=c++14
I get the following error:
mwe.cpp:30:14: runtime error: load of misaligned address 0x00000042ff61 for
type 'const (lambda at mwe.cpp:30:14) *', which requires 8 byte alignment
0x00000042ff61: note: pointer points here
00 00 00 00 00 4b 46 69 76 45 00 50 bc 63 00 00 00 00 00 62 ff 42 00 00 00
00 00 2f 61 69 61 2f
^
initial debugging suggest that the lambda, which is properly aligned in
E::operator() is accessed via a misaligned pointer in D::operator(),
introducing undefined behavior. How this happens escapes me.
The reproducer is:
template<typename T>
struct static_const { static constexpr T value {}; };
template<typename T>
constexpr T static_const<T>::value;
struct B {
static constexpr int bar(int) noexcept { return 0; }
constexpr int baz(int) noexcept { return 0; }
};
struct C {
auto operator()() const noexcept -> int { return 0; }
};
namespace {
constexpr auto const& c_fn = static_const<C>::value;
}
struct D {
template <typename F>
auto operator()(F&& f) const noexcept -> int { return f(0); }
};
namespace { constexpr auto const& d_fn = static_const<D>::value; }
struct E {
template <typename T = B>
auto operator()(T t = B()) const noexcept -> T {
auto l = [&](int i) { return t.baz(T::bar(i)); };
d_fn(l);
return t;
}
};
namespace { constexpr auto const& e_fn = static_const<E>::value; }
int main() {
auto a = c_fn();
auto b = e_fn();
return 0;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs