summaryrefslogtreecommitdiffstats
path: root/llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-04-12 23:18:21 +0000
committerZachary Turner <zturner@google.com>2017-04-12 23:18:21 +0000
commitc883a8c6dce207a494c6c3a54de1492635acb664 (patch)
treefb2ff9010b62853109fd592e006e560fc2cb4ed7 /llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp
parent1b395144442f4bf872fb772c87d8b6e3bf78cfd7 (diff)
downloadbcm5719-llvm-c883a8c6dce207a494c6c3a54de1492635acb664.tar.gz
bcm5719-llvm-c883a8c6dce207a494c6c3a54de1492635acb664.zip
[llvm-pdbdump] More advanced class definition dumping.
Previously the dumping of class definitions was very primitive, and it made it hard to do more than the most trivial of output formats when dumping. As such, we would only dump one line for each field, and then dump non-layout items like nested types and enums. With this patch, we do a complete analysis of the object hierarchy including aggregate types, bases, virtual bases, vftable analysis, etc. The only immediately visible effects of this are that a) we can now dump a line for the vfptr where before we would treat that as padding, and b) we now don't treat virtual bases that come at the end of a class as padding since we have a more detailed analysis of the class's storage usage. In subsequent patches, we should be able to use this analysis to display a complete graphical view of a class's layout including recursing arbitrarily deep into an object's base class / aggregate member hierarchy. llvm-svn: 300133
Diffstat (limited to 'llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp')
-rw-r--r--llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp b/llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp
new file mode 100644
index 00000000000..b10839beea2
--- /dev/null
+++ b/llvm/test/tools/llvm-pdbdump/Inputs/SimplePaddingTest.cpp
@@ -0,0 +1,122 @@
+// Compile with "cl /c /Zi /GR- SimplePaddingTest.cpp"
+// Link with "link SimplePaddingTest.obj /debug /nodefaultlib /entry:main"
+
+#include <stdint.h>
+
+extern "C" using at_exit_handler = void();
+
+int atexit(at_exit_handler handler) { return 0; }
+
+struct SimplePadNoPadding {
+ int32_t X;
+ int32_t Y;
+ // No padding anywhere, sizeof(T) = 8
+} A;
+
+struct SimplePadUnion {
+ union {
+ int32_t X;
+ int64_t Y;
+ struct {
+ int32_t X;
+ // 4 bytes of padding here
+ int64_t Y;
+ } Z;
+ };
+ // Since the padding occurs at a location that is occupied by other storage
+ // (namely the Y member), the storage will still be considered used, and so
+ // there will be no unused bytes in the larger class. But in the debug
+ // info for the nested struct, we should see padding.
+ // sizeof(SimplePadUnion) == sizeof(Z) == 16
+} B;
+
+struct SimplePadNoPadding2 {
+ bool A;
+ bool B;
+ bool C;
+ bool D;
+ // No padding anywhere, sizeof(T) = 4
+} C;
+
+struct alignas(4) SimplePadFields1 {
+ char A;
+ char B;
+ char C;
+ // 1 byte of padding here, sizeof(T) = 4
+} E;
+
+struct SimplePadFields2 {
+ int32_t Y;
+ char X;
+} F;
+
+struct SimplePadBase {
+ // Make sure this class is 4 bytes, and the derived class requires 8 byte
+ // alignment, so that padding is inserted between base and derived.
+ int32_t X;
+ // No padding here
+} G;
+
+struct SimplePadDerived : public SimplePadBase {
+ // 4 bytes of padding here due to Y requiring 8 byte alignment.
+ // Thus, sizeof(T) = 16
+ int64_t Y;
+} H;
+
+struct SimplePadEmptyBase1 {};
+struct SimplePadEmptyBase2 {};
+
+struct SimplePadEmpty : public SimplePadEmptyBase1, SimplePadEmptyBase2 {
+ // Bases have to occupy at least 1 byte of storage, so this requires
+ // 2 bytes of padding, plus 1 byte for each base, yielding sizeof(T) = 8
+ int32_t X;
+} I;
+
+struct SimplePadVfptr {
+ virtual ~SimplePadVfptr() {}
+ static void operator delete(void *ptr, size_t sz) {}
+ int32_t X;
+} J;
+
+struct NonEmptyBase1 {
+ bool X;
+};
+
+struct NonEmptyBase2 {
+ bool Y;
+};
+
+struct SimplePadMultiInherit : public NonEmptyBase1, public NonEmptyBase2 {
+ // X and Y from the 2 bases will get squished together, leaving 2 bytes
+ // of padding necessary for proper alignment of an int32.
+ // Therefore, sizeof(T) = 2 + 2 + 4 = 8
+ int32_t X;
+} K;
+
+struct SimplePadMultiInherit2 : public SimplePadFields1, SimplePadFields2 {
+ // There should be 1 byte of padding after the first class, and
+ // 3 bytes of padding after the second class.
+ int32_t X;
+} L;
+
+struct OneLevelInherit : public NonEmptyBase1 {
+ short Y;
+};
+
+struct SimplePadTwoLevelInherit : public OneLevelInherit {
+ // OneLevelInherit has nested padding because of its base,
+ // and then padding again because of this class. So each
+ // class should be 4 bytes, yielding sizeof(T) = 12.
+ int64_t Z;
+} M;
+
+struct SimplePadAggregate {
+ NonEmptyBase1 X;
+ int32_t Y;
+ // the presence of X will cause 3 bytes of padding to be injected.
+} N;
+
+int main(int argc, char **argv) {
+
+ return 0;
+}
OpenPOWER on IntegriCloud