-
Notifications
You must be signed in to change notification settings - Fork 31
fix GetVariableOffset
in cases of multi-level and multiple inheritance
#396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
#include "gtest/gtest.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'gtest/gtest.h' file not found [clang-diagnostic-error] #include "gtest/gtest.h"
^ |
||
|
||
#include <cstddef> | ||
|
||
using namespace TestUtils; | ||
using namespace llvm; | ||
using namespace clang; | ||
|
@@ -258,6 +260,88 @@ TEST(VariableReflectionTest, GetVariableOffset) { | |
EXPECT_TRUE((bool) Cpp::GetVariableOffset(VD_C_s_a)); | ||
} | ||
|
||
#define CODE \ | ||
class BaseA { \ | ||
public: \ | ||
virtual ~BaseA() {} \ | ||
int a; \ | ||
BaseA(int a) : a(a) {} \ | ||
}; \ | ||
\ | ||
class BaseB : public BaseA { \ | ||
public: \ | ||
virtual ~BaseB() {} \ | ||
std::string b; \ | ||
BaseB(int x, std::string b) : BaseA(x), b(b) {} \ | ||
}; \ | ||
\ | ||
class Base1 { \ | ||
public: \ | ||
virtual ~Base1() {} \ | ||
int i; \ | ||
std::string s; \ | ||
Base1(int i, std::string s) : i(i), s(s) {} \ | ||
}; \ | ||
\ | ||
class MyKlass : public BaseB, public Base1 { \ | ||
public: \ | ||
virtual ~MyKlass() {} \ | ||
int k; \ | ||
MyKlass(int k, int i, int x, std::string b, std::string s) \ | ||
: BaseB(x, b), Base1(i, s), k(k) {} \ | ||
} my_k(5, 4, 3, "Cpp", "Python"); | ||
|
||
CODE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 'b' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:270: expanded from macro 'CODE' BaseB(int x, std::string b) : BaseA(x), b(b) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 's' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:277: expanded from macro 'CODE' Base1(int i, std::string s) : i(i), s(s) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: pass by value and use std::move [modernize-pass-by-value] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:270: expanded from macro 'CODE' BaseB(int x, std::string b) : BaseA(x), b(b) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'my_k' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:285: expanded from macro 'CODE' } my_k(5, 4, 3, "Cpp", "Python");
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'Base1' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:275: expanded from macro 'CODE' class Base1 { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'BaseA' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:261: expanded from macro 'CODE' class BaseA { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'BaseB' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:268: expanded from macro 'CODE' class BaseB : public BaseA { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'MyKlass' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:283: expanded from macro 'CODE' class MyKlass : public BaseB, public Base1 { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 'b' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:272: expanded from macro 'CODE' BaseB(int x, std::string b) : BaseA(x), b(b) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 's' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:280: expanded from macro 'CODE' Base1(int i, std::string s) : i(i), s(s) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: pass by value and use std::move [modernize-pass-by-value] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:272: expanded from macro 'CODE' BaseB(int x, std::string b) : BaseA(x), b(b) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'my_k' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:289: expanded from macro 'CODE' } my_k(5, 4, 3, "Cpp", "Python");
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'Base1' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:277: expanded from macro 'CODE' class Base1 { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'BaseA' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:263: expanded from macro 'CODE' class BaseA { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'BaseB' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:270: expanded from macro 'CODE' class BaseB : public BaseA { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'MyKlass' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:285: expanded from macro 'CODE' class MyKlass : public BaseB, public Base1 { \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 'b' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:274: expanded from macro 'CODE' BaseB(int x, std::string b) : BaseA(x), b(b) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 's' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:282: expanded from macro 'CODE' Base1(int i, std::string s) : i(i), s(s) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: pass by value and use std::move [modernize-pass-by-value] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:274: expanded from macro 'CODE' BaseB(int x, std::string b) : BaseA(x), b(b) {} \
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'my_k' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] CODE
^ Additional contextunittests/CppInterOp/VariableReflectionTest.cpp:291: expanded from macro 'CODE' } my_k(5, 4, 3, "Cpp", "Python");
^ |
||
|
||
TEST(VariableReflectionTest, VariableOffsetsWithInheritance) { | ||
if (llvm::sys::RunningOnValgrind()) | ||
GTEST_SKIP() << "XFAIL due to Valgrind report"; | ||
|
||
Cpp::Declare("#include<string>"); | ||
|
||
#define Stringify(s) Stringifyx(s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function-like macro 'Stringify' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage] #define Stringify(s) Stringifyx(s)
^ |
||
#define Stringifyx(...) #__VA_ARGS__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variadic macro 'Stringifyx' used; consider using a 'constexpr' variadic template function [cppcoreguidelines-macro-usage] #define Stringifyx(...) #__VA_ARGS__
^ |
||
Cpp::Declare(Stringify(CODE)); | ||
#undef Stringifyx | ||
#undef Stringify | ||
#undef CODE | ||
|
||
Cpp::TCppScope_t myklass = Cpp::GetNamed("MyKlass"); | ||
EXPECT_TRUE(myklass); | ||
|
||
size_t num_bases = Cpp::GetNumBases(myklass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "size_t" is directly included [misc-include-cleaner] unittests/CppInterOp/VariableReflectionTest.cpp:6: + #include <cstddef> |
||
EXPECT_EQ(num_bases, 2); | ||
|
||
std::vector<Cpp::TCppScope_t> datamembers; | ||
Cpp::GetDatamembers(myklass, datamembers); | ||
for (size_t i = 0; i < num_bases; i++) { | ||
Cpp::TCppScope_t base = Cpp::GetBaseClass(myklass, i); | ||
EXPECT_TRUE(base); | ||
for (size_t i = 0; i < Cpp::GetNumBases(base); i++) { | ||
Cpp::TCppScope_t bbase = Cpp::GetBaseClass(base, i); | ||
EXPECT_TRUE(base); | ||
Cpp::GetDatamembers(bbase, datamembers); | ||
} | ||
Cpp::GetDatamembers(base, datamembers); | ||
} | ||
EXPECT_EQ(datamembers.size(), 5); | ||
|
||
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[0], myklass), | ||
((intptr_t)&(my_k.k)) - ((intptr_t)&(my_k))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.k)) - ((intptr_t)&(my_k)));
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.k)) - ((intptr_t)&(my_k)));
^ |
||
|
||
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[1], myklass), | ||
((intptr_t)&(my_k.a)) - ((intptr_t)&(my_k))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.a)) - ((intptr_t)&(my_k)));
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.a)) - ((intptr_t)&(my_k)));
^ |
||
|
||
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[2], myklass), | ||
((intptr_t)&(my_k.b)) - ((intptr_t)&(my_k))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.b)) - ((intptr_t)&(my_k)));
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.b)) - ((intptr_t)&(my_k)));
^ |
||
|
||
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[3], myklass), | ||
((intptr_t)&(my_k.i)) - ((intptr_t)&(my_k))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.i)) - ((intptr_t)&(my_k)));
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.i)) - ((intptr_t)&(my_k)));
^ |
||
|
||
EXPECT_EQ(Cpp::GetVariableOffset(datamembers[4], myklass), | ||
((intptr_t)&(my_k.s)) - ((intptr_t)&(my_k))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.s)) - ((intptr_t)&(my_k)));
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] ((intptr_t)&(my_k.s)) - ((intptr_t)&(my_k)));
^ |
||
} | ||
|
||
TEST(VariableReflectionTest, IsPublicVariable) { | ||
std::vector<Decl *> Decls, SubDecls; | ||
std::string code = R"( | ||
|
Uh oh!
There was an error while loading. Please reload this page.