[PATCH] D54344: [Clang][CodeGen][CXX]: Workaround __attribute((no_destroy)) crash/incorrect code generation.
Kristina Brooks via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 10 02:03:49 PST 2018
kristina added a comment.
I've managed to isolate enough to make for a testcase. Is that too broad or is it okay to attach as is?
The following triggers the assert:
namespace util {
template <typename T>
class test_vector
{
public:
test_vector(unsigned c)
: Used(0), TotalSize(sizeof(T) * c)
{
// Intentional
Storage = (T*)(new T[TotalSize]);
}
~test_vector() {
delete[] Storage;
}
char* data() {
return Storage;
}
unsigned size() {
return TotalSize;
}
void push_back(T one_thing) {
Storage[Used++] = one_thing;
}
private:
unsigned Used;
unsigned TotalSize;
T* Storage;
};
}
volatile int do_not_optimize_me = 0;
namespace os {
using char_vec_t = util::test_vector<char>;
class logger_base
{
public:
constexpr logger_base() = default;
protected:
char_vec_t* NamePtr = nullptr;
char_vec_t Name = char_vec_t(10);
};
class logger : public logger_base
{
public:
void stuff(const char* fmt, int something) {
do_not_optimize_me = something + fmt[0];
}
logger()
{
Name = char_vec_t(8);
Name.push_back('a');
}
logger(const char* name)
{
Name = util::test_vector<char>(__builtin_strlen(name));
Name.push_back(name[0]);
Name.push_back(name[1]);
}
};
}
#define TOPLEVEL_LOGGER(_var_name, _category_const) \
namespace { constexpr char $__##_var_name[] = _category_const; \
__attribute((no_destroy)) os::logger _var_name ($__##_var_name) ; }
TOPLEVEL_LOGGER(s_log, "something");
class some_class {
public:
some_class(int some_value) {
do_not_optimize_me = some_value;
s_log.stuff("wawawa", 5 + do_not_optimize_me);
}
~some_class() = default;
};
static some_class s_ctor(1);
https://reviews.llvm.org/D54344
More information about the cfe-commits
mailing list