Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/typo.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: cp %s %t // RUN: not %clang_cc1 -fsyntax-only -fixit -x c++ %t // RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ %t // RUN: grep test_string %t namespace std { template<typename T> class basic_string { // expected-note 3{{'basic_string' declared here}} public: int find(const char *substr); // expected-note{{'find' declared here}} static const int npos = -1; // expected-note{{'npos' declared here}} }; typedef basic_string<char> string; // expected-note 2{{'string' declared here}} } namespace otherstd { // expected-note 2{{'otherstd' declared here}} \ // expected-note{{namespace 'otherstd' defined here}} using namespace std; } using namespace std; other_std::strng str1; // expected-error{{use of undeclared identifier 'other_std'; did you mean 'otherstd'?}} \ // expected-error{{no type named 'strng' in namespace 'otherstd'; did you mean 'string'?}} tring str2; // expected-error{{unknown type name 'tring'; did you mean 'string'?}} ::other_std::string str3; // expected-error{{no member named 'other_std' in the global namespace; did you mean 'otherstd'?}} float area(float radius, // expected-note{{'radius' declared here}} float pi) { return radious * pi; // expected-error{{did you mean 'radius'?}} } using namespace othestd; // expected-error{{no namespace named 'othestd'; did you mean 'otherstd'?}} namespace blargh = otherstd; // expected-note 3{{namespace 'blargh' defined here}} using namespace ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}} namespace wibble = blarg; // expected-error{{no namespace named 'blarg'; did you mean 'blargh'?}} namespace wobble = ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}} bool test_string(std::string s) { basc_string<char> b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}} std::basic_sting<char> b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}} (void)b1; (void)b2; return s.fnd("hello") // expected-error{{no member named 'fnd' in 'std::basic_string<char>'; did you mean 'find'?}} == std::string::pos; // expected-error{{no member named 'pos' in 'std::basic_string<char>'; did you mean 'npos'?}} } struct Base { }; struct Derived : public Base { // expected-note{{base class 'Base' specified here}} int member; // expected-note 3{{'member' declared here}} Derived() : base(), // expected-error{{initializer 'base' does not name a non-static data member or base class; did you mean the base class 'Base'?}} ember() { } // expected-error{{initializer 'ember' does not name a non-static data member or base class; did you mean the member 'member'?}} int getMember() const { return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}} } int &getMember(); }; int &Derived::getMember() { return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}} } typedef int Integer; // expected-note{{'Integer' declared here}} int global_value; // expected-note{{'global_value' declared here}} int foo() { integer * i = 0; // expected-error{{unknown type name 'integer'; did you mean 'Integer'?}} unsinged *ptr = 0; // expected-error{{use of undeclared identifier 'unsinged'; did you mean 'unsigned'?}} return *i + *ptr + global_val; // expected-error{{use of undeclared identifier 'global_val'; did you mean 'global_value'?}} } namespace nonstd { typedef std::basic_string<char> yarn; // expected-note 2 {{'nonstd::yarn' declared here}} int narf; // expected-note{{'nonstd::narf' declared here}} } yarn str4; // expected-error{{unknown type name 'yarn'; did you mean 'nonstd::yarn'?}} wibble::yarn str5; // expected-error{{no type named 'yarn' in namespace 'otherstd'; did you mean 'nonstd::yarn'?}} namespace another { template<typename T> class wide_string {}; // expected-note {{'another::wide_string' declared here}} } int poit() { nonstd::basic_string<char> str; // expected-error{{no template named 'basic_string' in namespace 'nonstd'; did you mean simply 'basic_string'?}} nonstd::wide_string<char> str2; // expected-error{{no template named 'wide_string' in namespace 'nonstd'; did you mean 'another::wide_string'?}} return wibble::narf; // expected-error{{no member named 'narf' in namespace 'otherstd'; did you mean 'nonstd::narf'?}} } namespace check_bool { void f() { Bool b; // expected-error{{use of undeclared identifier 'Bool'; did you mean 'bool'?}} } } namespace outr { } namespace outer { namespace inner { // expected-note{{'outer::inner' declared here}} \ // expected-note{{namespace 'outer::inner' defined here}} \ // expected-note{{'inner' declared here}} int i; } } using namespace outr::inner; // expected-error{{no namespace named 'inner' in namespace 'outr'; did you mean 'outer::inner'?}} void func() { outr::inner::i = 3; // expected-error{{no member named 'inner' in namespace 'outr'; did you mean 'outer::inner'?}} outer::innr::i = 4; // expected-error{{no member named 'innr' in namespace 'outer'; did you mean 'inner'?}} } struct base { }; struct derived : base { int i; }; void func2() { derived d; // FIXME: we should offer a fix here. We do if the 'i' is misspelled, but we don't do name qualification changes // to replace base::i with derived::i as we would for other qualified name misspellings. // d.base::i = 3; } class A { void bar(int); }; void bar(int, int); // expected-note{{'::bar' declared here}} void A::bar(int x) { bar(x, 5); // expected-error{{too many arguments to function call, expected 1, have 2; did you mean '::bar'?}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/fixit-c90.c
/* RUN: cp %s %t RUN: %clang_cc1 -std=c90 -pedantic -fixit %t RUN: %clang_cc1 -pedantic -x c -std=c90 -Werror %t */ /* This test passes because clang merely warns for this syntax error even with -pedantic -Werror -std=c90. */ /* This is a test of the various code modification hints that are provided as part of warning or extension diagnostics. All of the warnings will be fixed by -fixit, and the resulting file should compile cleanly with -Werror -pedantic. */ enum e0 { e1, };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/fixit-cxx11-attributes.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s // RUN: cp %s %t // RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t // RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t // RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s namespace ClassSpecifier { class [[]] [[]] attr_after_class_name_decl [[]] [[]]; // expected-error {{an attribute list cannot appear here}} // CHECK: fix-it:{{.*}}:{9:5-9:5} // CHECK: fix-it:{{.*}}:{9:32-9:41} class [[]] [[]] attr_after_class_name_definition [[]] [[]] [[]]{}; // expected-error {{an attribute list cannot appear here}} // CHECK: fix-it:{{.*}}:{14:4-14:4} // CHECK: fix-it:{{.*}}:{14:37-14:51} class base {}; class [[]] [[]] final_class alignas(float) [[]] final // expected-error {{an attribute list cannot appear here}} alignas(float) [[]] [[]] alignas(float): base{}; // expected-error {{an attribute list cannot appear here}} // CHECK: fix-it:{{.*}}:{19:19-19:19} // CHECK: fix-it:{{.*}}:{20:5-20:25} // CHECK: fix-it:{{.*}}:{19:19-19:19} // CHECK: fix-it:{{.*}}:{21:5-21:44} class [[]] [[]] final_class_another [[]] [[]] alignas(16) final // expected-error {{an attribute list cannot appear here}} [[]] [[]] alignas(16) [[]]{}; // expected-error {{an attribute list cannot appear here}} // CHECK: fix-it:{{.*}}:{27:19-27:19} // CHECK: fix-it:{{.*}}:{28:5-28:27} // CHECK: fix-it:{{.*}}:{27:19-27:19} // CHECK: fix-it:{{.*}}:{29:5-29:31} } namespace BaseSpecifier { struct base1 {}; struct base2 {}; class with_base_spec : public [[a]] // expected-error {{an attribute list cannot appear here}} expected-warning {{unknown}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"[{{\[}}a]]" // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:33-[[@LINE-2]]:39}:"" virtual [[b]] base1, // expected-error {{an attribute list cannot appear here}} expected-warning {{unknown}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:26-[[@LINE-4]]:26}:"[{{\[}}b]]" // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:34-[[@LINE-2]]:40}:"" virtual [[c]] // expected-error {{an attribute list cannot appear here}} expected-warning {{unknown}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"[{{\[}}c]]" // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:34-[[@LINE-2]]:40}:"" public [[d]] base2 {}; // expected-error {{an attribute list cannot appear here}} expected-warning {{unknown}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:26-[[@LINE-4]]:26}:"[{{\[}}d]]" // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:33-[[@LINE-2]]:39}:"" }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/fixit-cxx0x.cpp
// RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s // RUN: cp %s %t // RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t // RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t /* This is a test of the various code modification hints that only apply in C++0x. */ struct A { explicit operator int(); // expected-note{{conversion to integral type}} }; void x() { switch(A()) { // expected-error{{explicit conversion to}} } } using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}} using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}} using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}} namespace SemiCommaTypo { int m {}, n [[]], // expected-error {{expected ';' at end of declaration}} int o; struct Base { virtual void f2(), f3(); }; struct MemberDeclarator : Base { int k : 4, //[[]] : 1, FIXME: test this once we support attributes here : 9, // expected-error {{expected ';' at end of declaration}} char c, // expected-error {{expected ';' at end of declaration}} typedef void F(), // expected-error {{expected ';' at end of declaration}} F f1, f2 final, f3 override, // expected-error {{expected ';' at end of declaration}} }; } namespace ScopedEnum { enum class E { a }; enum class E b = E::a; // expected-error {{must use 'enum' not 'enum class'}} struct S { friend enum class E; // expected-error {{must use 'enum' not 'enum class'}} }; } struct S2 { void f(int i); void g(int i); }; void S2::f(int i) { (void)[&, &i, &i]{}; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}} (void)[=, this]{ this->g(5); }; // expected-error{{'this' cannot be explicitly captured}} (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}} (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}} } #define bar "bar" const char *p = "foo"bar; // expected-error {{requires a space between}} #define ord - '0' int k = '4'ord; // expected-error {{requires a space between}} void operator"x" _y(char); // expected-error {{must be '""'}} void operator L"" _z(char); // expected-error {{encoding prefix}} void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}} void f() { 'b'_y; 'c'_z; 'd'_whoops; } template<typename ...Ts> struct MisplacedEllipsis { int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}} int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}} int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}} int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}} int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} int g(Ts ...()); // ok }; namespace TestMisplacedEllipsisRecovery { MisplacedEllipsis<int, char> me; int i; char k; int *ip; char *kp; int ifn(); char kfn(); int a = me.a(i, k); int b = me.b(i, k); int c = me.c(i, k); int d = me.d(i, k); int e = me.e(&ip, &kp); int f = me.f(ifn, kfn); int g = me.g(ifn, kfn); } template<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}} template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}} void func(); template<int *ip> struct IP { }; // expected-note{{declared here}} IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}} namespace MissingSemi { struct a // expected-error {{expected ';' after struct}} struct b // expected-error {{expected ';' after struct}} enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}} struct c // expected-error {{expected ';' after struct}} enum x : int // expected-error {{expected ';' after enum}} // FIXME: The following gives a poor diagnostic (we parse the 'int' and the // 'struct' as part of the same enum-base. // enum x : int // struct y namespace N { struct d // expected-error {{expected ';' after struct}} } } namespace NonStaticConstexpr { struct foo { constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}} constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} foo() : i(3), k(4) { } static int get_j() { return j; } }; } int RegisterVariable() { register int n; // expected-warning {{'register' storage class specifier is deprecated}} return n; } namespace MisplacedParameterPack { template <typename Args...> // expected-error {{'...' must immediately precede declared identifier}} void misplacedEllipsisInTypeParameter(Args...); template <typename... Args...> // expected-error {{'...' must immediately precede declared identifier}} void redundantEllipsisInTypeParameter(Args...); template <template <typename> class Args...> // expected-error {{'...' must immediately precede declared identifier}} void misplacedEllipsisInTemplateTypeParameter(Args<int>...); template <template <typename> class... Args...> // expected-error {{'...' must immediately precede declared identifier}} void redundantEllipsisInTemplateTypeParameter(Args<int>...); template <int N...> // expected-error {{'...' must immediately precede declared identifier}} void misplacedEllipsisInNonTypeTemplateParameter(); template <int... N...> // expected-error {{'...' must immediately precede declared identifier}} void redundantEllipsisInNonTypeTemplateParameter(); } namespace MisplacedDeclAndRefSpecAfterVirtSpec { struct B { virtual void f(); virtual void f() volatile const; }; struct D : B { virtual void f() override; virtual void f() override final const volatile; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} }; struct B2 { virtual void f() &; virtual void f() volatile const &&; }; struct D2 : B2 { virtual void f() override &; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}} virtual void f() override final const volatile &&; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'&&' qualifier may not appear after the virtual specifier 'final'}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/dereference-addressof.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: cp %s %t // RUN: not %clang_cc1 -fsyntax-only -fixit -x c %t // RUN: %clang_cc1 -fsyntax-only -pedantic -x c %t void ip(int *aPtr) {} // expected-note{{passing argument to parameter 'aPtr' here}} void i(int a) {} // expected-note{{passing argument to parameter 'a' here}} void ii(int a) {} // expected-note{{passing argument to parameter 'a' here}} void fp(float *aPtr) {} // expected-note{{passing argument to parameter 'aPtr' here}} void f(float a) {} // expected-note{{passing argument to parameter 'a' here}} void f2(int *aPtr, int a, float *bPtr, char c) { float fl = 0; ip(a); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'; take the address with &}} i(aPtr); // expected-warning{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; dereference with *}} ii(&a); // expected-warning{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; remove &}} fp(*bPtr); // expected-error{{passing 'float' to parameter of incompatible type 'float *'; remove *}} f(bPtr); // expected-error{{passing 'float *' to parameter of incompatible type 'float'; dereference with *}} a = aPtr; // expected-warning{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}} fl = bPtr + a; // expected-error{{assigning to 'float' from incompatible type 'float *'; dereference with *}} bPtr = bPtr[a]; // expected-error{{assigning to 'float *' from incompatible type 'float'; take the address with &}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/fixit-vexing-parse-cxx0x.cpp
// RUN: %clang_cc1 -verify -x c++ -std=c++11 %s // RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++11 %s 2>&1 | FileCheck %s struct X { int i; }; void func() { // CHECK: fix-it:"{{.*}}":{10:6-10:8}:"{}" X x(); // expected-warning {{function declaration}} expected-note{{replace parentheses with an initializer}} typedef int *Ptr; // CHECK: fix-it:"{{.*}}":{14:8-14:10}:" = nullptr" Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} // CHECK: fix-it:"{{.*}}":{17:15-17:17}:" = u'\\0'" char16_t u16(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} // CHECK: fix-it:"{{.*}}":{20:15-20:17}:" = U'\\0'" char32_t u32(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/FixIt/fixit.c
// RUN: %clang_cc1 -pedantic -Wunused-label -verify -x c %s // RUN: cp %s %t // RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t // RUN: grep -v CHECK %t > %t2 // RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t // RUN: FileCheck -input-file=%t2 %t /* This is a test of the various code modification hints that are provided as part of warning or extension diagnostics. All of the warnings will be fixed by -fixit, and the resulting file should compile cleanly with -Werror -pedantic. */ // FIXME: FIX-IT should add #include <string.h>? int strcmp(const char *s1, const char *s2); void f0(void) { }; // expected-warning {{';'}} struct s { int x, y;; // expected-warning {{extra ';'}} }; // CHECK: _Complex double cd; _Complex cd; // expected-warning {{assuming '_Complex double'}} // CHECK: struct s s0 = { .y = 5 }; struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}} // CHECK: int array0[5] = { [3] = 3 }; int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}} // CHECK: int x // CHECK: int y void f1(x, y) // expected-warning 2{{defaulting to type 'int'}} { } int i0 = { 17 }; #define ONE 1 #define TWO 2 int test_cond(int y, int fooBar) { // expected-note {{here}} // CHECK: int x = y ? 1 : 4+fooBar; int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}} // CHECK: x = y ? ONE : TWO; x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}} return x; } // CHECK: const typedef int int_t; const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}} // <rdar://problem/7159693> enum Color { Red // expected-error{{missing ',' between enumerators}} Green = 17 // expected-error{{missing ',' between enumerators}} Blue, }; // rdar://9295072 struct test_struct { // CHECK: struct test_struct *struct_ptr; test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}} }; void removeUnusedLabels(char c) { L0 /*removed comment*/: c++; // expected-warning {{unused label}} removeUnusedLabels(c); L1: // expected-warning {{unused label}} c++; /*preserved comment*/ L2 : c++; // expected-warning {{unused label}} LL // expected-warning {{unused label}} : c++; c = c + 3; L4: return; // expected-warning {{unused label}} } int oopsAComma = 0, // expected-error {{';'}} void oopsMoreCommas() { static int a[] = { 0, 1, 2 }, // expected-error {{';'}} static int b[] = { 3, 4, 5 }, // expected-error {{';'}} &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]); } int commaAtEndOfStatement() { int a = 1; a = 5, // expected-error {{';'}} int m = 5, // expected-error {{';'}} return 0, // expected-error {{';'}} } int noSemiAfterLabel(int n) { switch (n) { default: return n % 4; case 0: case 1: case 2: // CHECK: /*FOO*/ case 3: ; /*FOO*/ case 3: // expected-error {{expected statement}} } switch (n) { case 1: case 2: return 0; // CHECK: /*BAR*/ default: ; /*BAR*/ default: // expected-error {{expected statement}} } return 1; } struct noSemiAfterStruct // expected-error {{expected ';' after struct}} struct noSemiAfterStruct { int n // expected-warning {{';'}} } // expected-error {{expected ';' after struct}} enum noSemiAfterEnum { e1 } // expected-error {{expected ';' after enum}} int PR17175 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/parse-errors.c
// RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/invalid-yaml.yaml -fsyntax-only %s 2>&1 | FileCheck %s // CHECK: invalid virtual filesystem overlay file // RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/missing-key.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-MISSING-TYPE %s // CHECK-MISSING-TYPE: missing key 'type' // CHECK-MISSING-TYPE: invalid virtual filesystem overlay file // RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/unknown-key.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-UNKNOWN-KEY %s // CHECK-UNKNOWN-KEY: unknown key // CHECK-UNKNOWN-KEY: invalid virtual filesystem overlay file // RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/unknown-value.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-UNKNOWN-VALUE %s // CHECK-UNKNOWN-VALUE: expected boolean value // CHECK-UNKNOWN-VALUE: invalid virtual filesystem overlay file
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/implicit-include.c
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -include "not_real.h" -fsyntax-only %s // REQUIRES: shell void foo() { bar(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/external-names.c
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" -e "s:EXTERNAL_NAMES:true:" %S/Inputs/use-external-names.yaml > %t.external.yaml // RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" -e "s:EXTERNAL_NAMES:false:" %S/Inputs/use-external-names.yaml > %t.yaml // REQUIRES: shell #include "external-names.h" //// // Preprocessor (__FILE__ macro and # directives): // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -E %s | FileCheck -check-prefix=CHECK-PP-EXTERNAL %s // CHECK-PP-EXTERNAL: # {{[0-9]*}} "[[NAME:.*Inputs.external-names.h]]" // CHECK-PP-EXTERNAL-NEXT: void foo(char **c) { // CHECK-PP-EXTERNAL-NEXT: *c = "[[NAME]]"; // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -E %s | FileCheck -check-prefix=CHECK-PP %s // CHECK-PP-NOT: Inputs //// // Diagnostics: // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-DIAG-EXTERNAL %s // CHECK-DIAG-EXTERNAL: {{.*}}Inputs{{.}}external-names.h:{{[0-9]*:[0-9]*}}: warning: incompatible pointer // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-DIAG %s // CHECK-DIAG-NOT: Inputs //// // Debug info // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -triple %itanium_abi_triple -g -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG-EXTERNAL %s // CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num:[0-9]+]] // CHECK-DEBUG-EXTERNAL: ![[Num]] = !DIFile(filename: "{{[^"]*}}Inputs{{.}}external-names.h" // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -triple %itanium_abi_triple -g -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG %s // CHECK-DEBUG-NOT: Inputs
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/include-virtual-from-real.c
// RUN: rm -rf %t // RUN: mkdir -p %t // RUN: echo '#include "not_real.h"' > %t/include_not_real.h // RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s // REQUIRES: shell #include "include_not_real.h" void foo() { bar(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/include-mixed-real-and-virtual.c
// RUN: rm -rf %t // RUN: mkdir -p %t // RUN: echo "void baz(void);" > %t/real.h // RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s // REQUIRES: shell #include "not_real.h" #include "real.h" void foo() { bar(); baz(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/include.c
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -I %t -ivfsoverlay %t.yaml -fsyntax-only %s // REQUIRES: shell #include "not_real.h" void foo() { bar(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/include-real-from-virtual.c
// RUN: rm -rf %t // RUN: mkdir -p %t // RUN: echo "void baz(void);" > %t/real.h // RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s // REQUIRES: shell #include "include_real.h" void foo() { baz(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/VFS/relative-path.c
// RUN: mkdir -p %t // RUN: cd %t // RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -I . -ivfsoverlay %t.yaml -fsyntax-only %s // REQUIRES: shell #include "not_real.h" void foo() { bar(); }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/actual_header.h
void bar(void);
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/unknown-key.yaml
{ 'version': 0, 'unknown-key': 'value', 'roots': [] }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/incomplete-umbrella.modulemap
framework module Incomplete { umbrella header "Incomplete.h" export * module * { export * } }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/external-names.h
void foo(char **c) { *c = __FILE__; int x = c; // produce a diagnostic }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/public_header2.h
// public_header2.h
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/public_header.h
#import <SomeFramework/public_header2.h> void from_framework(void);
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/vfsoverlay2.yaml
{ 'version': 0, 'roots': [ { 'name': 'OUT_DIR', 'type': 'directory', 'contents': [ { 'name': 'module.map', 'type': 'file', 'external-contents': 'INPUT_DIR/actual_module2.map' } ] } ] }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/IncompleteVFS.h
// IncompleteVFS.h
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/vfsoverlay.yaml
{ 'version': 0, 'roots': [ { 'name': 'OUT_DIR', 'type': 'directory', 'contents': [ { 'name': 'not_real.h', 'type': 'file', 'external-contents': 'INPUT_DIR/actual_header.h' }, { 'name': 'import_some_frame.h', 'type': 'file', 'external-contents': 'INPUT_DIR/import_some_frame.h' }, { 'name': 'module.map', 'type': 'file', 'external-contents': 'INPUT_DIR/actual_module.map' }, { 'name': 'include_real.h', 'type': 'file', 'external-contents': 'INPUT_DIR/include_real.h' }, { 'name': 'SomeFramework.framework', 'type': 'directory', 'contents': [ { 'name': 'Headers', 'type': 'directory', 'contents': [ { 'name': 'public_header.h', 'type': 'file', 'external-contents': 'INPUT_DIR/public_header.h' }, { 'name': 'public_header2.h', 'type': 'file', 'external-contents': 'INPUT_DIR/public_header2.h' } ] } ] }, { 'name': 'Foo.framework/Headers/Foo.h', 'type': 'file', 'external-contents': 'INPUT_DIR/Foo.h' }, { 'name': 'Incomplete.framework', 'type': 'directory', 'contents': [ { 'name': 'Headers', 'type': 'directory', 'contents': [ { 'name': 'Incomplete.h', 'type': 'file', 'external-contents': 'INPUT_DIR/Incomplete.h' }, { 'name': 'IncompleteVFS.h', 'type': 'file', 'external-contents': 'INPUT_DIR/IncompleteVFS.h' } ] }, { 'name': 'Modules/module.modulemap', 'type': 'file', 'external-contents': 'INPUT_DIR/incomplete-umbrella.modulemap' } ] } ] } ] }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/use-external-names.yaml
{ 'version': 0, 'use-external-names': EXTERNAL_NAMES, 'roots': [{ 'type': 'file', 'name': 'OUT_DIR/external-names.h', 'external-contents': 'INPUT_DIR/external-names.h' }] }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/missing-key.yaml
{ 'version': 0, 'roots': [ { 'name' : 'foo', 'external-contents': 'bar' } ] }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/include_real.h
#include "real.h"
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/invalid-yaml.yaml
{ 'version': 0, 'roots': [] ]
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/import_some_frame.h
#import <SomeFramework/public_header.h> #import <SomeFramework/public_header2.h>
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/Incomplete.h
// does not include IncompleteVFS.h or IncompleteReal.h
0
repos/DirectXShaderCompiler/tools/clang/test/VFS
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/unknown-value.yaml
{ 'version': 0, 'case-sensitive': 'Maybe?', 'roots': [] }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/UsesFoo.framework
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/UsesFoo.framework/Headers/UsesFoo.h
@import Foo;
0
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/UsesFoo.framework
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/UsesFoo.framework/Modules/module.modulemap
framework module UsesFoo { umbrella header "UsesFoo.h" export * }
0
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/Foo.framework
repos/DirectXShaderCompiler/tools/clang/test/VFS/Inputs/Foo.framework/Modules/module.modulemap
framework module Foo { umbrella header "Foo.h" }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/TableGen/DiagnosticBase.inc
// Define the diagnostic mappings. class DiagMapping; def MAP_IGNORE : DiagMapping; def MAP_WARNING : DiagMapping; def MAP_ERROR : DiagMapping; def MAP_FATAL : DiagMapping; // Define the diagnostic classes. class DiagClass; def CLASS_NOTE : DiagClass; def CLASS_WARNING : DiagClass; def CLASS_EXTENSION : DiagClass; def CLASS_ERROR : DiagClass; class DiagGroup<string Name, list<DiagGroup> subgroups = []> { string GroupName = Name; list<DiagGroup> SubGroups = subgroups; string CategoryName = ""; } class InGroup<DiagGroup G> { DiagGroup Group = G; } // All diagnostics emitted by the compiler are an indirect subclass of this. class Diagnostic<string text, DiagClass DC, DiagMapping defaultmapping> { string Text = text; DiagClass Class = DC; DiagMapping DefaultMapping = defaultmapping; DiagGroup Group; string CategoryName = ""; } class Error<string str> : Diagnostic<str, CLASS_ERROR, MAP_ERROR>; class Warning<string str> : Diagnostic<str, CLASS_WARNING, MAP_WARNING>; class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_IGNORE>; class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_WARNING>; class Note<string str> : Diagnostic<str, CLASS_NOTE, MAP_FATAL/*ignored*/>;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/DXILValidation/Readme.md
Files in this directory are used by tests implemented ValidationTest.cpp
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/DXILValidation/lib_no_alloca.h
float2 test(float2 a) { float2 b = a; b.y = sin(a.y); return b; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Integration/carbon.c
// RUN: %clang -fsyntax-only %s #ifdef __APPLE__ #include <Carbon/Carbon.h> #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-basic-layout.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct A4 { int a; A4() : a(0xf00000a4) {} }; struct B4 { int a; B4() : a(0xf00000b4) {} }; struct C4 { int a; C4() : a(0xf00000c4) {} virtual void f() {printf("C4");} }; struct A16 { __declspec(align(16)) int a; A16() : a(0xf0000a16) {} }; struct C16 { __declspec(align(16)) int a; C16() : a(0xf0000c16) {} virtual void f() {printf("C16");} }; struct TestF0 : A4, virtual B4 { int a; TestF0() : a(0xf00000F0) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF0 // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF0 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct B4 (virtual base) // CHECK-NEXT: 12 | int a // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF0 // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF0 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B4 (virtual base) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: | [sizeof=32, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct TestF1 : A4, virtual A16 { int a; TestF1() : a(0xf00000f1) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF1 // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF1 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | struct A16 (virtual base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=32, align=16 // CHECK-NEXT: | nvsize=12, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF1 // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF1 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | struct A16 (virtual base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=48, align=16 // CHECK-X64-NEXT: | nvsize=24, nvalign=16] struct TestF2 : A4, virtual C4 { int a; TestF2() : a(0xf00000f2) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF2 // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF2 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct C4 (virtual base) // CHECK-NEXT: 12 | (C4 vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF2 // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF2 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct C4 (virtual base) // CHECK-X64-NEXT: 24 | (C4 vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct TestF3 : A4, virtual C16 { int a; TestF3() : a(0xf00000f3) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF3 // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF3 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | struct C16 (virtual base) // CHECK-NEXT: 16 | (C16 vftable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=12, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF3 // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF3 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | struct C16 (virtual base) // CHECK-X64-NEXT: 32 | (C16 vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=24, nvalign=16] struct TestF4 : TestF3, A4 { int a; TestF4() : a(0xf00000f4) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF4 // CHECK-NEXT: 0 | struct TestF3 (base) // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF3 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct A4 (base) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | struct C16 (virtual base) // CHECK-NEXT: 32 | (C16 vftable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF4 // CHECK-X64-NEXT: 0 | struct TestF3 (base) // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF3 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct A4 (base) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 28 | int a // CHECK-X64-NEXT: 32 | struct C16 (virtual base) // CHECK-X64-NEXT: 32 | (C16 vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct TestF5 : TestF3, A4 { int a; TestF5() : a(0xf00000f5) {} virtual void g() {printf("F5");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF5 // CHECK-NEXT: 0 | (TestF5 vftable pointer) // CHECK-NEXT: 16 | struct TestF3 (base) // CHECK-NEXT: 16 | struct A4 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (TestF3 vbtable pointer) // CHECK-NEXT: 24 | int a // CHECK-NEXT: 28 | struct A4 (base) // CHECK-NEXT: 28 | int a // CHECK-NEXT: 32 | int a // CHECK-NEXT: 48 | struct C16 (virtual base) // CHECK-NEXT: 48 | (C16 vftable pointer) // CHECK-NEXT: 64 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF5 // CHECK-X64-NEXT: 0 | (TestF5 vftable pointer) // CHECK-X64-NEXT: 16 | struct TestF3 (base) // CHECK-X64-NEXT: 16 | struct A4 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (TestF3 vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 40 | struct A4 (base) // CHECK-X64-NEXT: 40 | int a // CHECK-X64-NEXT: 44 | int a // CHECK-X64-NEXT: 48 | struct C16 (virtual base) // CHECK-X64-NEXT: 48 | (C16 vftable pointer) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct TestF6 : TestF3, A4 { int a; TestF6() : a(0xf00000f6) {} virtual void f() {printf("F6");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF6 // CHECK-NEXT: 0 | struct TestF3 (base) // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF3 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct A4 (base) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 44 | (vtordisp for vbase C16) // CHECK-NEXT: 48 | struct C16 (virtual base) // CHECK-NEXT: 48 | (C16 vftable pointer) // CHECK-NEXT: 64 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF6 // CHECK-X64-NEXT: 0 | struct TestF3 (base) // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF3 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct A4 (base) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 28 | int a // CHECK-X64-NEXT: 44 | (vtordisp for vbase C16) // CHECK-X64-NEXT: 48 | struct C16 (virtual base) // CHECK-X64-NEXT: 48 | (C16 vftable pointer) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct TestF7 : A4, virtual C16 { int a; TestF7() : a(0xf00000f7) {} virtual void f() {printf("F7");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF7 // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF7 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 28 | (vtordisp for vbase C16) // CHECK-NEXT: 32 | struct C16 (virtual base) // CHECK-NEXT: 32 | (C16 vftable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=12, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF7 // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF7 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 44 | (vtordisp for vbase C16) // CHECK-X64-NEXT: 48 | struct C16 (virtual base) // CHECK-X64-NEXT: 48 | (C16 vftable pointer) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=24, nvalign=16] struct TestF8 : TestF7, A4 { int a; TestF8() : a(0xf00000f8) {} virtual void f() {printf("F8");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF8 // CHECK-NEXT: 0 | struct TestF7 (base) // CHECK-NEXT: 0 | struct A4 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (TestF7 vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct A4 (base) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 44 | (vtordisp for vbase C16) // CHECK-NEXT: 48 | struct C16 (virtual base) // CHECK-NEXT: 48 | (C16 vftable pointer) // CHECK-NEXT: 64 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF8 // CHECK-X64-NEXT: 0 | struct TestF7 (base) // CHECK-X64-NEXT: 0 | struct A4 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (TestF7 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct A4 (base) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 28 | int a // CHECK-X64-NEXT: 44 | (vtordisp for vbase C16) // CHECK-X64-NEXT: 48 | struct C16 (virtual base) // CHECK-X64-NEXT: 48 | (C16 vftable pointer) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct TestF9 : A4, virtual C16 { int a; TestF9() : a(0xf00000f9) {} virtual void g() {printf("F9");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestF9 // CHECK-NEXT: 0 | (TestF9 vftable pointer) // CHECK-NEXT: 4 | struct A4 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (TestF9 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct C16 (virtual base) // CHECK-NEXT: 16 | (C16 vftable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=16, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestF9 // CHECK-X64-NEXT: 0 | (TestF9 vftable pointer) // CHECK-X64-NEXT: 8 | struct A4 (base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | (TestF9 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | struct C16 (virtual base) // CHECK-X64-NEXT: 32 | (C16 vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct TestFA : TestF9, A4 { int a; TestFA() : a(0xf00000fa) {} virtual void g() {printf("FA");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestFA // CHECK-NEXT: 0 | struct TestF9 (primary base) // CHECK-NEXT: 0 | (TestF9 vftable pointer) // CHECK-NEXT: 4 | struct A4 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (TestF9 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct A4 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | int a // CHECK-NEXT: 32 | struct C16 (virtual base) // CHECK-NEXT: 32 | (C16 vftable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestFA // CHECK-X64-NEXT: 0 | struct TestF9 (primary base) // CHECK-X64-NEXT: 0 | (TestF9 vftable pointer) // CHECK-X64-NEXT: 8 | struct A4 (base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | (TestF9 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | struct A4 (base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 36 | int a // CHECK-X64-NEXT: 48 | struct C16 (virtual base) // CHECK-X64-NEXT: 48 | (C16 vftable pointer) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct TestFB : A16, virtual C16 { int a; TestFB() : a(0xf00000fb) {} virtual void g() {printf("Fb");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestFB // CHECK-NEXT: 0 | (TestFB vftable pointer) // CHECK-NEXT: 16 | struct A16 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | (TestFB vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct C16 (virtual base) // CHECK-NEXT: 64 | (C16 vftable pointer) // CHECK-NEXT: 80 | int a // CHECK-NEXT: | [sizeof=96, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestFB // CHECK-X64-NEXT: 0 | (TestFB vftable pointer) // CHECK-X64-NEXT: 16 | struct A16 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | (TestFB vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct C16 (virtual base) // CHECK-X64-NEXT: 64 | (C16 vftable pointer) // CHECK-X64-NEXT: 80 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct TestFC : TestFB, A4 { int a; TestFC() : a(0xf00000fc) {} virtual void g() {printf("FC");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct TestFC // CHECK-NEXT: 0 | struct TestFB (primary base) // CHECK-NEXT: 0 | (TestFB vftable pointer) // CHECK-NEXT: 16 | struct A16 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | (TestFB vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct A4 (base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: 68 | int a // CHECK-NEXT: 80 | struct C16 (virtual base) // CHECK-NEXT: 80 | (C16 vftable pointer) // CHECK-NEXT: 96 | int a // CHECK-NEXT: | [sizeof=112, align=16 // CHECK-NEXT: | nvsize=80, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct TestFC // CHECK-X64-NEXT: 0 | struct TestFB (primary base) // CHECK-X64-NEXT: 0 | (TestFB vftable pointer) // CHECK-X64-NEXT: 16 | struct A16 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | (TestFB vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct A4 (base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 68 | int a // CHECK-X64-NEXT: 80 | struct C16 (virtual base) // CHECK-X64-NEXT: 80 | (C16 vftable pointer) // CHECK-X64-NEXT: 96 | int a // CHECK-X64-NEXT: | [sizeof=112, align=16 // CHECK-X64-NEXT: | nvsize=80, nvalign=16] struct A16f { __declspec(align(16)) int a; A16f() : a(0xf0000a16) {} virtual void f() {printf("A16f");} }; struct Y { char y; Y() : y(0xaa) {} }; struct X : virtual A16f {}; struct B : A4, Y, X { int a; B() : a(0xf000000b) {} }; struct F0 : A4, B { int a; F0() : a(0xf00000f0) {} virtual void g() {printf("F0");} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F0 // CHECK-NEXT: 0 | (F0 vftable pointer) // CHECK-NEXT: 16 | struct A4 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | struct B (base) // CHECK-NEXT: 32 | struct A4 (base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 36 | struct Y (base) // CHECK-NEXT: 36 | char y // CHECK-NEXT: 48 | struct X (base) // CHECK-NEXT: 48 | (X vbtable pointer) // CHECK-NEXT: 52 | int a // CHECK-NEXT: 64 | int a // CHECK-NEXT: 80 | struct A16f (virtual base) // CHECK-NEXT: 80 | (A16f vftable pointer) // CHECK-NEXT: 96 | int a // CHECK-NEXT: | [sizeof=112, align=16 // CHECK-NEXT: | nvsize=80, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F0 // CHECK-X64-NEXT: 0 | (F0 vftable pointer) // CHECK-X64-NEXT: 16 | struct A4 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | struct B (base) // CHECK-X64-NEXT: 32 | struct A4 (base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 36 | struct Y (base) // CHECK-X64-NEXT: 36 | char y // CHECK-X64-NEXT: 48 | struct X (base) // CHECK-X64-NEXT: 48 | (X vbtable pointer) // CHECK-X64-NEXT: 56 | int a // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 80 | struct A16f (virtual base) // CHECK-X64-NEXT: 80 | (A16f vftable pointer) // CHECK-X64-NEXT: 96 | int a // CHECK-X64-NEXT: | [sizeof=112, align=16 // CHECK-X64-NEXT: | nvsize=80, nvalign=16] struct F1 : B, A4 { int a; F1() : a(0xf00000f1) {} virtual void g() {printf("F1");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F1 // CHECK-NEXT: 0 | (F1 vftable pointer) // CHECK-NEXT: 16 | struct B (base) // CHECK-NEXT: 16 | struct A4 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct Y (base) // CHECK-NEXT: 20 | char y // CHECK-NEXT: 32 | struct X (base) // CHECK-NEXT: 32 | (X vbtable pointer) // CHECK-NEXT: 36 | int a // CHECK-NEXT: 48 | struct A4 (base) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 52 | int a // CHECK-NEXT: 64 | struct A16f (virtual base) // CHECK-NEXT: 64 | (A16f vftable pointer) // CHECK-NEXT: 80 | int a // CHECK-NEXT: | [sizeof=96, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F1 // CHECK-X64-NEXT: 0 | (F1 vftable pointer) // CHECK-X64-NEXT: 16 | struct B (base) // CHECK-X64-NEXT: 16 | struct A4 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | struct Y (base) // CHECK-X64-NEXT: 20 | char y // CHECK-X64-NEXT: 32 | struct X (base) // CHECK-X64-NEXT: 32 | (X vbtable pointer) // CHECK-X64-NEXT: 40 | int a // CHECK-X64-NEXT: 48 | struct A4 (base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 52 | int a // CHECK-X64-NEXT: 64 | struct A16f (virtual base) // CHECK-X64-NEXT: 64 | (A16f vftable pointer) // CHECK-X64-NEXT: 80 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct F2 : A4, virtual A16f { int a; F2() : a(0xf00000f2) {} virtual void g() {printf("F2");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F2 // CHECK-NEXT: 0 | (F2 vftable pointer) // CHECK-NEXT: 4 | struct A4 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (F2 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct A16f (virtual base) // CHECK-NEXT: 16 | (A16f vftable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=16, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F2 // CHECK-X64-NEXT: 0 | (F2 vftable pointer) // CHECK-X64-NEXT: 8 | struct A4 (base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | (F2 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | struct A16f (virtual base) // CHECK-X64-NEXT: 32 | (A16f vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct F3 : A4, virtual A16f { __declspec(align(16)) int a; F3() : a(0xf00000f3) {} virtual void g() {printf("F3");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F3 // CHECK-NEXT: 0 | (F3 vftable pointer) // CHECK-NEXT: 16 | struct A4 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (F3 vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct A16f (virtual base) // CHECK-NEXT: 64 | (A16f vftable pointer) // CHECK-NEXT: 80 | int a // CHECK-NEXT: | [sizeof=96, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F3 // CHECK-X64-NEXT: 0 | (F3 vftable pointer) // CHECK-X64-NEXT: 16 | struct A4 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (F3 vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct A16f (virtual base) // CHECK-X64-NEXT: 64 | (A16f vftable pointer) // CHECK-X64-NEXT: 80 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct F4 : A4, B { __declspec(align(16)) int a; F4() : a(0xf00000f4) {} virtual void g() {printf("F4");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F4 // CHECK-NEXT: 0 | (F4 vftable pointer) // CHECK-NEXT: 16 | struct A4 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | struct B (base) // CHECK-NEXT: 32 | struct A4 (base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 36 | struct Y (base) // CHECK-NEXT: 36 | char y // CHECK-NEXT: 48 | struct X (base) // CHECK-NEXT: 48 | (X vbtable pointer) // CHECK-NEXT: 52 | int a // CHECK-NEXT: 64 | int a // CHECK-NEXT: 80 | struct A16f (virtual base) // CHECK-NEXT: 80 | (A16f vftable pointer) // CHECK-NEXT: 96 | int a // CHECK-NEXT: | [sizeof=112, align=16 // CHECK-NEXT: | nvsize=80, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F4 // CHECK-X64-NEXT: 0 | (F4 vftable pointer) // CHECK-X64-NEXT: 16 | struct A4 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | struct B (base) // CHECK-X64-NEXT: 32 | struct A4 (base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 36 | struct Y (base) // CHECK-X64-NEXT: 36 | char y // CHECK-X64-NEXT: 48 | struct X (base) // CHECK-X64-NEXT: 48 | (X vbtable pointer) // CHECK-X64-NEXT: 56 | int a // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 80 | struct A16f (virtual base) // CHECK-X64-NEXT: 80 | (A16f vftable pointer) // CHECK-X64-NEXT: 96 | int a // CHECK-X64-NEXT: | [sizeof=112, align=16 // CHECK-X64-NEXT: | nvsize=80, nvalign=16] struct F5 : A16f, virtual A4 { int a; F5() : a(0xf00000f5) {} virtual void g() {printf("F5");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F5 // CHECK-NEXT: 0 | struct A16f (primary base) // CHECK-NEXT: 0 | (A16f vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | (F5 vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct A4 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F5 // CHECK-X64-NEXT: 0 | struct A16f (primary base) // CHECK-X64-NEXT: 0 | (A16f vftable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | (F5 vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct A4 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct F6 : virtual A16f, A4, virtual B { int a; F6() : a(0xf00000f6) {} virtual void g() {printf("F6");} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F6 // CHECK-NEXT: 0 | (F6 vftable pointer) // CHECK-NEXT: 4 | struct A4 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (F6 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct A16f (virtual base) // CHECK-NEXT: 16 | (A16f vftable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 48 | struct B (virtual base) // CHECK-NEXT: 48 | struct A4 (base) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 52 | struct Y (base) // CHECK-NEXT: 52 | char y // CHECK-NEXT: 64 | struct X (base) // CHECK-NEXT: 64 | (X vbtable pointer) // CHECK-NEXT: 68 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=16, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F6 // CHECK-X64-NEXT: 0 | (F6 vftable pointer) // CHECK-X64-NEXT: 8 | struct A4 (base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | (F6 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | struct A16f (virtual base) // CHECK-X64-NEXT: 32 | (A16f vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B (virtual base) // CHECK-X64-NEXT: 64 | struct A4 (base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 68 | struct Y (base) // CHECK-X64-NEXT: 68 | char y // CHECK-X64-NEXT: 80 | struct X (base) // CHECK-X64-NEXT: 80 | (X vbtable pointer) // CHECK-X64-NEXT: 88 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct ArrayFieldOfRecords { A4 InlineElts[2]; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct ArrayFieldOfRecords // CHECK-NEXT: 0 | struct A4 [2] InlineElts // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct ArrayFieldOfRecords // CHECK-X64-NEXT: 0 | struct A4 [2] InlineElts // CHECK-X64-NEXT: | [sizeof=8, align=4 // CHECK-X64-NEXT: | nvsize=8, nvalign=4] struct ArrayOfArrayFieldOfRecords { A4 InlineElts[2][2]; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct ArrayOfArrayFieldOfRecords // CHECK-NEXT: 0 | struct A4 [2][2] InlineElts // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct ArrayOfArrayFieldOfRecords // CHECK-X64-NEXT: 0 | struct A4 [2][2] InlineElts // CHECK-X64-NEXT: | [sizeof=16, align=4 // CHECK-X64-NEXT: | nvsize=16, nvalign=4] struct RecordArrayTypedef { typedef A4 ArrayTy[2]; ArrayTy InlineElts[2]; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RecordArrayTypedef // CHECK-NEXT: 0 | ArrayTy [2] InlineElts // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RecordArrayTypedef // CHECK-X64-NEXT: 0 | ArrayTy [2] InlineElts // CHECK-X64-NEXT: | [sizeof=16, align=4 // CHECK-X64-NEXT: | nvsize=16, nvalign=4] struct EmptyIntMemb { int FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct EmptyIntMemb // CHECK-NEXT: 0 | int [0] FlexArrayMemb // CHECK-NEXT: | [sizeof=1, align=4 // CHECK-NEXT: | nvsize=0, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct EmptyIntMemb // CHECK-X64-NEXT: 0 | int [0] FlexArrayMemb // CHECK-X64-NEXT: | [sizeof=4, align=4 // CHECK-X64-NEXT: | nvsize=0, nvalign=4] struct EmptyLongLongMemb { long long FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct EmptyLongLongMemb // CHECK-NEXT: 0 | long long [0] FlexArrayMemb // CHECK-NEXT: | [sizeof=1, align=8 // CHECK-NEXT: | nvsize=0, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct EmptyLongLongMemb // CHECK-X64-NEXT: 0 | long long [0] FlexArrayMemb // CHECK-X64-NEXT: | [sizeof=8, align=8 // CHECK-X64-NEXT: | nvsize=0, nvalign=8] int a[ sizeof(TestF0)+ sizeof(TestF1)+ sizeof(TestF2)+ sizeof(TestF3)+ sizeof(TestF4)+ sizeof(TestF5)+ sizeof(TestF6)+ sizeof(TestF7)+ sizeof(TestF8)+ sizeof(TestF9)+ sizeof(TestFA)+ sizeof(TestFB)+ sizeof(TestFC)+ sizeof(F0)+ sizeof(F1)+ sizeof(F2)+ sizeof(F3)+ sizeof(F4)+ sizeof(F5)+ sizeof(F6)+ sizeof(ArrayFieldOfRecords)+ sizeof(ArrayOfArrayFieldOfRecords)+ sizeof(RecordArrayTypedef)+ sizeof(EmptyIntMemb)+ sizeof(EmptyLongLongMemb)+ 0];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-aligned-tail-padding.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { int a; B0() : a(0xf00000B0) {} }; struct __declspec(align(16)) B1 { int a; B1() : a(0xf00000B1) {} }; struct B2 { __declspec(align(16)) int a; B2() : a(0xf00000B2) {} }; struct __declspec(align(16)) B3 { long long a1; int a; B3() : a(0xf00000B3), a1(0xf00000B3f00000B3ll) {} }; struct V { char a; V() : a(0X11) {} }; struct __declspec(align(32)) A16 {}; struct V1 : A16 { virtual void f() {} }; struct V2 { long long a; int a1; V2() : a(0xf0000011f0000011ll), a1(0xf0000011) {} }; struct V3 { int a; V3() : a(0xf0000022) {} }; struct __declspec(align(16)) A16X { }; struct __declspec(align(16)) B0X { int a, a1; B0X() : a(0xf00000B0), a1(0xf00000B0) {} }; struct B1X { int a; B1X() : a(0xf00000B1) {} }; struct B2X { int a; B2X() : a(0xf00000B2) {} }; struct __declspec(align(16)) B3X { int a; B3X() : a(0xf00000B3) {} virtual void g() {} }; struct B4X : A16X { int a, a1; B4X() : a(0xf00000B4), a1(0xf00000B4) {} }; struct B5X : virtual A16X { int a, a1; B5X() : a(0xf00000B5), a1(0xf00000B5) {} }; struct B6X { int a; B6X() : a(0xf00000B6) {} }; struct A : B1, B0, B2, virtual V { int a; A() : a(0xf000000A) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | struct B1 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | struct B0 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 16 | struct B2 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | (A vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct V (virtual base) // CHECK-NEXT: 64 | char a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | struct B1 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 4 | struct B0 (base) // CHECK-X64-NEXT: 4 | int a // CHECK-X64-NEXT: 16 | struct B2 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | (A vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct V (virtual base) // CHECK-X64-NEXT: 64 | char a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct B : B2, B0, B1, virtual V { int a; B() : a(0xf000000B) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | struct B2 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 16 | struct B0 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | struct B1 (base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 36 | (B vbtable pointer) // CHECK-NEXT: 52 | int a // CHECK-NEXT: 64 | struct V (virtual base) // CHECK-NEXT: 64 | char a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | struct B2 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | struct B1 (base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 40 | (B vbtable pointer) // CHECK-X64-NEXT: 52 | int a // CHECK-X64-NEXT: 64 | struct V (virtual base) // CHECK-X64-NEXT: 64 | char a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct C : B1, B0, virtual V { int a; long long a1; C() : a(0xf000000C), a1(0xf000000Cf000000Cll) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | struct B1 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | struct B0 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (C vbtable pointer) // CHECK-NEXT: 24 | int a // CHECK-NEXT: 32 | long long a1 // CHECK-NEXT: 48 | struct V (virtual base) // CHECK-NEXT: 48 | char a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | struct B1 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 4 | struct B0 (base) // CHECK-X64-NEXT: 4 | int a // CHECK-X64-NEXT: 8 | (C vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | long long a1 // CHECK-X64-NEXT: 48 | struct V (virtual base) // CHECK-X64-NEXT: 48 | char a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct D : B2, B0, virtual V { int a; D() : a(0xf000000D) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct B2 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 16 | struct B0 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (D vbtable pointer) // CHECK-NEXT: 36 | int a // CHECK-NEXT: 48 | struct V (virtual base) // CHECK-NEXT: 48 | char a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | struct B2 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (D vbtable pointer) // CHECK-X64-NEXT: 36 | int a // CHECK-X64-NEXT: 48 | struct V (virtual base) // CHECK-X64-NEXT: 48 | char a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct E : B3, B0, virtual V { int a; E() : a(0xf000000E) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | struct B3 (base) // CHECK-NEXT: 0 | long long a1 // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | struct B0 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (E vbtable pointer) // CHECK-NEXT: 36 | int a // CHECK-NEXT: 48 | struct V (virtual base) // CHECK-NEXT: 48 | char a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | struct B3 (base) // CHECK-X64-NEXT: 0 | long long a1 // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (E vbtable pointer) // CHECK-X64-NEXT: 36 | int a // CHECK-X64-NEXT: 48 | struct V (virtual base) // CHECK-X64-NEXT: 48 | char a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct F : B0, virtual V1 { __declspec(align(16)) int a; F() : a(0xf000000F) {} virtual void f() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | struct B0 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (F vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 92 | (vtordisp for vbase V1) // CHECK-NEXT: 96 | struct V1 (virtual base) // CHECK-NEXT: 96 | (V1 vftable pointer) // CHECK-NEXT: 128 | struct A16 (base) (empty) // CHECK-NEXT: | [sizeof=128, align=32 // CHECK-NEXT: | nvsize=48, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | struct B0 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (F vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 92 | (vtordisp for vbase V1) // CHECK-X64-NEXT: 96 | struct V1 (virtual base) // CHECK-X64-NEXT: 96 | (V1 vftable pointer) // CHECK-X64-NEXT: 128 | struct A16 (base) (empty) // CHECK-X64-NEXT: | [sizeof=128, align=32 // CHECK-X64-NEXT: | nvsize=48, nvalign=32] struct G : virtual V2, virtual V3 { int a; G() : a(0xf0000001) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct G // CHECK-NEXT: 0 | (G vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct V2 (virtual base) // CHECK-NEXT: 8 | long long a // CHECK-NEXT: 16 | int a1 // CHECK-NEXT: 24 | struct V3 (virtual base) // CHECK-NEXT: 24 | int a // CHECK-NEXT: | [sizeof=28, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct G // CHECK-X64-NEXT: 0 | (G vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct V2 (virtual base) // CHECK-X64-NEXT: 16 | long long a // CHECK-X64-NEXT: 24 | int a1 // CHECK-X64-NEXT: 32 | struct V3 (virtual base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct H { __declspec(align(16)) int a; int b; H() : a(0xf0000010), b(0xf0000010) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct H // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | int b // CHECK-NEXT: | [sizeof=16, align=16 // CHECK-NEXT: | nvsize=16, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct H // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 4 | int b // CHECK-X64-NEXT: | [sizeof=16, align=16 // CHECK-X64-NEXT: | nvsize=16, nvalign=16] struct I { B2 a; int b; I() : b(0xf0000010) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct I // CHECK-NEXT: 0 | struct B2 a // CHECK-NEXT: 0 | int a // CHECK: 16 | int b // CHECK-NEXT: | [sizeof=32, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct I // CHECK-X64-NEXT: 0 | struct B2 a // CHECK-X64-NEXT: 0 | int a // CHECK-X64: 16 | int b // CHECK-X64-NEXT: | [sizeof=32, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct AX : B0X, virtual B2X, virtual B6X, virtual B3X { int a; AX() : a(0xf000000A) {} virtual void f() {} virtual void g() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AX // CHECK-NEXT: 0 | (AX vftable pointer) // CHECK-NEXT: 16 | struct B0X (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | int a1 // CHECK-NEXT: 24 | (AX vbtable pointer) // CHECK-NEXT: 40 | int a // CHECK-NEXT: 48 | struct B2X (virtual base) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 52 | struct B6X (virtual base) // CHECK-NEXT: 52 | int a // CHECK-NEXT: 76 | (vtordisp for vbase B3X) // CHECK-NEXT: 80 | struct B3X (virtual base) // CHECK-NEXT: 80 | (B3X vftable pointer) // CHECK-NEXT: 84 | int a // CHECK-NEXT: | [sizeof=96, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AX // CHECK-X64-NEXT: 0 | (AX vftable pointer) // CHECK-X64-NEXT: 16 | struct B0X (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | int a1 // CHECK-X64-NEXT: 24 | (AX vbtable pointer) // CHECK-X64-NEXT: 40 | int a // CHECK-X64-NEXT: 48 | struct B2X (virtual base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 52 | struct B6X (virtual base) // CHECK-X64-NEXT: 52 | int a // CHECK-X64-NEXT: 76 | (vtordisp for vbase B3X) // CHECK-X64-NEXT: 80 | struct B3X (virtual base) // CHECK-X64-NEXT: 80 | (B3X vftable pointer) // CHECK-X64-NEXT: 88 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct BX : B4X, virtual B2X, virtual B6X, virtual B3X { int a; BX() : a(0xf000000B) {} virtual void f() {} virtual void g() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct BX // CHECK-NEXT: 0 | (BX vftable pointer) // CHECK-NEXT: 16 | struct B4X (base) // CHECK-NEXT: 16 | struct A16X (base) (empty) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | int a1 // CHECK-NEXT: 32 | (BX vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct B2X (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: 68 | struct B6X (virtual base) // CHECK-NEXT: 68 | int a // CHECK-NEXT: 92 | (vtordisp for vbase B3X) // CHECK-NEXT: 96 | struct B3X (virtual base) // CHECK-NEXT: 96 | (B3X vftable pointer) // CHECK-NEXT: 100 | int a // CHECK-NEXT: | [sizeof=112, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct BX // CHECK-X64-NEXT: 0 | (BX vftable pointer) // CHECK-X64-NEXT: 16 | struct B4X (base) // CHECK-X64-NEXT: 16 | struct A16X (base) (empty) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | int a1 // CHECK-X64-NEXT: 32 | (BX vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B2X (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 68 | struct B6X (virtual base) // CHECK-X64-NEXT: 68 | int a // CHECK-X64-NEXT: 92 | (vtordisp for vbase B3X) // CHECK-X64-NEXT: 96 | struct B3X (virtual base) // CHECK-X64-NEXT: 96 | (B3X vftable pointer) // CHECK-X64-NEXT: 104 | int a // CHECK-X64-NEXT: | [sizeof=112, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct CX : B5X, virtual B2X, virtual B6X, virtual B3X { int a; CX() : a(0xf000000C) {} virtual void f() {} virtual void g() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct CX // CHECK-NEXT: 0 | (CX vftable pointer) // CHECK-NEXT: 16 | struct B5X (base) // CHECK-NEXT: 16 | (B5X vbtable pointer) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 24 | int a1 // CHECK-NEXT: 28 | int a // CHECK-NEXT: 32 | struct A16X (virtual base) (empty) // CHECK-NEXT: 32 | struct B2X (virtual base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 36 | struct B6X (virtual base) // CHECK-NEXT: 36 | int a // CHECK-NEXT: 60 | (vtordisp for vbase B3X) // CHECK-NEXT: 64 | struct B3X (virtual base) // CHECK-NEXT: 64 | (B3X vftable pointer) // CHECK-NEXT: 68 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct CX // CHECK-X64-NEXT: 0 | (CX vftable pointer) // CHECK-X64-NEXT: 16 | struct B5X (base) // CHECK-X64-NEXT: 16 | (B5X vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 28 | int a1 // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | struct A16X (virtual base) (empty) // CHECK-X64-NEXT: 48 | struct B2X (virtual base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 52 | struct B6X (virtual base) // CHECK-X64-NEXT: 52 | int a // CHECK-X64-NEXT: 76 | (vtordisp for vbase B3X) // CHECK-X64-NEXT: 80 | struct B3X (virtual base) // CHECK-X64-NEXT: 80 | (B3X vftable pointer) // CHECK-X64-NEXT: 88 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct __declspec(align(16)) DX { int a; DX() : a(0xf000000D) {} virtual void f() {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct DX // CHECK-NEXT: 0 | (DX vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: | [sizeof=16, align=16 // CHECK-NEXT: | nvsize=8, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct DX // CHECK-X64-NEXT: 0 | (DX vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: | [sizeof=16, align=16 // CHECK-X64-NEXT: | nvsize=16, nvalign=16] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(G)+ sizeof(H)+ sizeof(I)+ sizeof(AX)+ sizeof(BX)+ sizeof(CX)+ sizeof(DX)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-bitfields-vbases.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>&1 \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 struct B0 { int a; }; struct B1 { int a; }; struct A : virtual B0 { char a : 1; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct B : virtual B0 { short a : 1; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | (B vbtable pointer) // CHECK-NEXT: 4 | short a // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | (B vbtable pointer) // CHECK-X64-NEXT: 8 | short a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct C : virtual B0 { char a : 1; char : 0; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 5 | char // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 9 | char // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct D : virtual B0 { char a : 1; char b; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | (D vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 5 | char b // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | (D vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 9 | char b // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct E : virtual B0, virtual B1 { long long : 1; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | (E vbtable pointer) // CHECK-NEXT: 8 | long long // CHECK-NEXT: 16 | struct B0 (virtual base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B1 (virtual base) // CHECK-NEXT: 20 | int a // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=16, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | (E vbtable pointer) // CHECK-X64-NEXT: 8 | long long // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | struct B1 (virtual base) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-empty-nonvirtual-bases.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s extern "C" int printf(const char *fmt, ...); struct __declspec(align(8)) B0 { B0() {printf("B0 : %p\n", this);} }; struct __declspec(align(8)) B1 { B1() {printf("B1 : %p\n", this);} }; struct __declspec(align(8)) B2 { B2() {printf("B2 : %p\n", this);} }; struct __declspec(align(8)) B3 { B3() {printf("B3 : %p\n", this);} }; struct __declspec(align(8)) B4 { B4() {printf("B4 : %p\n", this);} }; struct C0 { int a; C0() : a(0xf00000C0) {printf("C0 : %p\n", this);} }; struct C1 { int a; C1() : a(0xf00000C1) {printf("C1 : %p\n", this);} }; struct C2 { int a; C2() : a(0xf00000C2) {printf("C2 : %p\n", this);} }; struct C3 { int a; C3() : a(0xf00000C3) {printf("C3 : %p\n", this);} }; struct C4 { int a; C4() : a(0xf00000C4) {printf("C4 : %p\n", this);} }; struct A : B0 { int a; A() : a(0xf000000A) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | struct B0 (base) (empty) // CHECK-NEXT: 0 | int a // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] struct B : B0 { B0 b0; int a; B() : a(0xf000000B) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | struct B0 (base) (empty) // CHECK-NEXT: 0 | struct B0 b0 (empty) // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=0, nvalign=8] // CHECK: 8 | int a // CHECK-NEXT: | [sizeof=16, align=8 // CHECK-NEXT: | nvsize=16, nvalign=8] struct C : B0, B1, B2, B3, B4 { int a; C() : a(0xf000000C) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | struct B0 (base) (empty) // CHECK-NEXT: 8 | struct B1 (base) (empty) // CHECK-NEXT: 16 | struct B2 (base) (empty) // CHECK-NEXT: 24 | struct B3 (base) (empty) // CHECK-NEXT: 32 | struct B4 (base) (empty) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=40, align=8 // CHECK-NEXT: | nvsize=40, nvalign=8] struct D { B0 b0; C0 c0; C1 c1; C2 c2; B1 b1; int a; D() : a(0xf000000D) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct B0 b0 (empty) // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=0, nvalign=8] // CHECK: 8 | struct C0 c0 // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK: 12 | struct C1 c1 // CHECK-NEXT: 12 | int a // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK: 16 | struct C2 c2 // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK: 24 | struct B1 b1 (empty) // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=0, nvalign=8] // CHECK: 32 | int a // CHECK-NEXT: | [sizeof=40, align=8 // CHECK-NEXT: | nvsize=40, nvalign=8] struct E : B0, C0, C1, C2, B1 { int a; E() : a(0xf000000E) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | struct B0 (base) (empty) // CHECK-NEXT: 0 | struct C0 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | struct C1 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct C2 (base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | struct B1 (base) (empty) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=24, nvalign=8] struct F : C0, B0, B1, C1 { int a; F() : a(0xf000000F) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | struct C0 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 8 | struct B0 (base) (empty) // CHECK-NEXT: 16 | struct B1 (base) (empty) // CHECK-NEXT: 16 | struct C1 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | int a // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=24, nvalign=8] struct G : B0, B1, B2, B3, B4 { __declspec(align(32)) int a; G() : a(0xf0000011) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct G // CHECK-NEXT: 0 | struct B0 (base) (empty) // CHECK-NEXT: 8 | struct B1 (base) (empty) // CHECK-NEXT: 16 | struct B2 (base) (empty) // CHECK-NEXT: 24 | struct B3 (base) (empty) // CHECK-NEXT: 32 | struct B4 (base) (empty) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=64, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] struct __declspec(align(32)) H : B0, B1, B2, B3, B4 { int a; H() : a(0xf0000011) {printf("X : %p\n", this);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct H // CHECK-NEXT: 0 | struct B0 (base) (empty) // CHECK-NEXT: 8 | struct B1 (base) (empty) // CHECK-NEXT: 16 | struct B2 (base) (empty) // CHECK-NEXT: 24 | struct B3 (base) (empty) // CHECK-NEXT: 32 | struct B4 (base) (empty) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=64, align=32 // CHECK-NEXT: | nvsize=40, nvalign=32] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(G)+ sizeof(H)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-member-pointers.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fms-extensions -fsyntax-only %s 2>&1 | FileCheck %s struct __single_inheritance S; struct __multiple_inheritance M; struct __virtual_inheritance V; struct U; struct SD { char a; int S::*mp; }; struct MD { char a; int M::*mp; }; struct VD { char a; int V::*mp; }; struct UD { char a; int U::*mp; }; struct SF { char a; int (S::*mp)(); }; struct MF { char a; int (M::*mp)(); }; struct VF { char a; int (V::*mp)(); }; struct UF { char a; int (U::*mp)(); }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct SD // CHECK-NEXT: 0 | char a // CHECK-NEXT: 4 | int struct S::* mp // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct MD // CHECK-NEXT: 0 | char a // CHECK-NEXT: 4 | int struct M::* mp // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct VD // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | int struct V::* mp // CHECK-NEXT: | [sizeof=16, align=8 // CHECK-NEXT: | nvsize=16, nvalign=8] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct UD // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | int struct U::* mp // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=24, nvalign=8] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct SF // CHECK-NEXT: 0 | char a // CHECK-NEXT: 4 | int (struct S::*)(void) __attribute__((thiscall)) mp // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct MF // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | int (struct M::*)(void) __attribute__((thiscall)) mp // CHECK-NEXT: | [sizeof=16, align=8 // CHECK-NEXT: | nvsize=16, nvalign=8] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct VF // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | int (struct V::*)(void) __attribute__((thiscall)) mp // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=24, nvalign=8] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct UF // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | int (struct U::*)(void) __attribute__((thiscall)) mp // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=24, nvalign=8] char a[sizeof(SD) + sizeof(MD) + sizeof(VD) + sizeof(UD) + sizeof(SF) + sizeof(MF) + sizeof(VF) + sizeof(UF)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-empty-base-after-base-with-vbptr.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fdump-record-layouts %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 struct U { char a; }; struct V { }; struct W { }; struct X : virtual V { char a; }; struct Y : virtual V { char a; }; struct Z : Y { }; struct A : X, W { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | struct X (base) // CHECK-NEXT: 0 | (X vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 9 | struct W (base) (empty) // CHECK-NEXT: 9 | char a // CHECK-NEXT: 12 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | struct X (base) // CHECK-X64-NEXT: 0 | (X vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 17 | struct W (base) (empty) // CHECK-X64-NEXT: 17 | char a // CHECK-X64-NEXT: 24 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct B : X, U, W { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | struct X (base) // CHECK-NEXT: 0 | (X vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 8 | struct U (base) // CHECK-NEXT: 8 | char a // CHECK-NEXT: 9 | struct W (base) (empty) // CHECK-NEXT: 9 | char a // CHECK-NEXT: 12 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | struct X (base) // CHECK-X64-NEXT: 0 | (X vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 16 | struct U (base) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 17 | struct W (base) (empty) // CHECK-X64-NEXT: 17 | char a // CHECK-X64-NEXT: 24 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct C : X, V, W { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | struct X (base) // CHECK-NEXT: 0 | (X vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 9 | struct V (base) (empty) // CHECK-NEXT: 10 | struct W (base) (empty) // CHECK-NEXT: 10 | char a // CHECK-NEXT: 12 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | struct X (base) // CHECK-X64-NEXT: 0 | (X vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 17 | struct V (base) (empty) // CHECK-X64-NEXT: 18 | struct W (base) (empty) // CHECK-X64-NEXT: 18 | char a // CHECK-X64-NEXT: 24 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct D : X, U, V, W { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct X (base) // CHECK-NEXT: 0 | (X vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 8 | struct U (base) // CHECK-NEXT: 8 | char a // CHECK-NEXT: 9 | struct V (base) (empty) // CHECK-NEXT: 10 | struct W (base) (empty) // CHECK-NEXT: 10 | char a // CHECK-NEXT: 12 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | struct X (base) // CHECK-X64-NEXT: 0 | (X vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 16 | struct U (base) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 17 | struct V (base) (empty) // CHECK-X64-NEXT: 18 | struct W (base) (empty) // CHECK-X64-NEXT: 18 | char a // CHECK-X64-NEXT: 24 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct E : X, U, Y, V, W { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | struct X (base) // CHECK-NEXT: 0 | (X vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 8 | struct U (base) // CHECK-NEXT: 8 | char a // CHECK-NEXT: 12 | struct Y (base) // CHECK-NEXT: 12 | (Y vbtable pointer) // CHECK-NEXT: 16 | char a // CHECK-NEXT: 21 | struct V (base) (empty) // CHECK-NEXT: 22 | struct W (base) (empty) // CHECK-NEXT: 22 | char a // CHECK-NEXT: 24 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=24, align=4 // CHECK-NEXT: | nvsize=24, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | struct X (base) // CHECK-X64-NEXT: 0 | (X vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 16 | struct U (base) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct Y (base) // CHECK-X64-NEXT: 24 | (Y vbtable pointer) // CHECK-X64-NEXT: 32 | char a // CHECK-X64-NEXT: 41 | struct V (base) (empty) // CHECK-X64-NEXT: 42 | struct W (base) (empty) // CHECK-X64-NEXT: 42 | char a // CHECK-X64-NEXT: 48 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=48, align=8 // CHECK-X64-NEXT: | nvsize=48, nvalign=8] struct F : Z, W { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | struct Z (base) // CHECK-NEXT: 0 | struct Y (base) // CHECK-NEXT: 0 | (Y vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 9 | struct W (base) (empty) // CHECK-NEXT: 9 | char a // CHECK-NEXT: 12 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | struct Z (base) // CHECK-X64-NEXT: 0 | struct Y (base) // CHECK-X64-NEXT: 0 | (Y vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 17 | struct W (base) (empty) // CHECK-X64-NEXT: 17 | char a // CHECK-X64-NEXT: 24 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct G : X, W, Y, V { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct G // CHECK-NEXT: 0 | struct X (base) // CHECK-NEXT: 0 | (X vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 9 | struct W (base) (empty) // CHECK-NEXT: 12 | struct Y (base) // CHECK-NEXT: 12 | (Y vbtable pointer) // CHECK-NEXT: 16 | char a // CHECK-NEXT: 21 | struct V (base) (empty) // CHECK-NEXT: 21 | char a // CHECK-NEXT: 24 | struct V (virtual base) (empty) // CHECK-NEXT: | [sizeof=24, align=4 // CHECK-NEXT: | nvsize=24, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct G // CHECK-X64-NEXT: 0 | struct X (base) // CHECK-X64-NEXT: 0 | (X vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 17 | struct W (base) (empty) // CHECK-X64-NEXT: 24 | struct Y (base) // CHECK-X64-NEXT: 24 | (Y vbtable pointer) // CHECK-X64-NEXT: 32 | char a // CHECK-X64-NEXT: 41 | struct V (base) (empty) // CHECK-X64-NEXT: 41 | char a // CHECK-X64-NEXT: 48 | struct V (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=48, align=8 // CHECK-X64-NEXT: | nvsize=48, nvalign=8] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(G)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-vtordisp.cpp
// RUN: %clang_cc1 -fno-rtti -fms-extensions -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>&1 \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -fms-extensions -emit-llvm-only -triple x86_64-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { int a; B0() : a(0xf00000B0) {} virtual void f() { printf("B0"); } }; struct __declspec(align(16)) B1 { int a; B1() : a(0xf00000B1) {} virtual void f() { printf("B1"); } }; struct __declspec(align(16)) Align16 {}; struct __declspec(align(32)) Align32 {}; struct VAlign16 : virtual Align16 {}; struct VAlign32 : virtual Align32 {}; struct A : virtual B0, virtual B1 { int a; A() : a(0xf000000A) {} virtual void f() { printf("A"); } virtual void g() { printf("A"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vftable pointer) // CHECK-NEXT: 4 | (A vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | (vtordisp for vbase B0) // CHECK-NEXT: 20 | struct B0 (virtual base) // CHECK-NEXT: 20 | (B0 vftable pointer) // CHECK-NEXT: 24 | int a // CHECK-NEXT: 44 | (vtordisp for vbase B1) // CHECK-NEXT: 48 | struct B1 (virtual base) // CHECK-NEXT: 48 | (B1 vftable pointer) // CHECK-NEXT: 52 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=12, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vftable pointer) // CHECK-X64-NEXT: 8 | (A vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 36 | (vtordisp for vbase B0) // CHECK-X64-NEXT: 40 | struct B0 (virtual base) // CHECK-X64-NEXT: 40 | (B0 vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 76 | (vtordisp for vbase B1) // CHECK-X64-NEXT: 80 | struct B1 (virtual base) // CHECK-X64-NEXT: 80 | (B1 vftable pointer) // CHECK-X64-NEXT: 88 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=24, nvalign=16] struct C : virtual B0, virtual B1, VAlign32 { int a; C() : a(0xf000000C) {} virtual void f() { printf("C"); } virtual void g() { printf("C"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vftable pointer) // CHECK-NEXT: 32 | struct VAlign32 (base) // CHECK-NEXT: 32 | (VAlign32 vbtable pointer) // CHECK-NEXT: 36 | int a // CHECK-NEXT: 64 | (vtordisp for vbase B0) // CHECK-NEXT: 68 | struct B0 (virtual base) // CHECK-NEXT: 68 | (B0 vftable pointer) // CHECK-NEXT: 72 | int a // CHECK-NEXT: 108 | (vtordisp for vbase B1) // CHECK-NEXT: 112 | struct B1 (virtual base) // CHECK-NEXT: 112 | (B1 vftable pointer) // CHECK-NEXT: 116 | int a // CHECK-NEXT: 128 | struct Align32 (virtual base) (empty) // CHECK-NEXT: | [sizeof=128, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vftable pointer) // CHECK-X64-NEXT: 32 | struct VAlign32 (base) // CHECK-X64-NEXT: 32 | (VAlign32 vbtable pointer) // CHECK-X64-NEXT: 40 | int a // CHECK-X64-NEXT: 68 | (vtordisp for vbase B0) // CHECK-X64-NEXT: 72 | struct B0 (virtual base) // CHECK-X64-NEXT: 72 | (B0 vftable pointer) // CHECK-X64-NEXT: 80 | int a // CHECK-X64-NEXT: 108 | (vtordisp for vbase B1) // CHECK-X64-NEXT: 112 | struct B1 (virtual base) // CHECK-X64-NEXT: 112 | (B1 vftable pointer) // CHECK-X64-NEXT: 120 | int a // CHECK-X64-NEXT: 128 | struct Align32 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=128, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct __declspec(align(32)) D : virtual B0, virtual B1 { int a; D() : a(0xf000000D) {} virtual void f() { printf("D"); } virtual void g() { printf("D"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | (D vftable pointer) // CHECK-NEXT: 4 | (D vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 32 | (vtordisp for vbase B0) // CHECK-NEXT: 36 | struct B0 (virtual base) // CHECK-NEXT: 36 | (B0 vftable pointer) // CHECK-NEXT: 40 | int a // CHECK-NEXT: 76 | (vtordisp for vbase B1) // CHECK-NEXT: 80 | struct B1 (virtual base) // CHECK-NEXT: 80 | (B1 vftable pointer) // CHECK-NEXT: 84 | int a // CHECK-NEXT: | [sizeof=96, align=32 // CHECK-NEXT: | nvsize=12, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | (D vftable pointer) // CHECK-X64-NEXT: 8 | (D vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 36 | (vtordisp for vbase B0) // CHECK-X64-NEXT: 40 | struct B0 (virtual base) // CHECK-X64-NEXT: 40 | (B0 vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 76 | (vtordisp for vbase B1) // CHECK-X64-NEXT: 80 | struct B1 (virtual base) // CHECK-X64-NEXT: 80 | (B1 vftable pointer) // CHECK-X64-NEXT: 88 | int a // CHECK-X64-NEXT: | [sizeof=96, align=32 // CHECK-X64-NEXT: | nvsize=24, nvalign=32] struct AT { virtual ~AT(){} }; struct CT : virtual AT { virtual ~CT(); }; CT::~CT(){} // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct CT // CHECK-NEXT: 0 | (CT vbtable pointer) // CHECK-NEXT: 4 | struct AT (virtual base) // CHECK-NEXT: 4 | (AT vftable pointer) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct CT // CHECK-X64-NEXT: 0 | (CT vbtable pointer) // CHECK-X64-NEXT: 8 | struct AT (virtual base) // CHECK-X64-NEXT: 8 | (AT vftable pointer) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct XA { XA() { printf("XA"); } long long ll; }; struct XB : XA { XB() { printf("XB"); } virtual void foo() {} int b; }; struct XC : virtual XB { XC() { printf("XC"); } virtual void foo() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct XC // CHECK-NEXT: 0 | (XC vbtable pointer) // CHECK-NEXT: 4 | (vtordisp for vbase XB) // CHECK-NEXT: 8 | struct XB (virtual base) // CHECK-NEXT: 8 | (XB vftable pointer) // CHECK-NEXT: 16 | struct XA (base) // CHECK-NEXT: 16 | long long ll // CHECK-NEXT: 24 | int b // CHECK-NEXT: | [sizeof=32, align=8 // CHECK-NEXT: | nvsize=4, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct XC // CHECK-X64-NEXT: 0 | (XC vbtable pointer) // CHECK-X64-NEXT: 12 | (vtordisp for vbase XB) // CHECK-X64-NEXT: 16 | struct XB (virtual base) // CHECK-X64-NEXT: 16 | (XB vftable pointer) // CHECK-X64-NEXT: 24 | struct XA (base) // CHECK-X64-NEXT: 24 | long long ll // CHECK-X64-NEXT: 32 | int b // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] namespace pragma_test1 { // No overrides means no vtordisps by default. struct A { virtual ~A(); virtual void foo(); int a; }; struct B : virtual A { virtual ~B(); virtual void bar(); int b; }; struct C : virtual B { int c; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct pragma_test1::C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | int c // CHECK-NEXT: 8 | struct pragma_test1::A (virtual base) // CHECK-NEXT: 8 | (A vftable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct pragma_test1::B (virtual base) // CHECK-NEXT: 16 | (B vftable pointer) // CHECK-NEXT: 20 | (B vbtable pointer) // CHECK-NEXT: 24 | int b // CHECK-NEXT: | [sizeof=28, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout } namespace pragma_test2 { struct A { virtual ~A(); virtual void foo(); int a; }; #pragma vtordisp(push,2) struct B : virtual A { virtual ~B(); virtual void bar(); int b; }; struct C : virtual B { int c; }; #pragma vtordisp(pop) // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct pragma_test2::C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | int c // CHECK-NEXT: 8 | (vtordisp for vbase A) // CHECK-NEXT: 12 | struct pragma_test2::A (virtual base) // CHECK-NEXT: 12 | (A vftable pointer) // CHECK-NEXT: 16 | int a // By adding a virtual method and vftable to B, now we need a vtordisp. // CHECK-NEXT: 20 | (vtordisp for vbase B) // CHECK-NEXT: 24 | struct pragma_test2::B (virtual base) // CHECK-NEXT: 24 | (B vftable pointer) // CHECK-NEXT: 28 | (B vbtable pointer) // CHECK-NEXT: 32 | int b // CHECK-NEXT: | [sizeof=36, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout } namespace pragma_test3 { struct A { virtual ~A(); virtual void foo(); int a; }; #pragma vtordisp(push,2) struct B : virtual A { virtual ~B(); virtual void foo(); int b; }; struct C : virtual B { int c; }; #pragma vtordisp(pop) // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct pragma_test3::C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | int c // CHECK-NEXT: 8 | (vtordisp for vbase A) // CHECK-NEXT: 12 | struct pragma_test3::A (virtual base) // CHECK-NEXT: 12 | (A vftable pointer) // CHECK-NEXT: 16 | int a // No vtordisp before B! It doesn't have its own vftable. // CHECK-NEXT: 20 | struct pragma_test3::B (virtual base) // CHECK-NEXT: 20 | (B vbtable pointer) // CHECK-NEXT: 24 | int b // CHECK-NEXT: | [sizeof=28, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout } namespace pragma_test4 { struct A { A(); virtual void foo(); int a; }; // Make sure the pragma applies to class template decls before they've been // instantiated. #pragma vtordisp(push,2) template <typename T> struct B : virtual A { B(); virtual ~B(); virtual void bar(); T b; }; #pragma vtordisp(pop) struct C : virtual B<int> { int c; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct pragma_test4::C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | int c // Pragma applies to B, which has vbase A. // CHECK-NEXT: 8 | (vtordisp for vbase A) // CHECK-NEXT: 12 | struct pragma_test4::A (virtual base) // CHECK-NEXT: 12 | (A vftable pointer) // CHECK-NEXT: 16 | int a // Pragma does not apply to C, and B doesn't usually need a vtordisp in C. // CHECK-NEXT: 20 | struct pragma_test4::B<int> (virtual base) // CHECK-NEXT: 20 | (B vftable pointer) // CHECK-NEXT: 24 | (B vbtable pointer) // CHECK-NEXT: 28 | int b // CHECK-NEXT: | [sizeof=32, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout } struct GA { virtual void fun() {} }; struct GB: public GA {}; struct GC: public virtual GA { virtual void fun() {} GC() {} }; struct GD: public virtual GC, public virtual GB {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct GD // CHECK-NEXT: 0 | (GD vbtable pointer) // CHECK-NEXT: 4 | (vtordisp for vbase GA) // CHECK-NEXT: 8 | struct GA (virtual base) // CHECK-NEXT: 8 | (GA vftable pointer) // CHECK-NEXT: 12 | struct GC (virtual base) // CHECK-NEXT: 12 | (GC vbtable pointer) // CHECK-NEXT: 16 | struct GB (virtual base) // CHECK-NEXT: 16 | struct GA (primary base) // CHECK-NEXT: 16 | (GA vftable pointer) // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct GD // CHECK-X64-NEXT: 0 | (GD vbtable pointer) // CHECK-X64-NEXT: 12 | (vtordisp for vbase GA) // CHECK-X64-NEXT: 16 | struct GA (virtual base) // CHECK-X64-NEXT: 16 | (GA vftable pointer) // CHECK-X64-NEXT: 24 | struct GC (virtual base) // CHECK-X64-NEXT: 24 | (GC vbtable pointer) // CHECK-X64-NEXT: 32 | struct GB (virtual base) // CHECK-X64-NEXT: 32 | struct GA (primary base) // CHECK-X64-NEXT: 32 | (GA vftable pointer) // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct HA { virtual void fun() {} }; #pragma vtordisp(push, 2) struct HB : virtual HA {}; #pragma vtordisp(pop) #pragma vtordisp(push, 0) struct HC : virtual HB {}; #pragma vtordisp(pop) // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct HC // CHECK-NEXT: 0 | (HC vbtable pointer) // CHECK-NEXT: 4 | (vtordisp for vbase HA) // CHECK-NEXT: 8 | struct HA (virtual base) // CHECK-NEXT: 8 | (HA vftable pointer) // CHECK-NEXT: 12 | struct HB (virtual base) // CHECK-NEXT: 12 | (HB vbtable pointer) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct HC // CHECK-X64-NEXT: 0 | (HC vbtable pointer) // CHECK-X64-NEXT: 12 | (vtordisp for vbase HA) // CHECK-X64-NEXT: 16 | struct HA (virtual base) // CHECK-X64-NEXT: 16 | (HA vftable pointer) // CHECK-X64-NEXT: 24 | struct HB (virtual base) // CHECK-X64-NEXT: 24 | (HB vbtable pointer) // CHECK-X64-NEXT: | [sizeof=32, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct IA { virtual void f(); }; struct __declspec(dllexport) IB : virtual IA { virtual void f() = 0; IB() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct IB // CHECK-NEXT: 0 | (IB vbtable pointer) // CHECK-NEXT: 4 | struct IA (virtual base) // CHECK-NEXT: 4 | (IA vftable pointer) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct IB // CHECK-X64-NEXT: 0 | (IB vbtable pointer) // CHECK-X64-NEXT: 8 | struct IA (virtual base) // CHECK-X64-NEXT: 8 | (IA vftable pointer) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] int a[ sizeof(A)+ sizeof(C)+ sizeof(D)+ sizeof(CT)+ sizeof(XC)+ sizeof(pragma_test1::C)+ sizeof(pragma_test2::C)+ sizeof(pragma_test3::C)+ sizeof(pragma_test4::C)+ sizeof(GD)+ sizeof(HC)+ sizeof(IB)+ 0];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-lazy-empty-nonvirtual-base.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { B0() { printf("B0 = %p\n", this); } }; struct B1 { B1() { printf("B1 = %p\n", this); } }; struct B2 { B2() { printf("B2 = %p\n", this); } }; struct B3 { B3() { printf("B3 = %p\n", this); } }; struct B4 { B4() { printf("B4 = %p\n", this); } }; struct B5 { B5() { printf("B5 = %p\n", this); } }; struct __declspec(align(2)) B6 { B6() { printf("B6 = %p\n", this); } }; struct __declspec(align(16)) B7 { B7() { printf("B7 = %p\n", this); } }; struct B8 { char c[5]; B8() { printf("B8 = %p\n", this); } }; struct B9 { char c[6]; B9() { printf("B9 = %p\n", this); } }; struct B10 { char c[7]; B10() { printf("B10 = %p\n", this); } }; struct B11 { char c[8]; B11() { printf("B11 = %p\n", this); } }; struct B0X { B0X() { printf("B0 = %p\n", this); } }; struct B1X { B1X() { printf("B1 = %p\n", this); } }; struct __declspec(align(16)) B2X { B2X() { printf("B2 = %p\n", this); } }; struct __declspec(align(2)) B3X { B3X() { printf("B3 = %p\n", this); } }; struct B4X { B4X() { printf("B4 = %p\n", this); } }; struct B5X { B5X() { printf("B5 = %p\n", this); } }; struct B6X { B6X() { printf("B6 = %p\n", this); } }; struct B8X { short a; B8X() : a(0x000000B8) { printf("B8 = %p\n", this); } }; struct AA : B8, B1, virtual B0 { int a; AA() : a(0x000000AA) { printf("AA = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AA // CHECK-NEXT: 0 | struct B8 (base) // CHECK-NEXT: 0 | char [5] c // CHECK-NEXT: 13 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AA vbtable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AA // CHECK-X64-NEXT: 0 | struct B8 (base) // CHECK-X64-NEXT: 0 | char [5] c // CHECK-X64-NEXT: 17 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AA vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AB : B8, B1, virtual B0 { short a; AB() : a(0x000000AB) { printf("AB = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AB // CHECK-NEXT: 0 | struct B8 (base) // CHECK-NEXT: 0 | char [5] c // CHECK-NEXT: 13 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AB vbtable pointer) // CHECK-NEXT: 14 | short a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AB // CHECK-X64-NEXT: 0 | struct B8 (base) // CHECK-X64-NEXT: 0 | char [5] c // CHECK-X64-NEXT: 17 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AB vbtable pointer) // CHECK-X64-NEXT: 18 | short a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AC : B8, B1, virtual B0 { char a; AC() : a(0x000000AC) { printf("AC = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AC // CHECK-NEXT: 0 | struct B8 (base) // CHECK-NEXT: 0 | char [5] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AC vbtable pointer) // CHECK-NEXT: 12 | char a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AC // CHECK-X64-NEXT: 0 | struct B8 (base) // CHECK-X64-NEXT: 0 | char [5] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AC vbtable pointer) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AD : B8, B1, virtual B0 { AD() { printf("AD = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AD // CHECK-NEXT: 0 | struct B8 (base) // CHECK-NEXT: 0 | char [5] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AD vbtable pointer) // CHECK-NEXT: 12 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AD // CHECK-X64-NEXT: 0 | struct B8 (base) // CHECK-X64-NEXT: 0 | char [5] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AD vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct AA1 : B9, B1, virtual B0 { int a; AA1() : a(0x00000AA1) { printf("AA1 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AA1 // CHECK-NEXT: 0 | struct B9 (base) // CHECK-NEXT: 0 | char [6] c // CHECK-NEXT: 14 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AA1 vbtable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AA1 // CHECK-X64-NEXT: 0 | struct B9 (base) // CHECK-X64-NEXT: 0 | char [6] c // CHECK-X64-NEXT: 18 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AA1 vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AB1 : B9, B1, virtual B0 { short a; AB1() : a(0x00000AB1) { printf("AB1 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AB1 // CHECK-NEXT: 0 | struct B9 (base) // CHECK-NEXT: 0 | char [6] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AB1 vbtable pointer) // CHECK-NEXT: 12 | short a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AB1 // CHECK-X64-NEXT: 0 | struct B9 (base) // CHECK-X64-NEXT: 0 | char [6] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AB1 vbtable pointer) // CHECK-X64-NEXT: 16 | short a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AC1 : B9, B1, virtual B0 { char a; AC1() : a(0x000000C1) { printf("AC1 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AC1 // CHECK-NEXT: 0 | struct B9 (base) // CHECK-NEXT: 0 | char [6] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AC1 vbtable pointer) // CHECK-NEXT: 12 | char a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AC1 // CHECK-X64-NEXT: 0 | struct B9 (base) // CHECK-X64-NEXT: 0 | char [6] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AC1 vbtable pointer) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AD1 : B9, B1, virtual B0 { AD1() { printf("AD1 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AD1 // CHECK-NEXT: 0 | struct B9 (base) // CHECK-NEXT: 0 | char [6] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AD1 vbtable pointer) // CHECK-NEXT: 12 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AD1 // CHECK-X64-NEXT: 0 | struct B9 (base) // CHECK-X64-NEXT: 0 | char [6] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AD1 vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct AA2 : B10, B1, virtual B0 { int a; AA2() : a(0x00000AA2) { printf("AA2 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AA2 // CHECK-NEXT: 0 | struct B10 (base) // CHECK-NEXT: 0 | char [7] c // CHECK-NEXT: 15 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AA2 vbtable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AA2 // CHECK-X64-NEXT: 0 | struct B10 (base) // CHECK-X64-NEXT: 0 | char [7] c // CHECK-X64-NEXT: 19 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AA2 vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AB2 : B10, B1, virtual B0 { short a; AB2() : a(0x00000AB2) { printf("AB2 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AB2 // CHECK-NEXT: 0 | struct B10 (base) // CHECK-NEXT: 0 | char [7] c // CHECK-NEXT: 13 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AB2 vbtable pointer) // CHECK-NEXT: 14 | short a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AB2 // CHECK-X64-NEXT: 0 | struct B10 (base) // CHECK-X64-NEXT: 0 | char [7] c // CHECK-X64-NEXT: 17 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AB2 vbtable pointer) // CHECK-X64-NEXT: 18 | short a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AC2 : B10, B1, virtual B0 { char a; AC2() : a(0x000000C2) { printf("AC2 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AC2 // CHECK-NEXT: 0 | struct B10 (base) // CHECK-NEXT: 0 | char [7] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AC2 vbtable pointer) // CHECK-NEXT: 12 | char a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AC2 // CHECK-X64-NEXT: 0 | struct B10 (base) // CHECK-X64-NEXT: 0 | char [7] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AC2 vbtable pointer) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AD2 : B10, B1, virtual B0 { AD2() { printf("AD2 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AD2 // CHECK-NEXT: 0 | struct B10 (base) // CHECK-NEXT: 0 | char [7] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AD2 vbtable pointer) // CHECK-NEXT: 12 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AD2 // CHECK-X64-NEXT: 0 | struct B10 (base) // CHECK-X64-NEXT: 0 | char [7] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AD2 vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct AA3 : B11, B1, virtual B0 { int a; AA3() : a(0x00000AA3) { printf("AA3 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AA3 // CHECK-NEXT: 0 | struct B11 (base) // CHECK-NEXT: 0 | char [8] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AA3 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AA3 // CHECK-X64-NEXT: 0 | struct B11 (base) // CHECK-X64-NEXT: 0 | char [8] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AA3 vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AB3 : B11, B1, virtual B0 { short a; AB3() : a(0x00000AB3) { printf("AB3 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AB3 // CHECK-NEXT: 0 | struct B11 (base) // CHECK-NEXT: 0 | char [8] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AB3 vbtable pointer) // CHECK-NEXT: 12 | short a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AB3 // CHECK-X64-NEXT: 0 | struct B11 (base) // CHECK-X64-NEXT: 0 | char [8] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AB3 vbtable pointer) // CHECK-X64-NEXT: 16 | short a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AC3 : B11, B1, virtual B0 { char a; AC3() : a(0x000000C3) { printf("AC3 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AC3 // CHECK-NEXT: 0 | struct B11 (base) // CHECK-NEXT: 0 | char [8] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AC3 vbtable pointer) // CHECK-NEXT: 12 | char a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AC3 // CHECK-X64-NEXT: 0 | struct B11 (base) // CHECK-X64-NEXT: 0 | char [8] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AC3 vbtable pointer) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct AD3 : B11, B1, virtual B0 { AD3() { printf("AD3 = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AD3 // CHECK-NEXT: 0 | struct B11 (base) // CHECK-NEXT: 0 | char [8] c // CHECK-NEXT: 12 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (AD3 vbtable pointer) // CHECK-NEXT: 12 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AD3 // CHECK-X64-NEXT: 0 | struct B11 (base) // CHECK-X64-NEXT: 0 | char [8] c // CHECK-X64-NEXT: 16 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (AD3 vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct B : B1, B2, virtual B0 { B() { printf("B = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | struct B1 (base) (empty) // CHECK-NEXT: 8 | struct B2 (base) (empty) // CHECK-NEXT: 4 | (B vbtable pointer) // CHECK-NEXT: 8 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | struct B1 (base) (empty) // CHECK-X64-NEXT: 16 | struct B2 (base) (empty) // CHECK-X64-NEXT: 8 | (B vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct C : B1, B2, B3, virtual B0 { char a; C() : a(0x0000000C) { printf("C = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | struct B1 (base) (empty) // CHECK-NEXT: 1 | struct B2 (base) (empty) // CHECK-NEXT: 8 | struct B3 (base) (empty) // CHECK-NEXT: 4 | (C vbtable pointer) // CHECK-NEXT: 8 | char a // CHECK-NEXT: 12 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | struct B1 (base) (empty) // CHECK-X64-NEXT: 1 | struct B2 (base) (empty) // CHECK-X64-NEXT: 16 | struct B3 (base) (empty) // CHECK-X64-NEXT: 8 | (C vbtable pointer) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct D : B1, B2, B3, B4, B5, virtual B0 { int a; D() : a(0x0000000D) { printf("D = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct B1 (base) (empty) // CHECK-NEXT: 1 | struct B2 (base) (empty) // CHECK-NEXT: 2 | struct B3 (base) (empty) // CHECK-NEXT: 3 | struct B4 (base) (empty) // CHECK-NEXT: 8 | struct B5 (base) (empty) // CHECK-NEXT: 4 | (D vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | struct B1 (base) (empty) // CHECK-X64-NEXT: 1 | struct B2 (base) (empty) // CHECK-X64-NEXT: 2 | struct B3 (base) (empty) // CHECK-X64-NEXT: 3 | struct B4 (base) (empty) // CHECK-X64-NEXT: 16 | struct B5 (base) (empty) // CHECK-X64-NEXT: 8 | (D vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct E : B1, B6, B3, B4, B5, virtual B0 { int a; E() : a(0x0000000E) { printf("E = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | struct B1 (base) (empty) // CHECK-NEXT: 2 | struct B6 (base) (empty) // CHECK-NEXT: 3 | struct B3 (base) (empty) // CHECK-NEXT: 4 | struct B4 (base) (empty) // CHECK-NEXT: 13 | struct B5 (base) (empty) // CHECK-NEXT: 8 | (E vbtable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | struct B1 (base) (empty) // CHECK-X64-NEXT: 2 | struct B6 (base) (empty) // CHECK-X64-NEXT: 3 | struct B3 (base) (empty) // CHECK-X64-NEXT: 4 | struct B4 (base) (empty) // CHECK-X64-NEXT: 17 | struct B5 (base) (empty) // CHECK-X64-NEXT: 8 | (E vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct F : B1, B6, B4, B8, B5, virtual B0 { int a; F() : a(0x0000000F) { printf("&a = %p\n", &a); printf("F = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | struct B1 (base) (empty) // CHECK-NEXT: 2 | struct B6 (base) (empty) // CHECK-NEXT: 3 | struct B4 (base) (empty) // CHECK-NEXT: 3 | struct B8 (base) // CHECK-NEXT: 3 | char [5] c // CHECK-NEXT: 12 | struct B5 (base) (empty) // CHECK-NEXT: 8 | (F vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | struct B1 (base) (empty) // CHECK-X64-NEXT: 2 | struct B6 (base) (empty) // CHECK-X64-NEXT: 3 | struct B4 (base) (empty) // CHECK-X64-NEXT: 3 | struct B8 (base) // CHECK-X64-NEXT: 3 | char [5] c // CHECK-X64-NEXT: 16 | struct B5 (base) (empty) // CHECK-X64-NEXT: 8 | (F vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct G : B8, B1, virtual B0 { int a; __declspec(align(16)) int a1; G() : a(0x00000010), a1(0xf0000010) { printf("G = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct G // CHECK-NEXT: 0 | struct B8 (base) // CHECK-NEXT: 0 | char [5] c // CHECK-NEXT: 21 | struct B1 (base) (empty) // CHECK-NEXT: 8 | (G vbtable pointer) // CHECK-NEXT: 24 | int a // CHECK-NEXT: 32 | int a1 // CHECK-NEXT: 48 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct G // CHECK-X64-NEXT: 0 | struct B8 (base) // CHECK-X64-NEXT: 0 | char [5] c // CHECK-X64-NEXT: 21 | struct B1 (base) (empty) // CHECK-X64-NEXT: 8 | (G vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a1 // CHECK-X64-NEXT: 48 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=48, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct AX : B1X, B2X, B3X, B4X, virtual B0X { int a; AX() : a(0x0000000A) { printf(" A = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AX // CHECK-NEXT: 0 | struct B1X (base) (empty) // CHECK-NEXT: 16 | struct B2X (base) (empty) // CHECK-NEXT: 18 | struct B3X (base) (empty) // CHECK-NEXT: 35 | struct B4X (base) (empty) // CHECK-NEXT: 20 | (AX vbtable pointer) // CHECK-NEXT: 36 | int a // CHECK-NEXT: 48 | struct B0X (virtual base) (empty) // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AX // CHECK-X64-NEXT: 0 | struct B1X (base) (empty) // CHECK-X64-NEXT: 16 | struct B2X (base) (empty) // CHECK-X64-NEXT: 18 | struct B3X (base) (empty) // CHECK-X64-NEXT: 35 | struct B4X (base) (empty) // CHECK-X64-NEXT: 24 | (AX vbtable pointer) // CHECK-X64-NEXT: 36 | int a // CHECK-X64-NEXT: 48 | struct B0X (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=48, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct BX : B2X, B1X, B3X, B4X, virtual B0X { int a; BX() : a(0x0000000B) { printf(" B = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct BX // CHECK-NEXT: 0 | struct B2X (base) (empty) // CHECK-NEXT: 1 | struct B1X (base) (empty) // CHECK-NEXT: 2 | struct B3X (base) (empty) // CHECK-NEXT: 19 | struct B4X (base) (empty) // CHECK-NEXT: 4 | (BX vbtable pointer) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 32 | struct B0X (virtual base) (empty) // CHECK-NEXT: | [sizeof=32, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct BX // CHECK-X64-NEXT: 0 | struct B2X (base) (empty) // CHECK-X64-NEXT: 1 | struct B1X (base) (empty) // CHECK-X64-NEXT: 2 | struct B3X (base) (empty) // CHECK-X64-NEXT: 19 | struct B4X (base) (empty) // CHECK-X64-NEXT: 8 | (BX vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 32 | struct B0X (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=32, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct CX : B1X, B3X, B2X, virtual B0X { int a; CX() : a(0x0000000C) { printf(" C = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct CX // CHECK-NEXT: 0 | struct B1X (base) (empty) // CHECK-NEXT: 2 | struct B3X (base) (empty) // CHECK-NEXT: 32 | struct B2X (base) (empty) // CHECK-NEXT: 16 | (CX vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 48 | struct B0X (virtual base) (empty) // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct CX // CHECK-X64-NEXT: 0 | struct B1X (base) (empty) // CHECK-X64-NEXT: 2 | struct B3X (base) (empty) // CHECK-X64-NEXT: 32 | struct B2X (base) (empty) // CHECK-X64-NEXT: 16 | (CX vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | struct B0X (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=48, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct DX : B8X, B1X, virtual B0X { int a; DX() : a(0x0000000D) { printf(" D = %p\n", this); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct DX // CHECK-NEXT: 0 | struct B8X (base) // CHECK-NEXT: 0 | short a // CHECK-NEXT: 10 | struct B1X (base) (empty) // CHECK-NEXT: 4 | (DX vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct B0X (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct DX // CHECK-X64-NEXT: 0 | struct B8X (base) // CHECK-X64-NEXT: 0 | short a // CHECK-X64-NEXT: 18 | struct B1X (base) (empty) // CHECK-X64-NEXT: 8 | (DX vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | struct B0X (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct C0 {}; struct C1 : public C0 { int C1F0; }; struct C2 : public C1, public C0 {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C2 // CHECK-NEXT: 0 | struct C1 (base) // CHECK-NEXT: 0 | struct C0 (base) (empty) // CHECK-NEXT: 0 | int C1F0 // CHECK-NEXT: 5 | struct C0 (base) (empty) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C2 // CHECK-X64-NEXT: 0 | struct C1 (base) // CHECK-X64-NEXT: 0 | struct C0 (base) (empty) // CHECK-X64-NEXT: 0 | int C1F0 // CHECK-X64-NEXT: 5 | struct C0 (base) (empty) // CHECK-X64-NEXT: | [sizeof=8, align=4 // CHECK-X64-NEXT: | nvsize=8, nvalign=4] struct JA { char a; }; struct JB { char a; virtual void f() {} }; struct JC { char a; }; struct JD : JA, JB, virtual JC {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct JD // CHECK-NEXT: 0 | struct JB (primary base) // CHECK-NEXT: 0 | (JB vftable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 12 | struct JA (base) // CHECK-NEXT: 12 | char a // CHECK-NEXT: 8 | (JD vbtable pointer) // CHECK-NEXT: 16 | struct JC (virtual base) // CHECK-NEXT: 16 | char a // CHECK-NEXT: | [sizeof=17, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct JD // CHECK-X64-NEXT: 0 | struct JB (primary base) // CHECK-X64-NEXT: 0 | (JB vftable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 24 | struct JA (base) // CHECK-X64-NEXT: 24 | char a // CHECK-X64-NEXT: 16 | (JD vbtable pointer) // CHECK-X64-NEXT: 32 | struct JC (virtual base) // CHECK-X64-NEXT: 32 | char a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=32, nvalign=8] int a[ sizeof(AA)+ sizeof(AB)+ sizeof(AC)+ sizeof(AD)+ sizeof(AA1)+ sizeof(AB1)+ sizeof(AC1)+ sizeof(AD1)+ sizeof(AA2)+ sizeof(AB2)+ sizeof(AC2)+ sizeof(AD2)+ sizeof(AA3)+ sizeof(AB3)+ sizeof(AC3)+ sizeof(AD3)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(G)+ sizeof(AX)+ sizeof(BX)+ sizeof(CX)+ sizeof(DX)+ sizeof(C2)+ sizeof(JD)+ 0];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-empty-layout.c
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s struct EmptyIntMemb { int FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK: Type: struct EmptyIntMemb // CHECK: Record: // CHECK: Layout: <ASTRecordLayout // CHECK: Size:32 // CHECK: Alignment:32 // CHECK: FieldOffsets: [0]> struct EmptyLongLongMemb { long long FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK: Type: struct EmptyLongLongMemb // CHECK: Record: // CHECK: Layout: <ASTRecordLayout // CHECK: Size:32 // CHECK: Alignment:64 // CHECK: FieldOffsets: [0]> struct EmptyAligned2LongLongMemb { long long __declspec(align(2)) FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK: Type: struct EmptyAligned2LongLongMemb // CHECK: Record: // CHECK: Layout: <ASTRecordLayout // CHECK: Size:32 // CHECK: Alignment:64 // CHECK: FieldOffsets: [0]> struct EmptyAligned8LongLongMemb { long long __declspec(align(8)) FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK: Type: struct EmptyAligned8LongLongMemb // CHECK: Record: // CHECK: Layout: <ASTRecordLayout // CHECK: Size:64 // CHECK: Alignment:64 // CHECK: FieldOffsets: [0]> #pragma pack(1) struct __declspec(align(4)) EmptyPackedAligned4LongLongMemb { long long FlexArrayMemb[0]; }; #pragma pack() // CHECK: *** Dumping AST Record Layout // CHECK: Type: struct EmptyPackedAligned4LongLongMemb // CHECK: Record: // CHECK: Layout: <ASTRecordLayout // CHECK: Size:32 // CHECK: Alignment:32 // CHECK: FieldOffsets: [0]> #pragma pack(1) struct EmptyPackedAligned8LongLongMemb { long long __declspec(align(8)) FlexArrayMemb[0]; }; #pragma pack() // CHECK: *** Dumping AST Record Layout // CHECK: Type: struct EmptyPackedAligned8LongLongMemb // CHECK: Record: // CHECK: Layout: <ASTRecordLayout // CHECK: Size:64 // CHECK: Alignment:64 // CHECK: FieldOffsets: [0]> int a[ sizeof(struct EmptyIntMemb)+ sizeof(struct EmptyLongLongMemb)+ sizeof(struct EmptyAligned2LongLongMemb)+ sizeof(struct EmptyAligned8LongLongMemb)+ sizeof(struct EmptyPackedAligned4LongLongMemb)+ sizeof(struct EmptyPackedAligned8LongLongMemb)+ 0];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-pack-and-align.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only -Wno-inaccessible-base %s 2>&1 \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only -Wno-inaccessible-base %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); char buffer[419430400]; struct A { char a; A() { printf("A = %d\n", (int)((char*)this - buffer)); printf("A.a = %d\n", (int)((char*)&a - buffer)); } }; struct B { __declspec(align(4)) long long a; B() { printf("B = %d\n", (int)((char*)this - buffer)); printf("B.a = %d\n", (int)((char*)&a - buffer)); } }; #pragma pack(push, 2) struct X { B a; char b; int c; X() { printf("X = %d\n", (int)((char*)this - buffer)); printf("X.a = %d\n", (int)((char*)&a - buffer)); printf("X.b = %d\n", (int)((char*)&b - buffer)); printf("X.c = %d\n", (int)((char*)&c - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct X // CHECK-NEXT: 0 | struct B a // CHECK-NEXT: 0 | long long a // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] // CHECK-NEXT: 8 | char b // CHECK-NEXT: 10 | int c // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=14, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct X // CHECK-X64-NEXT: 0 | struct B a // CHECK-X64-NEXT: 0 | long long a // CHECK-X64-NEXT: | [sizeof=8, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] // CHECK-X64-NEXT: 8 | char b // CHECK-X64-NEXT: 10 | int c // CHECK-X64-NEXT: | [sizeof=16, align=4 // CHECK-X64-NEXT: | nvsize=14, nvalign=4] struct Y : A, B { char a; int b; Y() { printf("Y = %d\n", (int)((char*)this - buffer)); printf("Y.a = %d\n", (int)((char*)&a - buffer)); printf("Y.b = %d\n", (int)((char*)&b - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct Y // CHECK-NEXT: 0 | struct A (base) // CHECK-NEXT: 0 | char a // CHECK-NEXT: 4 | struct B (base) // CHECK-NEXT: 4 | long long a // CHECK-NEXT: 12 | char a // CHECK-NEXT: 14 | int b // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=18, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct Y // CHECK-X64-NEXT: 0 | struct A (base) // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 4 | struct B (base) // CHECK-X64-NEXT: 4 | long long a // CHECK-X64-NEXT: 12 | char a // CHECK-X64-NEXT: 14 | int b // CHECK-X64-NEXT: | [sizeof=20, align=4 // CHECK-X64-NEXT: | nvsize=18, nvalign=4] struct Z : virtual B { char a; int b; Z() { printf("Z = %d\n", (int)((char*)this - buffer)); printf("Z.a = %d\n", (int)((char*)&a - buffer)); printf("Z.b = %d\n", (int)((char*)&b - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct Z // CHECK-NEXT: 0 | (Z vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 6 | int b // CHECK-NEXT: 12 | struct B (virtual base) // CHECK-NEXT: 12 | long long a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=10, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct Z // CHECK-X64-NEXT: 0 | (Z vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 10 | int b // CHECK-X64-NEXT: 16 | struct B (virtual base) // CHECK-X64-NEXT: 16 | long long a // CHECK-X64-NEXT: | [sizeof=24, align=4 // CHECK-X64-NEXT: | nvsize=14, nvalign=4] #pragma pack(pop) struct A1 { long long a; }; #pragma pack(push, 1) struct B1 : virtual A1 { char a; }; #pragma pack(pop) struct C1 : B1 {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C1 // CHECK-NEXT: 0 | struct B1 (base) // CHECK-NEXT: 0 | (B1 vbtable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 8 | struct A1 (virtual base) // CHECK-NEXT: 8 | long long a // CHECK-NEXT: | [sizeof=16, align=8 // CHECK-NEXT: | nvsize=5, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C1 // CHECK-X64-NEXT: 0 | struct B1 (base) // CHECK-X64-NEXT: 0 | (B1 vbtable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 16 | struct A1 (virtual base) // CHECK-X64-NEXT: 16 | long long a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=9, nvalign=8] struct CA0 { CA0() {} }; struct CA1 : virtual CA0 { CA1() {} }; #pragma pack(push, 1) struct CA2 : public CA1, public CA0 { virtual void CA2Method() {} CA2() {} }; #pragma pack(pop) // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct CA2 // CHECK-NEXT: 0 | (CA2 vftable pointer) // CHECK-NEXT: 4 | struct CA1 (base) // CHECK-NEXT: 4 | (CA1 vbtable pointer) // CHECK-NEXT: 9 | struct CA0 (base) (empty) // CHECK-NEXT: 9 | struct CA0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=9, align=1 // CHECK-NEXT: | nvsize=9, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct CA2 // CHECK-X64-NEXT: 0 | (CA2 vftable pointer) // CHECK-X64-NEXT: 8 | struct CA1 (base) // CHECK-X64-NEXT: 8 | (CA1 vbtable pointer) // CHECK-X64-NEXT: 17 | struct CA0 (base) (empty) // CHECK-X64-NEXT: 17 | struct CA0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=17, align=1 // CHECK-X64-NEXT: | nvsize=17, nvalign=1] #pragma pack(16) struct YA { __declspec(align(32)) char : 1; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct YA (empty) // CHECK-NEXT: 0 | char // CHECK-NEXT: | [sizeof=32, align=32 // CHECK-NEXT: | nvsize=32, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct YA (empty) // CHECK-X64-NEXT: 0 | char // CHECK-X64-NEXT: | [sizeof=32, align=32 // CHECK-X64-NEXT: | nvsize=32, nvalign=32] #pragma pack(1) struct YB { char a; YA b; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct YB // CHECK-NEXT: 0 | char a // CHECK-NEXT: 1 | struct YA b (empty) // CHECK-NEXT: 1 | char // CHECK-NEXT: | [sizeof=32, align=32 // CHECK-NEXT: | nvsize=32, nvalign=32] // CHECK-NEXT: | [sizeof=33, align=1 // CHECK-NEXT: | nvsize=33, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct YB // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 1 | struct YA b (empty) // CHECK-X64-NEXT: 1 | char // CHECK-X64-NEXT: | [sizeof=32, align=32 // CHECK-X64-NEXT: | nvsize=32, nvalign=32] // CHECK-X64-NEXT: | [sizeof=33, align=1 // CHECK-X64-NEXT: | nvsize=33, nvalign=1] #pragma pack(8) struct YC { __declspec(align(32)) char : 1; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct YC (empty) // CHECK-NEXT: 0 | char // CHECK-NEXT: | [sizeof=32, align=32 // CHECK-NEXT: | nvsize=32, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct YC (empty) // CHECK-X64-NEXT: 0 | char // CHECK-X64-NEXT: | [sizeof=8, align=32 // CHECK-X64-NEXT: | nvsize=8, nvalign=32] #pragma pack(1) struct YD { char a; YC b; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct YD // CHECK-NEXT: 0 | char a // CHECK-NEXT: 1 | struct YC b (empty) // CHECK-NEXT: 1 | char // CHECK-NEXT: | [sizeof=32, align=32 // CHECK-NEXT: | nvsize=32, nvalign=32] // CHECK-NEXT: | [sizeof=33, align=1 // CHECK-NEXT: | nvsize=33, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct YD // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 1 | struct YC b (empty) // CHECK-X64-NEXT: 1 | char // CHECK-X64-NEXT: | [sizeof=8, align=32 // CHECK-X64-NEXT: | nvsize=8, nvalign=32] // CHECK-X64-NEXT: | [sizeof=9, align=1 // CHECK-X64-NEXT: | nvsize=9, nvalign=1] #pragma pack(4) struct YE { __declspec(align(32)) char : 1; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct YE (empty) // CHECK-NEXT: 0 | char // CHECK-NEXT: | [sizeof=4, align=32 // CHECK-NEXT: | nvsize=4, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct YE (empty) // CHECK-X64-NEXT: 0 | char // CHECK-X64-NEXT: | [sizeof=4, align=32 // CHECK-X64-NEXT: | nvsize=4, nvalign=32] #pragma pack(1) struct YF { char a; YE b; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct YF // CHECK-NEXT: 0 | char a // CHECK-NEXT: 1 | struct YE b (empty) // CHECK-NEXT: 1 | char // CHECK-NEXT: | [sizeof=4, align=32 // CHECK-NEXT: | nvsize=4, nvalign=32] // CHECK-NEXT: | [sizeof=5, align=1 // CHECK-NEXT: | nvsize=5, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct YF // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 1 | struct YE b (empty) // CHECK-X64-NEXT: 1 | char // CHECK-X64-NEXT: | [sizeof=4, align=32 // CHECK-X64-NEXT: | nvsize=4, nvalign=32] // CHECK-X64-NEXT: | [sizeof=5, align=1 // CHECK-X64-NEXT: | nvsize=5, nvalign=1] #pragma pack(16) struct __declspec(align(16)) D0 { char a; }; #pragma pack(1) struct D1 : public D0 { char a; }; #pragma pack(16) struct D2 : D1 { char a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D2 // CHECK-NEXT: 0 | struct D1 (base) // CHECK-NEXT: 0 | struct D0 (base) // CHECK-NEXT: 0 | char a // CHECK-NEXT: 1 | char a // CHECK-NEXT: 2 | char a // CHECK-NEXT: | [sizeof=16, align=16 // CHECK-NEXT: | nvsize=16, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D2 // CHECK-X64-NEXT: 0 | struct D1 (base) // CHECK-X64-NEXT: 0 | struct D0 (base) // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 1 | char a // CHECK-X64-NEXT: 2 | char a // CHECK-X64-NEXT: | [sizeof=16, align=16 // CHECK-X64-NEXT: | nvsize=16, nvalign=16] #pragma pack() struct JA { char a; }; #pragma pack(1) struct JB { __declspec(align(4)) char a; }; #pragma pack() struct JC : JB, JA { }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct JC // CHECK-NEXT: 0 | struct JB (base) // CHECK-NEXT: 0 | char a // CHECK-NEXT: 1 | struct JA (base) // CHECK-NEXT: 1 | char a // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct JC // CHECK-X64-NEXT: 0 | struct JB (base) // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 1 | struct JA (base) // CHECK-X64-NEXT: 1 | char a // CHECK-X64-NEXT: | [sizeof=4, align=4 // CHECK-X64-NEXT: | nvsize=4, nvalign=4] #pragma pack() struct KA { char a; }; #pragma pack(1) struct KB : KA { __declspec(align(2)) char a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct KB // CHECK-NEXT: 0 | struct KA (base) // CHECK-NEXT: 0 | char a // CHECK-NEXT: 2 | char a // CHECK-NEXT: | [sizeof=4, align=2 // CHECK-NEXT: | nvsize=3, nvalign=2] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct KB // CHECK-X64-NEXT: 0 | struct KA (base) // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 2 | char a // CHECK-X64-NEXT: | [sizeof=4, align=2 // CHECK-X64-NEXT: | nvsize=3, nvalign=2] #pragma pack(1) struct L { virtual void fun() {} __declspec(align(256)) int Field; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct L // CHECK-NEXT: 0 | (L vftable pointer) // CHECK-NEXT: 256 | int Field // CHECK-NEXT: | [sizeof=512, align=256 // CHECK-NEXT: | nvsize=260, nvalign=256] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct L // CHECK-X64-NEXT: 0 | (L vftable pointer) // CHECK-X64-NEXT: 256 | int Field // CHECK-X64-NEXT: | [sizeof=512, align=256 // CHECK-X64-NEXT: | nvsize=260, nvalign=256] #pragma pack() struct MA {}; #pragma pack(1) struct MB : virtual MA { __declspec(align(256)) int Field; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct MB // CHECK-NEXT: 0 | (MB vbtable pointer) // CHECK-NEXT: 256 | int Field // CHECK-NEXT: 260 | struct MA (virtual base) (empty) // CHECK-NEXT: | [sizeof=512, align=256 // CHECK-NEXT: | nvsize=260, nvalign=256] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct MB // CHECK-X64-NEXT: 0 | (MB vbtable pointer) // CHECK-X64-NEXT: 256 | int Field // CHECK-X64-NEXT: 260 | struct MA (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=512, align=256 // CHECK-X64-NEXT: | nvsize=260, nvalign=256] struct RA {}; #pragma pack(1) struct __declspec(align(8)) RB0 { __declspec(align(1024)) int b : 3; }; struct __declspec(align(8)) RB1 { __declspec(align(1024)) int b : 3; virtual void f() {} }; struct __declspec(align(8)) RB2 : virtual RA { __declspec(align(1024)) int b : 3; }; struct __declspec(align(8)) RB3 : virtual RA { __declspec(align(1024)) int b : 3; virtual void f() {} }; struct RC { char _; __declspec(align(1024)) int c : 3; }; struct RE { char _; RC c; }; #pragma pack() // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RB0 // CHECK-NEXT: 0 | int b // CHECK-NEXT: | [sizeof=8, align=1024 // CHECK-NEXT: | nvsize=4, nvalign=1024] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RB1 // CHECK-NEXT: 0 | (RB1 vftable pointer) // CHECK-NEXT: 1024 | int b // CHECK-NEXT: | [sizeof=1032, align=1024 // CHECK-NEXT: | nvsize=1028, nvalign=1024] // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RB2 // CHECK-NEXT: 0 | (RB2 vbtable pointer) // CHECK-NEXT: 1024 | int b // CHECK-NEXT: 1028 | struct RA (virtual base) (empty) // CHECK-NEXT: | [sizeof=1032, align=1024 // CHECK-NEXT: | nvsize=1028, nvalign=1024] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RB3 // CHECK-NEXT: 0 | (RB3 vftable pointer) // CHECK-NEXT: 1024 | (RB3 vbtable pointer) // CHECK-NEXT: 2048 | int b // CHECK-NEXT: 2052 | struct RA (virtual base) (empty) // CHECK-NEXT: | [sizeof=2056, align=1024 // CHECK-NEXT: | nvsize=2052, nvalign=1024] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RC // CHECK-NEXT: 0 | char _ // CHECK-NEXT: 1024 | int c // CHECK-NEXT: | [sizeof=1028, align=1024 // CHECK-NEXT: | nvsize=1028, nvalign=1024] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RE // CHECK-NEXT: 0 | char _ // CHECK-NEXT: 1 | struct RC c // CHECK-NEXT: 1 | char _ // CHECK-NEXT: 1025 | int c // CHECK-NEXT: | [sizeof=1028, align=1024 // CHECK-NEXT: | nvsize=1028, nvalign=1024] // CHECK-NEXT: | [sizeof=1029, align=1 // CHECK-NEXT: | nvsize=1029, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RB0 // CHECK-X64-NEXT: 0 | int b // CHECK-X64-NEXT: | [sizeof=8, align=1024 // CHECK-X64-NEXT: | nvsize=4, nvalign=1024] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RB1 // CHECK-X64-NEXT: 0 | (RB1 vftable pointer) // CHECK-X64-NEXT: 1024 | int b // CHECK-X64-NEXT: | [sizeof=1032, align=1024 // CHECK-X64-NEXT: | nvsize=1028, nvalign=1024] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RB2 // CHECK-X64-NEXT: 0 | (RB2 vbtable pointer) // CHECK-X64-NEXT: 1024 | int b // CHECK-X64-NEXT: 1028 | struct RA (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=1032, align=1024 // CHECK-X64-NEXT: | nvsize=1028, nvalign=1024] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RB3 // CHECK-X64-NEXT: 0 | (RB3 vftable pointer) // CHECK-X64-NEXT: 1024 | (RB3 vbtable pointer) // CHECK-X64-NEXT: 2048 | int b // CHECK-X64-NEXT: 2052 | struct RA (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=2056, align=1024 // CHECK-X64-NEXT: | nvsize=2052, nvalign=1024] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RC // CHECK-X64-NEXT: 0 | char _ // CHECK-X64-NEXT: 1024 | int c // CHECK-X64-NEXT: | [sizeof=1028, align=1024 // CHECK-X64-NEXT: | nvsize=1028, nvalign=1024] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RE // CHECK-X64-NEXT: 0 | char _ // CHECK-X64-NEXT: 1 | struct RC c // CHECK-X64-NEXT: 1 | char _ // CHECK-X64-NEXT: 1025 | int c // CHECK-X64-NEXT: | [sizeof=1028, align=1024 // CHECK-X64-NEXT: | nvsize=1028, nvalign=1024] // CHECK-X64-NEXT: | [sizeof=1029, align=1 // CHECK-X64-NEXT: | nvsize=1029, nvalign=1] struct NA {}; struct NB {}; #pragma pack(push, 1) struct NC : virtual NA, virtual NB {}; #pragma pack(pop) struct ND : NC {}; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct NA (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct NB (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct NC // CHECK-NEXT: 0 | (NC vbtable pointer) // CHECK-NEXT: 4 | struct NA (virtual base) (empty) // CHECK-NEXT: 8 | struct NB (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=1 // CHECK-NEXT: | nvsize=4, nvalign=1] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct ND // CHECK-NEXT: 0 | struct NC (base) // CHECK-NEXT: 0 | (NC vbtable pointer) // CHECK-NEXT: 4 | struct NA (virtual base) (empty) // CHECK-NEXT: 8 | struct NB (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct NA (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct NB (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct NC // CHECK-X64-NEXT: 0 | (NC vbtable pointer) // CHECK-X64-NEXT: 8 | struct NA (virtual base) (empty) // CHECK-X64-NEXT: 12 | struct NB (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=12, align=1 // CHECK-X64-NEXT: | nvsize=8, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct ND // CHECK-X64-NEXT: 0 | struct NC (base) // CHECK-X64-NEXT: 0 | (NC vbtable pointer) // CHECK-X64-NEXT: 8 | struct NA (virtual base) (empty) // CHECK-X64-NEXT: 12 | struct NB (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=12, align=4 // CHECK-X64-NEXT: | nvsize=8, nvalign=4] struct OA {}; struct OB {}; struct OC : virtual OA, virtual OB {}; #pragma pack(push, 1) struct OD : OC {}; #pragma pack(pop) // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct OA (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct OB (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct OC // CHECK-NEXT: 0 | (OC vbtable pointer) // CHECK-NEXT: 4 | struct OA (virtual base) (empty) // CHECK-NEXT: 8 | struct OB (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct OD // CHECK-NEXT: 0 | struct OC (base) // CHECK-NEXT: 0 | (OC vbtable pointer) // CHECK-NEXT: 4 | struct OA (virtual base) (empty) // CHECK-NEXT: 8 | struct OB (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=1 // CHECK-NEXT: | nvsize=4, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct OA (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct OB (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct OC // CHECK-X64-NEXT: 0 | (OC vbtable pointer) // CHECK-X64-NEXT: 8 | struct OA (virtual base) (empty) // CHECK-X64-NEXT: 12 | struct OB (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct OD // CHECK-X64-NEXT: 0 | struct OC (base) // CHECK-X64-NEXT: 0 | (OC vbtable pointer) // CHECK-X64-NEXT: 8 | struct OA (virtual base) (empty) // CHECK-X64-NEXT: 12 | struct OB (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=12, align=1 // CHECK-X64-NEXT: | nvsize=8, nvalign=1] struct __declspec(align(4)) PA { int c; }; typedef __declspec(align(8)) PA PB; #pragma pack(push, 1) struct PC { char a; PB x; }; #pragma pack(pop) // CHECK: *** Dumping AST Record Layout // CHECK: 0 | struct PC // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | struct PA x // CHECK-NEXT: 8 | int c // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-NEXT: | [sizeof=16, align=8 // CHECK-NEXT: | nvsize=12, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: 0 | struct PC // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 8 | struct PA x // CHECK-X64-NEXT: 8 | int c // CHECK-X64-NEXT: | [sizeof=4, align=4 // CHECK-X64-NEXT: | nvsize=4, nvalign=4] // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=12, nvalign=8] typedef PB PD; #pragma pack(push, 1) struct PE { char a; PD x; }; #pragma pack(pop) // CHECK: *** Dumping AST Record Layout // CHECK: 0 | struct PE // CHECK-NEXT: 0 | char a // CHECK-NEXT: 8 | struct PA x // CHECK-NEXT: 8 | int c // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-NEXT: | [sizeof=16, align=8 // CHECK-NEXT: | nvsize=12, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: 0 | struct PE // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 8 | struct PA x // CHECK-X64-NEXT: 8 | int c // CHECK-X64-NEXT: | [sizeof=4, align=4 // CHECK-X64-NEXT: | nvsize=4, nvalign=4] // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=12, nvalign=8] typedef int __declspec(align(2)) QA; #pragma pack(push, 1) struct QB { char a; QA b; }; #pragma pack(pop) // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct QB // CHECK-NEXT: 0 | char a // CHECK-NEXT: 2 | QA b // CHECK-NEXT: | [sizeof=6, align=2 // CHECK-NEXT: | nvsize=6, nvalign=2] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct QB // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 2 | QA b // CHECK-X64-NEXT: | [sizeof=6, align=2 // CHECK-X64-NEXT: | nvsize=6, nvalign=2] struct QC { char a; QA b; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct QC // CHECK-NEXT: 0 | char a // CHECK-NEXT: 4 | QA b // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct QC // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 4 | QA b // CHECK-X64-NEXT: | [sizeof=8, align=4 // CHECK-X64-NEXT: | nvsize=8, nvalign=4] struct QD { char a; QA b : 3; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct QD // CHECK-NEXT: 0 | char a // CHECK-NEXT: 4 | QA b // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct QD // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 4 | QA b // CHECK-X64-NEXT: | [sizeof=8, align=4 // CHECK-X64-NEXT: | nvsize=8, nvalign=4] struct __declspec(align(4)) EmptyAlignedLongLongMemb { long long FlexArrayMemb[0]; }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct EmptyAlignedLongLongMemb // CHECK-NEXT: 0 | long long [0] FlexArrayMemb // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=0, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct EmptyAlignedLongLongMemb // CHECK-X64-NEXT: 0 | long long [0] FlexArrayMemb // CHECK-X64-NEXT: | [sizeof=8, align=8 // CHECK-X64-NEXT: | nvsize=0, nvalign=8] #pragma pack(1) struct __declspec(align(4)) EmptyPackedAlignedLongLongMemb { long long FlexArrayMemb[0]; }; #pragma pack() // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct EmptyPackedAlignedLongLongMemb // CHECK-NEXT: 0 | long long [0] FlexArrayMemb // CHECK-NEXT: | [sizeof=4, align=4 // CHECK-NEXT: | nvsize=0, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct EmptyPackedAlignedLongLongMemb // CHECK-X64-NEXT: 0 | long long [0] FlexArrayMemb // CHECK-X64-NEXT: | [sizeof=4, align=4 // CHECK-X64-NEXT: | nvsize=0, nvalign=4] int a[ sizeof(X)+ sizeof(Y)+ sizeof(Z)+ sizeof(C1)+ sizeof(CA2)+ sizeof(YA)+ sizeof(YB)+ sizeof(YC)+ sizeof(YD)+ sizeof(YE)+ sizeof(YF)+ sizeof(YF)+ sizeof(D2)+ sizeof(JC)+ sizeof(KB)+ sizeof(L)+ sizeof(MB)+ sizeof(RB0)+ sizeof(RB1)+ sizeof(RB2)+ sizeof(RB3)+ sizeof(RC)+ sizeof(RE)+ sizeof(ND)+ sizeof(OD)+ sizeof(PC)+ sizeof(PE)+ sizeof(QB)+ sizeof(QC)+ sizeof(QD)+ sizeof(EmptyAlignedLongLongMemb)+ sizeof(EmptyPackedAlignedLongLongMemb)+ 0];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-vfvb-alignment.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>&1 \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { int a; B0() : a(0xf00000B0) {} }; struct B1 { char a; B1() : a(0xB1) {} }; struct B2 : virtual B1 { int a; B2() : a(0xf00000B2) {} }; struct B3 { __declspec(align(16)) int a; B3() : a(0xf00000B3) {} }; struct B4 : virtual B3 { int a; B4() : a(0xf00000B4) {} }; struct B5 { __declspec(align(32)) int a; B5() : a(0xf00000B5) {} }; struct B6 { int a; B6() : a(0xf00000B6) {} virtual void f() { printf("B6"); } }; struct A : B0, virtual B1 { __declspec(align(16)) int a; A() : a(0xf000000A) {} virtual void f() { printf("A"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vftable pointer) // CHECK-NEXT: 16 | struct B0 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (A vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct B1 (virtual base) // CHECK-NEXT: 64 | char a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vftable pointer) // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (A vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B1 (virtual base) // CHECK-X64-NEXT: 64 | char a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct B : A, B2 { int a; B() : a(0xf000000B) {} virtual void f() { printf("B"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | struct A (primary base) // CHECK-NEXT: 0 | (A vftable pointer) // CHECK-NEXT: 16 | struct B0 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (A vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct B2 (base) // CHECK-NEXT: 64 | (B2 vbtable pointer) // CHECK-NEXT: 68 | int a // CHECK-NEXT: 72 | int a // CHECK-NEXT: 80 | struct B1 (virtual base) // CHECK-NEXT: 80 | char a // CHECK-NEXT: | [sizeof=96, align=16 // CHECK-NEXT: | nvsize=80, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | struct A (primary base) // CHECK-X64-NEXT: 0 | (A vftable pointer) // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (A vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B2 (base) // CHECK-X64-NEXT: 64 | (B2 vbtable pointer) // CHECK-X64-NEXT: 72 | int a // CHECK-X64-NEXT: 80 | int a // CHECK-X64-NEXT: 96 | struct B1 (virtual base) // CHECK-X64-NEXT: 96 | char a // CHECK-X64-NEXT: | [sizeof=112, align=16 // CHECK-X64-NEXT: | nvsize=96, nvalign=16] struct C : B4 { int a; C() : a(0xf000000C) {} virtual void f() { printf("C"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vftable pointer) // CHECK-NEXT: 16 | struct B4 (base) // CHECK-NEXT: 16 | (B4 vbtable pointer) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 24 | int a // CHECK-NEXT: 32 | struct B3 (virtual base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vftable pointer) // CHECK-X64-NEXT: 16 | struct B4 (base) // CHECK-X64-NEXT: 16 | (B4 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | struct B3 (virtual base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct D : C { int a; D() : a(0xf000000D) {} virtual void f() { printf("D"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct C (primary base) // CHECK-NEXT: 0 | (C vftable pointer) // CHECK-NEXT: 16 | struct B4 (base) // CHECK-NEXT: 16 | (B4 vbtable pointer) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 24 | int a // CHECK-NEXT: 32 | int a // CHECK-NEXT: 48 | struct B3 (virtual base) // CHECK-NEXT: 48 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | struct C (primary base) // CHECK-X64-NEXT: 0 | (C vftable pointer) // CHECK-X64-NEXT: 16 | struct B4 (base) // CHECK-X64-NEXT: 16 | (B4 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B3 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct E : virtual C { int a; E() : a(0xf000000E) {} virtual void f() { printf("E"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | (E vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 16 | struct B3 (virtual base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 44 | (vtordisp for vbase C) // CHECK-NEXT: 48 | struct C (virtual base) // CHECK-NEXT: 48 | (C vftable pointer) // CHECK-NEXT: 64 | struct B4 (base) // CHECK-NEXT: 64 | (B4 vbtable pointer) // CHECK-NEXT: 68 | int a // CHECK-NEXT: 72 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=8, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | (E vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B3 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 44 | (vtordisp for vbase C) // CHECK-X64-NEXT: 48 | struct C (virtual base) // CHECK-X64-NEXT: 48 | (C vftable pointer) // CHECK-X64-NEXT: 64 | struct B4 (base) // CHECK-X64-NEXT: 64 | (B4 vbtable pointer) // CHECK-X64-NEXT: 72 | int a // CHECK-X64-NEXT: 80 | int a // CHECK-X64-NEXT: | [sizeof=96, align=16 // CHECK-X64-NEXT: | nvsize=16, nvalign=16] struct F : B3, virtual B0 { int a; F() : a(0xf000000F) {} virtual void f() { printf("F"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | (F vftable pointer) // CHECK-NEXT: 16 | struct B3 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | (F vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct B0 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | (F vftable pointer) // CHECK-X64-NEXT: 16 | struct B3 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | (F vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B0 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct G : B2, B6, virtual B1 { int a; G() : a(0xf0000010) {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct G // CHECK-NEXT: 0 | struct B6 (primary base) // CHECK-NEXT: 0 | (B6 vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B2 (base) // CHECK-NEXT: 8 | (B2 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B1 (virtual base) // CHECK-NEXT: 20 | char a // CHECK-NEXT: | [sizeof=21, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct G // CHECK-X64-NEXT: 0 | struct B6 (primary base) // CHECK-X64-NEXT: 0 | (B6 vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B2 (base) // CHECK-X64-NEXT: 16 | (B2 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 40 | struct B1 (virtual base) // CHECK-X64-NEXT: 40 | char a // CHECK-X64-NEXT: | [sizeof=48, align=8 // CHECK-X64-NEXT: | nvsize=40, nvalign=8] struct H : B6, B2, virtual B1 { int a; H() : a(0xf0000011) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct H // CHECK-NEXT: 0 | struct B6 (primary base) // CHECK-NEXT: 0 | (B6 vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B2 (base) // CHECK-NEXT: 8 | (B2 vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B1 (virtual base) // CHECK-NEXT: 20 | char a // CHECK-NEXT: | [sizeof=21, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct H // CHECK-X64-NEXT: 0 | struct B6 (primary base) // CHECK-X64-NEXT: 0 | (B6 vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B2 (base) // CHECK-X64-NEXT: 16 | (B2 vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 40 | struct B1 (virtual base) // CHECK-X64-NEXT: 40 | char a // CHECK-X64-NEXT: | [sizeof=48, align=8 // CHECK-X64-NEXT: | nvsize=40, nvalign=8] struct I : B0, virtual B1 { int a; int a1; __declspec(align(16)) int a2; I() : a(0xf0000011), a1(0xf0000011), a2(0xf0000011) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct I // CHECK-NEXT: 0 | struct B0 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | (I vbtable pointer) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 24 | int a1 // CHECK-NEXT: 32 | int a2 // CHECK-NEXT: 48 | struct B1 (virtual base) // CHECK-NEXT: 48 | char a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct I // CHECK-X64-NEXT: 0 | struct B0 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 8 | (I vbtable pointer) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | int a1 // CHECK-X64-NEXT: 32 | int a2 // CHECK-X64-NEXT: 48 | struct B1 (virtual base) // CHECK-X64-NEXT: 48 | char a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct J : B0, B3, virtual B1 { int a; int a1; J() : a(0xf0000012), a1(0xf0000012) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct J // CHECK-NEXT: 0 | struct B0 (base) // CHECK-NEXT: 0 | int a // CHECK-NEXT: 16 | struct B3 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | (J vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 52 | int a1 // CHECK-NEXT: 64 | struct B1 (virtual base) // CHECK-NEXT: 64 | char a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct J // CHECK-X64-NEXT: 0 | struct B0 (base) // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 16 | struct B3 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | (J vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 52 | int a1 // CHECK-X64-NEXT: 64 | struct B1 (virtual base) // CHECK-X64-NEXT: 64 | char a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct K { int a; K() : a(0xf0000013) {} virtual void f() { printf("K"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct K // CHECK-NEXT: 0 | (K vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct K // CHECK-X64-NEXT: 0 | (K vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct L : virtual K { int a; L() : a(0xf0000014) {} virtual void g() { printf("L"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct L // CHECK-NEXT: 0 | (L vftable pointer) // CHECK-NEXT: 4 | (L vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct K (virtual base) // CHECK-NEXT: 12 | (K vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct L // CHECK-X64-NEXT: 0 | (L vftable pointer) // CHECK-X64-NEXT: 8 | (L vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct K (virtual base) // CHECK-X64-NEXT: 24 | (K vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct M : virtual K { int a; M() : a(0xf0000015) {} virtual void f() { printf("M"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct M // CHECK-NEXT: 0 | (M vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (vtordisp for vbase K) // CHECK-NEXT: 12 | struct K (virtual base) // CHECK-NEXT: 12 | (K vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct M // CHECK-X64-NEXT: 0 | (M vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 20 | (vtordisp for vbase K) // CHECK-X64-NEXT: 24 | struct K (virtual base) // CHECK-X64-NEXT: 24 | (K vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(G)+ sizeof(H)+ sizeof(I)+ sizeof(J)+ sizeof(K)+ sizeof(L)+ sizeof(M)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); __declspec(align(4096)) char buffer[4096]; struct AT {}; struct V : AT { char c; V() { printf("V - this: %d\n", (int)((char*)this - buffer)); } }; struct AT0 { union { struct { int a; AT t; } y; int b; } x; char c; AT0() { printf("AT0 - this: %d\n", (int)((char*)this - buffer)); } }; struct AT1 : V { int a; AT1() { printf("AT1 - this: %d\n", (int)((char*)this - buffer)); } }; struct AT2 { AT0 t; char AT2FieldName0; AT2() { printf("AT2 - this: %d\n", (int)((char*)this - buffer)); printf("AT2 - Fiel: %d\n", (int)((char*)&AT2FieldName0 - buffer)); } }; struct AT3 : AT2, AT1 { AT3() { printf("AT3 - this: %d\n", (int)((char*)this - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AT3 // CHECK-NEXT: 0 | struct AT2 (base) // CHECK-NEXT: 0 | struct AT0 t // CHECK-NEXT: 0 | union AT0::(anonymous at {{.*}} x // CHECK-NEXT: 0 | struct AT0::(anonymous at {{.*}} y // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | struct AT t (empty) // CHECK: 0 | int b // CHECK: 8 | char c // CHECK: 12 | char AT2FieldName0 // CHECK-NEXT: 20 | struct AT1 (base) // CHECK-NEXT: 20 | struct V (base) // CHECK-NEXT: 20 | struct AT (base) (empty) // CHECK-NEXT: 20 | char c // CHECK-NEXT: 24 | int a // CHECK-NEXT: | [sizeof=28, align=4 // CHECK-NEXT: | nvsize=28, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AT3 // CHECK-X64-NEXT: 0 | struct AT2 (base) // CHECK-X64-NEXT: 0 | struct AT0 t // CHECK-X64-NEXT: 0 | union AT0::(anonymous at {{.*}} x // CHECK-X64-NEXT: 0 | struct AT0::(anonymous at {{.*}} y // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 4 | struct AT t (empty) // CHECK-X64: 0 | int b // CHECK-X64: 8 | char c // CHECK-X64: 12 | char AT2FieldName0 // CHECK-X64-NEXT: 20 | struct AT1 (base) // CHECK-X64-NEXT: 20 | struct V (base) // CHECK-X64-NEXT: 20 | struct AT (base) (empty) // CHECK-X64-NEXT: 20 | char c // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: | [sizeof=28, align=4 // CHECK-X64-NEXT: | nvsize=28, nvalign=4] struct BT0 { BT0() { printf("BT0 - this: %d\n", (int)((char*)this - buffer)); } }; struct BT2 : BT0 { char BT2FieldName0; BT2() { printf("BT2 - this: %d\n", (int)((char*)this - buffer)); printf("BT2 - Fiel: %d\n", (int)((char*)&BT2FieldName0 - buffer)); } }; struct BT3 : BT0, BT2 { BT3() { printf("BT3 - this: %d\n", (int)((char*)this - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct BT3 // CHECK-NEXT: 0 | struct BT0 (base) (empty) // CHECK-NEXT: 1 | struct BT2 (base) // CHECK-NEXT: 1 | struct BT0 (base) (empty) // CHECK-NEXT: 1 | char BT2FieldName0 // CHECK-NEXT: | [sizeof=2, align=1 // CHECK-NEXT: | nvsize=2, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct BT3 // CHECK-X64-NEXT: 0 | struct BT0 (base) (empty) // CHECK-X64-NEXT: 1 | struct BT2 (base) // CHECK-X64-NEXT: 1 | struct BT0 (base) (empty) // CHECK-X64-NEXT: 1 | char BT2FieldName0 // CHECK-X64-NEXT: | [sizeof=2, align=1 // CHECK-X64-NEXT: | nvsize=2, nvalign=1] struct T0 : AT { T0() { printf("T0 (this) : %d\n", (int)((char*)this - buffer)); } }; struct T1 : T0 { char a; T1() { printf("T1 (this) : %d\n", (int)((char*)this - buffer)); printf("T1 (fiel) : %d\n", (int)((char*)&a - buffer)); } }; struct T2 : AT { char a; T2() { printf("T2 (this) : %d\n", (int)((char*)this - buffer)); printf("T2 (fiel) : %d\n", (int)((char*)&a - buffer)); } }; struct __declspec(align(1)) T3 : virtual T1, virtual T2 { T3() { printf("T3 (this) : %d\n", (int)((char*)this - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct T3 // CHECK-NEXT: 0 | (T3 vbtable pointer) // CHECK-NEXT: 4 | struct T1 (virtual base) // CHECK-NEXT: 4 | struct T0 (base) (empty) // CHECK-NEXT: 4 | struct AT (base) (empty) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 12 | struct T2 (virtual base) // CHECK-NEXT: 12 | struct AT (base) (empty) // CHECK-NEXT: 12 | char a // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct T3 // CHECK-X64-NEXT: 0 | (T3 vbtable pointer) // CHECK-X64-NEXT: 8 | struct T1 (virtual base) // CHECK-X64-NEXT: 8 | struct T0 (base) (empty) // CHECK-X64-NEXT: 8 | struct AT (base) (empty) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 16 | struct T2 (virtual base) // CHECK-X64-NEXT: 16 | struct AT (base) (empty) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct B {}; struct C { int a; }; struct D : B, virtual C { B b; }; struct E : D, B {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | struct D (base) // CHECK-NEXT: 4 | struct B (base) (empty) // CHECK-NEXT: 0 | (D vbtable pointer) // CHECK-NEXT: 4 | struct B b (empty) // CHECK: 8 | struct B (base) (empty) // CHECK-NEXT: 8 | struct C (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | struct D (base) // CHECK-X64-NEXT: 8 | struct B (base) (empty) // CHECK-X64-NEXT: 0 | (D vbtable pointer) // CHECK-X64-NEXT: 8 | struct B b (empty) // CHECK-X64: 16 | struct B (base) (empty) // CHECK-X64-NEXT: 16 | struct C (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct F : virtual D, virtual B {}; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | (F vbtable pointer) // CHECK-NEXT: 4 | struct C (virtual base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct D (virtual base) // CHECK-NEXT: 12 | struct B (base) (empty) // CHECK-NEXT: 8 | (D vbtable pointer) // CHECK-NEXT: 12 | struct B b (empty) // CHECK: 16 | struct B (virtual base) (empty) // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | (F vbtable pointer) // CHECK-X64-NEXT: 8 | struct C (virtual base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct D (virtual base) // CHECK-X64-NEXT: 24 | struct B (base) (empty) // CHECK-X64-NEXT: 16 | (D vbtable pointer) // CHECK-X64-NEXT: 24 | struct B b (empty) // CHECK-X64: 32 | struct B (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=32, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct JC0 { JC0() { printf("JC0 : %d\n", (int)((char*)this - buffer)); } }; struct JC1 : JC0 { virtual void f() {} JC1() { printf("JC1 : %d\n", (int)((char*)this - buffer)); } }; struct JC2 : JC1 { JC2() { printf("JC2 : %d\n", (int)((char*)this - buffer)); } }; struct JC4 : JC1, JC2 { JC4() { printf("JC4 : %d\n", (int)((char*)this - buffer)); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct JC4 // CHECK-NEXT: 0 | struct JC1 (primary base) // CHECK-NEXT: 0 | (JC1 vftable pointer) // CHECK-NEXT: 4 | struct JC0 (base) (empty) // CHECK-NEXT: 8 | struct JC2 (base) // CHECK-NEXT: 8 | struct JC1 (primary base) // CHECK-NEXT: 8 | (JC1 vftable pointer) // CHECK-NEXT: 12 | struct JC0 (base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct JC4 // CHECK-X64-NEXT: 0 | struct JC1 (primary base) // CHECK-X64-NEXT: 0 | (JC1 vftable pointer) // CHECK-X64-NEXT: 8 | struct JC0 (base) (empty) // CHECK-X64-NEXT: 16 | struct JC2 (base) // CHECK-X64-NEXT: 16 | struct JC1 (primary base) // CHECK-X64-NEXT: 16 | (JC1 vftable pointer) // CHECK-X64-NEXT: 24 | struct JC0 (base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct RA {}; struct RB { char c; }; struct RV {}; struct RW { char c; }; struct RY { RY() { printf("%Id\n", (char*)this - buffer); } }; struct RX0 : RB, RA {}; struct RX1 : RA, RB {}; struct RX2 : RA { char a; }; struct RX3 : RA { RB a; }; struct RX4 { RA a; char b; }; struct RX5 { RA a; RB b; }; struct RX6 : virtual RV { RB a; }; struct RX7 : virtual RW { RA a; }; struct RX8 : RA, virtual RW {}; struct RZ0 : RX0, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ0 // CHECK-NEXT: 0 | struct RX0 (base) // CHECK-NEXT: 0 | struct RB (base) // CHECK-NEXT: 0 | char c // CHECK-NEXT: 1 | struct RA (base) (empty) // CHECK-NEXT: 2 | struct RY (base) (empty) // CHECK-NEXT: | [sizeof=2, align=1 // CHECK-NEXT: | nvsize=2, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ0 // CHECK-X64-NEXT: 0 | struct RX0 (base) // CHECK-X64-NEXT: 0 | struct RB (base) // CHECK-X64-NEXT: 0 | char c // CHECK-X64-NEXT: 1 | struct RA (base) (empty) // CHECK-X64-NEXT: 2 | struct RY (base) (empty) // CHECK-X64-NEXT: | [sizeof=2, align=1 // CHECK-X64-NEXT: | nvsize=2, nvalign=1] struct RZ1 : RX1, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ1 // CHECK-NEXT: 0 | struct RX1 (base) // CHECK-NEXT: 0 | struct RA (base) (empty) // CHECK-NEXT: 0 | struct RB (base) // CHECK-NEXT: 0 | char c // CHECK-NEXT: 1 | struct RY (base) (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=1, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ1 // CHECK-X64-NEXT: 0 | struct RX1 (base) // CHECK-X64-NEXT: 0 | struct RA (base) (empty) // CHECK-X64-NEXT: 0 | struct RB (base) // CHECK-X64-NEXT: 0 | char c // CHECK-X64-NEXT: 1 | struct RY (base) (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=1, nvalign=1] struct RZ2 : RX2, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ2 // CHECK-NEXT: 0 | struct RX2 (base) // CHECK-NEXT: 0 | struct RA (base) (empty) // CHECK-NEXT: 0 | char a // CHECK-NEXT: 2 | struct RY (base) (empty) // CHECK-NEXT: | [sizeof=2, align=1 // CHECK-NEXT: | nvsize=2, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ2 // CHECK-X64-NEXT: 0 | struct RX2 (base) // CHECK-X64-NEXT: 0 | struct RA (base) (empty) // CHECK-X64-NEXT: 0 | char a // CHECK-X64-NEXT: 2 | struct RY (base) (empty) // CHECK-X64-NEXT: | [sizeof=2, align=1 // CHECK-X64-NEXT: | nvsize=2, nvalign=1] struct RZ3 : RX3, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ3 // CHECK-NEXT: 0 | struct RX3 (base) // CHECK-NEXT: 0 | struct RA (base) (empty) // CHECK-NEXT: 0 | struct RB a // CHECK-NEXT: 0 | char c // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=1, nvalign=1] // CHECK-NEXT: 1 | struct RY (base) (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=1, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ3 // CHECK-X64-NEXT: 0 | struct RX3 (base) // CHECK-X64-NEXT: 0 | struct RA (base) (empty) // CHECK-X64-NEXT: 0 | struct RB a // CHECK-X64-NEXT: 0 | char c // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=1, nvalign=1] // CHECK-X64-NEXT: 1 | struct RY (base) (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=1, nvalign=1] struct RZ4 : RX4, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ4 // CHECK-NEXT: 0 | struct RX4 (base) // CHECK-NEXT: 0 | struct RA a (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK-NEXT: 1 | char b // CHECK-NEXT: 3 | struct RY (base) (empty) // CHECK-NEXT: | [sizeof=3, align=1 // CHECK-NEXT: | nvsize=3, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ4 // CHECK-X64-NEXT: 0 | struct RX4 (base) // CHECK-X64-NEXT: 0 | struct RA a (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64-NEXT: 1 | char b // CHECK-X64-NEXT: 3 | struct RY (base) (empty) // CHECK-X64-NEXT: | [sizeof=3, align=1 // CHECK-X64-NEXT: | nvsize=3, nvalign=1] struct RZ5 : RX5, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ5 // CHECK-NEXT: 0 | struct RX5 (base) // CHECK-NEXT: 0 | struct RA a (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK-NEXT: 1 | struct RB b // CHECK-NEXT: 1 | char c // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=1, nvalign=1] // CHECK-NEXT: 2 | struct RY (base) (empty) // CHECK-NEXT: | [sizeof=2, align=1 // CHECK-NEXT: | nvsize=2, nvalign=1] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ5 // CHECK-X64-NEXT: 0 | struct RX5 (base) // CHECK-X64-NEXT: 0 | struct RA a (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64-NEXT: 1 | struct RB b // CHECK-X64-NEXT: 1 | char c // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=1, nvalign=1] // CHECK-X64-NEXT: 2 | struct RY (base) (empty) // CHECK-X64-NEXT: | [sizeof=2, align=1 // CHECK-X64-NEXT: | nvsize=2, nvalign=1] struct RZ6 : RX6, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ6 // CHECK-NEXT: 0 | struct RX6 (base) // CHECK-NEXT: 0 | (RX6 vbtable pointer) // CHECK-NEXT: 4 | struct RB a // CHECK-NEXT: 4 | char c // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=1, nvalign=1] // CHECK-NEXT: 9 | struct RY (base) (empty) // CHECK-NEXT: 12 | struct RV (virtual base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ6 // CHECK-X64-NEXT: 0 | struct RX6 (base) // CHECK-X64-NEXT: 0 | (RX6 vbtable pointer) // CHECK-X64-NEXT: 8 | struct RB a // CHECK-X64-NEXT: 8 | char c // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=1, nvalign=1] // CHECK-X64-NEXT: 17 | struct RY (base) (empty) // CHECK-X64-NEXT: 24 | struct RV (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct RZ7 : RX7, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ7 // CHECK-NEXT: 0 | struct RX7 (base) // CHECK-NEXT: 0 | (RX7 vbtable pointer) // CHECK-NEXT: 4 | struct RA a (empty) // CHECK-NEXT: | [sizeof=1, align=1 // CHECK-NEXT: | nvsize=0, nvalign=1] // CHECK-NEXT: 8 | struct RY (base) (empty) // CHECK-NEXT: 8 | struct RW (virtual base) // CHECK-NEXT: 8 | char c // CHECK-NEXT: | [sizeof=9, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ7 // CHECK-X64-NEXT: 0 | struct RX7 (base) // CHECK-X64-NEXT: 0 | (RX7 vbtable pointer) // CHECK-X64-NEXT: 8 | struct RA a (empty) // CHECK-X64-NEXT: | [sizeof=1, align=1 // CHECK-X64-NEXT: | nvsize=0, nvalign=1] // CHECK-X64-NEXT: 16 | struct RY (base) (empty) // CHECK-X64-NEXT: 16 | struct RW (virtual base) // CHECK-X64-NEXT: 16 | char c // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct RZ8 : RX8, RY {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct RZ8 // CHECK-NEXT: 0 | struct RX8 (base) // CHECK-NEXT: 4 | struct RA (base) (empty) // CHECK-NEXT: 0 | (RX8 vbtable pointer) // CHECK-NEXT: 4 | struct RY (base) (empty) // CHECK-NEXT: 4 | struct RW (virtual base) // CHECK-NEXT: 4 | char c // CHECK-NEXT: | [sizeof=5, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct RZ8 // CHECK-X64-NEXT: 0 | struct RX8 (base) // CHECK-X64-NEXT: 8 | struct RA (base) (empty) // CHECK-X64-NEXT: 0 | (RX8 vbtable pointer) // CHECK-X64-NEXT: 8 | struct RY (base) (empty) // CHECK-X64-NEXT: 8 | struct RW (virtual base) // CHECK-X64-NEXT: 8 | char c // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct JA {}; struct JB {}; struct JC : JA { virtual void f() {} }; struct JD : virtual JB, virtual JC { virtual void f() {} JD() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct JD // CHECK-NEXT: 0 | (JD vbtable pointer) // CHECK-NEXT: 4 | struct JB (virtual base) (empty) // CHECK-NEXT: 4 | (vtordisp for vbase JC) // CHECK-NEXT: 8 | struct JC (virtual base) // CHECK-NEXT: 8 | (JC vftable pointer) // CHECK-NEXT: 12 | struct JA (base) (empty) // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct JD // CHECK-X64-NEXT: 0 | (JD vbtable pointer) // CHECK-X64-NEXT: 8 | struct JB (virtual base) (empty) // CHECK-X64-NEXT: 12 | (vtordisp for vbase JC) // CHECK-X64-NEXT: 16 | struct JC (virtual base) // CHECK-X64-NEXT: 16 | (JC vftable pointer) // CHECK-X64-NEXT: 24 | struct JA (base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] int a[ sizeof(AT3) + sizeof(BT3) + sizeof(T3) + sizeof(E) + sizeof(F) + sizeof(JC4) + sizeof(RZ0) + sizeof(RZ1) + sizeof(RZ2) + sizeof(RZ3) + sizeof(RZ4) + sizeof(RZ5) + sizeof(RZ6) + sizeof(RZ7) + sizeof(RZ8) + sizeof(JD) + 0];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-empty-virtual-base.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct __declspec(align(8)) B0 { B0() {printf("B0 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct __declspec(align(8)) B1 { B1() {printf("B1 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct __declspec(align(8)) B2 { B2() {printf("B2 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct __declspec(align(8)) B3 { B3() {printf("B3 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct __declspec(align(8)) B4 { B4() {printf("B4 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct C0 { int a; C0() : a(0xf00000C0) {printf("C0 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct C1 { int a; C1() : a(0xf00000C1) {printf("C1 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct C2 { int a; C2() : a(0xf00000C2) {printf("C2 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct C3 { int a; C3() : a(0xf00000C3) {printf("C3 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct C4 { int a; C4() : a(0xf00000C4) {printf("C4 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct __declspec(align(16)) D0 { D0() {printf("D0 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} virtual void f() {} }; struct D1 { D1() {printf("D1 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct D2 { int a[8]; D2() {printf("D2 : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; struct A : virtual B0 { int a; A() : a(0xf000000A) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct B : virtual B0 { B0 b0; int a; B() : a(0xf000000B) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | (B vbtable pointer) // CHECK-NEXT: 8 | struct B0 b0 (empty) // CHECK-NEXT: | [sizeof=8, align=8 // CHECK-NEXT: | nvsize=0, nvalign=8] // CHECK: 16 | int a // CHECK-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=24, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | (B vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 b0 (empty) // CHECK-X64-NEXT: | [sizeof=8, align=8 // CHECK-X64-NEXT: | nvsize=0, nvalign=8] // CHECK-X64: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct C : virtual B0, virtual B1, virtual B2, virtual B3, virtual B4 { int a; C() : a(0xf000000C) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) (empty) // CHECK-NEXT: 16 | struct B1 (virtual base) (empty) // CHECK-NEXT: 24 | struct B2 (virtual base) (empty) // CHECK-NEXT: 32 | struct B3 (virtual base) (empty) // CHECK-NEXT: 40 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=40, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 24 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 32 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 40 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 48 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=48, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct D { B0 b0; C0 c0; C1 c1; C2 c2; B1 b1; int a; D() : a(0xf000000D) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct B0 b0 (empty) // CHECK: 8 | struct C0 c0 // CHECK-NEXT: 8 | int a // CHECK: 12 | struct C1 c1 // CHECK-NEXT: 12 | int a // CHECK: 16 | struct C2 c2 // CHECK-NEXT: 16 | int a // CHECK: 24 | struct B1 b1 (empty) // CHECK: 32 | int a // CHECK-NEXT: | [sizeof=40, align=8 // CHECK-NEXT: | nvsize=40, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | struct B0 b0 (empty) // CHECK-X64: 8 | struct C0 c0 // CHECK-X64-NEXT: 8 | int a // CHECK-X64: 12 | struct C1 c1 // CHECK-X64-NEXT: 12 | int a // CHECK-X64: 16 | struct C2 c2 // CHECK-X64-NEXT: 16 | int a // CHECK-X64: 24 | struct B1 b1 (empty) // CHECK-X64: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=40, nvalign=8] struct E : virtual B0, virtual C0, virtual C1, virtual C2, virtual B1 { int a; E() : a(0xf000000E) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | (E vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) (empty) // CHECK-NEXT: 8 | struct C0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct C1 (virtual base) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | struct C2 (virtual base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 24 | struct B1 (virtual base) (empty) // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | (E vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 16 | struct C0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | struct C1 (virtual base) // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: 24 | struct C2 (virtual base) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=32, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct F : virtual C0, virtual B0, virtual B1, virtual C1 { int a; F() : a(0xf000000F) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | (F vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct C0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: 24 | struct B1 (virtual base) (empty) // CHECK-NEXT: 24 | struct C1 (virtual base) // CHECK-NEXT: 24 | int a // CHECK-NEXT: | [sizeof=32, align=8 // CHECK-NEXT: | nvsize=8, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | (F vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct C0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 32 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 32 | struct C1 (virtual base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct G : virtual C0, virtual B0, virtual B1, D0, virtual C1 { int a; G() : a(0xf0000010) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} virtual void f() {} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct G // CHECK-NEXT: 0 | struct D0 (primary base) // CHECK-NEXT: 0 | (D0 vftable pointer) // CHECK-NEXT: 4 | (G vbtable pointer) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 32 | struct C0 (virtual base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 40 | struct B0 (virtual base) (empty) // CHECK-NEXT: 56 | struct B1 (virtual base) (empty) // CHECK-NEXT: 56 | struct C1 (virtual base) // CHECK-NEXT: 56 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct G // CHECK-X64-NEXT: 0 | struct D0 (primary base) // CHECK-X64-NEXT: 0 | (D0 vftable pointer) // CHECK-X64-NEXT: 8 | (G vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | struct C0 (virtual base) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 40 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 56 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 56 | struct C1 (virtual base) // CHECK-X64-NEXT: 56 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct H : virtual C0, virtual B0, virtual B1, virtual D0, virtual C1 { int a; H() : a(0xf0000011) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} virtual void f() {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct H // CHECK-NEXT: 0 | (H vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct C0 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-NEXT: 24 | struct B1 (virtual base) (empty) // CHECK-NEXT: 44 | (vtordisp for vbase D0) // CHECK-NEXT: 48 | struct D0 (virtual base) // CHECK-NEXT: 48 | (D0 vftable pointer) // CHECK-NEXT: 52 | struct C1 (virtual base) // CHECK-NEXT: 52 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=8, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct H // CHECK-X64-NEXT: 0 | (H vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct C0 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 60 | (vtordisp for vbase D0) // CHECK-X64-NEXT: 64 | struct D0 (virtual base) // CHECK-X64-NEXT: 64 | (D0 vftable pointer) // CHECK-X64-NEXT: 72 | struct C1 (virtual base) // CHECK-X64-NEXT: 72 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=16, nvalign=16] struct I : virtual B0, virtual B1, virtual B2, virtual B3, virtual B4 { __declspec(align(32)) int a; I() : a(0xf0000012) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct I // CHECK-NEXT: 0 | (I vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B0 (virtual base) (empty) // CHECK-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=192, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct I // CHECK-X64-NEXT: 0 | (I vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=192, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct __declspec(align(32)) J : virtual B0, virtual B1, virtual B2, virtual B3, virtual B4 { int a; J() : a(0xf0000012) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct J // CHECK-NEXT: 0 | (J vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) (empty) // CHECK-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-NEXT: 72 | struct B2 (virtual base) (empty) // CHECK-NEXT: 104 | struct B3 (virtual base) (empty) // CHECK-NEXT: 136 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=160, align=32 // CHECK-NEXT: | nvsize=8, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct J // CHECK-X64-NEXT: 0 | (J vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=160, align=32 // CHECK-X64-NEXT: | nvsize=16, nvalign=32] struct K : virtual D1, virtual B1, virtual B2, virtual B3, virtual B4 { __declspec(align(32)) int a; K() : a(0xf0000013) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct K // CHECK-NEXT: 0 | (K vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct D1 (virtual base) (empty) // CHECK-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=192, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct K // CHECK-X64-NEXT: 0 | (K vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=192, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct L : virtual B1, virtual D1, virtual B2, virtual B3, virtual B4 { __declspec(align(32)) int a; L() : a(0xf0000014) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct L // CHECK-NEXT: 0 | (L vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-NEXT: 68 | struct D1 (virtual base) (empty) // CHECK-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=192, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct L // CHECK-X64-NEXT: 0 | (L vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 68 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=192, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct M : virtual B1, virtual B2, virtual D1, virtual B3, virtual B4 { __declspec(align(32)) int a; M() : a(0xf0000015) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct M // CHECK-NEXT: 0 | (M vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-NEXT: 72 | struct B2 (virtual base) (empty) // CHECK-NEXT: 100 | struct D1 (virtual base) (empty) // CHECK-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=192, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct M // CHECK-X64-NEXT: 0 | (M vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 100 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=192, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct N : virtual C0, virtual B1, virtual D1, virtual B2, virtual B3, virtual B4 { __declspec(align(32)) int a; N() : a(0xf0000016) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct N // CHECK-NEXT: 0 | (N vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct C0 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-NEXT: 100 | struct D1 (virtual base) (empty) // CHECK-NEXT: 136 | struct B2 (virtual base) (empty) // CHECK-NEXT: 168 | struct B3 (virtual base) (empty) // CHECK-NEXT: 200 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=224, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct N // CHECK-X64-NEXT: 0 | (N vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct C0 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 100 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 200 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=224, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct O : virtual C0, virtual B1, virtual B2, virtual D1, virtual B3, virtual B4 { __declspec(align(32)) int a; O() : a(0xf0000017) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct O // CHECK-NEXT: 0 | (O vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct C0 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-NEXT: 132 | struct D1 (virtual base) (empty) // CHECK-NEXT: 168 | struct B3 (virtual base) (empty) // CHECK-NEXT: 200 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=224, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct O // CHECK-X64-NEXT: 0 | (O vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct C0 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 132 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 200 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=224, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct P : virtual B1, virtual C0, virtual D1, virtual B2, virtual B3, virtual B4 { __declspec(align(32)) int a; P() : a(0xf0000018) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct P // CHECK-NEXT: 0 | (P vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-NEXT: 64 | struct C0 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: 68 | struct D1 (virtual base) (empty) // CHECK-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=192, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct P // CHECK-X64-NEXT: 0 | (P vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 64 | struct C0 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 68 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=192, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct Q : virtual B1, virtual C0, virtual B2, virtual D1, virtual B3, virtual B4 { __declspec(align(32)) int a; Q() : a(0xf0000019) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct Q // CHECK-NEXT: 0 | (Q vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-NEXT: 64 | struct C0 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: 72 | struct B2 (virtual base) (empty) // CHECK-NEXT: 100 | struct D1 (virtual base) (empty) // CHECK-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=192, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct Q // CHECK-X64-NEXT: 0 | (Q vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 64 | struct C0 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: 72 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 100 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 168 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=192, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct R : virtual B0, virtual B1, virtual B2, virtual C0, virtual B3, virtual B4 { __declspec(align(32)) int a; R() : a(0xf0000020) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct R // CHECK-NEXT: 0 | (R vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B0 (virtual base) (empty) // CHECK-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-NEXT: 104 | struct C0 (virtual base) // CHECK-NEXT: 104 | int a // CHECK-NEXT: 112 | struct B3 (virtual base) (empty) // CHECK-NEXT: 136 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=160, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct R // CHECK-X64-NEXT: 0 | (R vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct C0 (virtual base) // CHECK-X64-NEXT: 104 | int a // CHECK-X64-NEXT: 112 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=160, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct S : virtual B0, virtual B1, virtual C0, virtual B2, virtual B3, virtual B4 { __declspec(align(32)) int a; S() : a(0xf0000021) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct S // CHECK-NEXT: 0 | (S vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 64 | struct B0 (virtual base) (empty) // CHECK-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-NEXT: 72 | struct C0 (virtual base) // CHECK-NEXT: 72 | int a // CHECK-NEXT: 80 | struct B2 (virtual base) (empty) // CHECK-NEXT: 104 | struct B3 (virtual base) (empty) // CHECK-NEXT: 136 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=160, align=32 // CHECK-NEXT: | nvsize=64, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct S // CHECK-X64-NEXT: 0 | (S vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 64 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 72 | struct C0 (virtual base) // CHECK-X64-NEXT: 72 | int a // CHECK-X64-NEXT: 80 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 136 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=160, align=32 // CHECK-X64-NEXT: | nvsize=64, nvalign=32] struct T : virtual B0, virtual B1, virtual C0, virtual D2, virtual B2, virtual B3, virtual B4 { __declspec(align(16)) int a; T() : a(0xf0000022) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct T // CHECK-NEXT: 0 | (T vbtable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | struct B0 (virtual base) (empty) // CHECK-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-NEXT: 40 | struct C0 (virtual base) // CHECK-NEXT: 40 | int a // CHECK-NEXT: 44 | struct D2 (virtual base) // CHECK-NEXT: 44 | int [8] a // CHECK-NEXT: 80 | struct B2 (virtual base) (empty) // CHECK-NEXT: 88 | struct B3 (virtual base) (empty) // CHECK-NEXT: 104 | struct B4 (virtual base) (empty) // CHECK-NEXT: | [sizeof=112, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct T // CHECK-X64-NEXT: 0 | (T vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: 40 | struct C0 (virtual base) // CHECK-X64-NEXT: 40 | int a // CHECK-X64-NEXT: 44 | struct D2 (virtual base) // CHECK-X64-NEXT: 44 | int [8] a // CHECK-X64-NEXT: 80 | struct B2 (virtual base) (empty) // CHECK-X64-NEXT: 88 | struct B3 (virtual base) (empty) // CHECK-X64-NEXT: 104 | struct B4 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=112, align=16 // CHECK-X64-NEXT: | nvsize=32, nvalign=16] struct __declspec(align(32)) U : virtual B0, virtual B1 { int a; U() : a(0xf0000023) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct U // CHECK-NEXT: 0 | (U vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) (empty) // CHECK-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-NEXT: | [sizeof=64, align=32 // CHECK-NEXT: | nvsize=8, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct U // CHECK-X64-NEXT: 0 | (U vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) (empty) // CHECK-X64-NEXT: 40 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=64, align=32 // CHECK-X64-NEXT: | nvsize=16, nvalign=32] struct __declspec(align(32)) V : virtual D1 { int a; V() : a(0xf0000024) {printf("X : %3d\n", ((int)(__SIZE_TYPE__)this)&0xfff);} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct V // CHECK-NEXT: 0 | (V vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct D1 (virtual base) (empty) // CHECK-NEXT: | [sizeof=32, align=32 // CHECK-NEXT: | nvsize=8, nvalign=32] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct V // CHECK-X64-NEXT: 0 | (V vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct D1 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=32, align=32 // CHECK-X64-NEXT: | nvsize=16, nvalign=32] struct T0 {}; struct T1 : T0 { char a; }; struct T3 : virtual T1, virtual T0 { long long a; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct T3 // CHECK-NEXT: 0 | (T3 vbtable pointer) // CHECK-NEXT: 8 | long long a // CHECK-NEXT: 16 | struct T1 (virtual base) // CHECK-NEXT: 16 | struct T0 (base) (empty) // CHECK-NEXT: 16 | char a // CHECK-NEXT: 24 | struct T0 (virtual base) (empty) // CHECK-NEXT: | [sizeof=24, align=8 // CHECK-NEXT: | nvsize=16, nvalign=8] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct T3 // CHECK-X64-NEXT: 0 | (T3 vbtable pointer) // CHECK-X64-NEXT: 8 | long long a // CHECK-X64-NEXT: 16 | struct T1 (virtual base) // CHECK-X64-NEXT: 16 | struct T0 (base) (empty) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: 24 | struct T0 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct Q0A {}; struct Q0B { char Q0BField; }; struct Q0C : virtual Q0A, virtual Q0B { char Q0CField; }; struct Q0D : Q0C, Q0A {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct Q0D // CHECK-NEXT: 0 | struct Q0C (base) // CHECK-NEXT: 0 | (Q0C vbtable pointer) // CHECK-NEXT: 4 | char Q0CField // CHECK-NEXT: 8 | struct Q0A (base) (empty) // CHECK-NEXT: 8 | struct Q0A (virtual base) (empty) // CHECK-NEXT: 8 | struct Q0B (virtual base) // CHECK-NEXT: 8 | char Q0BField // CHECK-NEXT: | [sizeof=9, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct Q0D // CHECK-X64-NEXT: 0 | struct Q0C (base) // CHECK-X64-NEXT: 0 | (Q0C vbtable pointer) // CHECK-X64-NEXT: 8 | char Q0CField // CHECK-X64-NEXT: 16 | struct Q0A (base) (empty) // CHECK-X64-NEXT: 16 | struct Q0A (virtual base) (empty) // CHECK-X64-NEXT: 16 | struct Q0B (virtual base) // CHECK-X64-NEXT: 16 | char Q0BField // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(G)+ sizeof(H)+ sizeof(I)+ sizeof(J)+ sizeof(K)+ sizeof(L)+ sizeof(M)+ sizeof(N)+ sizeof(O)+ sizeof(P)+ sizeof(Q)+ sizeof(R)+ sizeof(S)+ sizeof(T)+ sizeof(U)+ sizeof(V)+ sizeof(T3)+ sizeof(Q0D)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-primary-bases.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { int a; B0() : a(0xf00000B0) { printf("B0 = %p\n", this); } virtual void f() { printf("B0"); } }; struct B1 { int a; B1() : a(0xf00000B1) { printf("B1 = %p\n", this); } virtual void g() { printf("B1"); } }; struct B2 { int a; B2() : a(0xf00000B2) { printf("B1 = %p\n", this); } }; struct B0X { int a; B0X() : a(0xf00000B0) {} }; struct B1X { int a; B1X() : a(0xf00000B1) {} virtual void f() { printf("B0"); } }; struct B2X : virtual B1X { int a; B2X() : a(0xf00000B2) {} }; struct A : virtual B0 { }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vbtable pointer) // CHECK-NEXT: 4 | struct B0 (virtual base) // CHECK-NEXT: 4 | (B0 vftable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 (virtual base) // CHECK-X64-NEXT: 8 | (B0 vftable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct B : virtual B0 { virtual void f() { printf("B"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | (B vbtable pointer) // CHECK-NEXT: 4 | struct B0 (virtual base) // CHECK-NEXT: 4 | (B0 vftable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | (B vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 (virtual base) // CHECK-X64-NEXT: 8 | (B0 vftable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct C : virtual B0 { virtual void g() { printf("A"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vftable pointer) // CHECK-NEXT: 4 | (C vbtable pointer) // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | (B0 vftable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vftable pointer) // CHECK-X64-NEXT: 8 | (C vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | (B0 vftable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: | [sizeof=32, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct D : virtual B2, virtual B0 { virtual void f() { printf("D"); } virtual void g() { printf("D"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | (D vftable pointer) // CHECK-NEXT: 4 | (D vbtable pointer) // CHECK-NEXT: 8 | struct B2 (virtual base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct B0 (virtual base) // CHECK-NEXT: 12 | (B0 vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | (D vftable pointer) // CHECK-X64-NEXT: 8 | (D vbtable pointer) // CHECK-X64-NEXT: 16 | struct B2 (virtual base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B0 (virtual base) // CHECK-X64-NEXT: 24 | (B0 vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct E : B0, virtual B1 { virtual void f() { printf("E"); } virtual void g() { printf("E"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | struct B0 (primary base) // CHECK-NEXT: 0 | (B0 vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (E vbtable pointer) // CHECK-NEXT: 12 | struct B1 (virtual base) // CHECK-NEXT: 12 | (B1 vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | struct B0 (primary base) // CHECK-X64-NEXT: 0 | (B0 vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | (E vbtable pointer) // CHECK-X64-NEXT: 24 | struct B1 (virtual base) // CHECK-X64-NEXT: 24 | (B1 vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct F : virtual B0, virtual B1 { }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | (F vbtable pointer) // CHECK-NEXT: 4 | struct B0 (virtual base) // CHECK-NEXT: 4 | (B0 vftable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct B1 (virtual base) // CHECK-NEXT: 12 | (B1 vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | (F vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 (virtual base) // CHECK-X64-NEXT: 8 | (B0 vftable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B1 (virtual base) // CHECK-X64-NEXT: 24 | (B1 vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct AX : B0X, B1X { int a; AX() : a(0xf000000A) {} virtual void f() { printf("A"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct AX // CHECK-NEXT: 0 | struct B1X (primary base) // CHECK-NEXT: 0 | (B1X vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0X (base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | int a // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct AX // CHECK-X64-NEXT: 0 | struct B1X (primary base) // CHECK-X64-NEXT: 0 | (B1X vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0X (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct BX : B0X, B1X { int a; BX() : a(0xf000000B) {} virtual void g() { printf("B"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct BX // CHECK-NEXT: 0 | struct B1X (primary base) // CHECK-NEXT: 0 | (B1X vftable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0X (base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | int a // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=16, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct BX // CHECK-X64-NEXT: 0 | struct B1X (primary base) // CHECK-X64-NEXT: 0 | (B1X vftable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0X (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 20 | int a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct CX : B0X, B2X { int a; CX() : a(0xf000000C) {} virtual void g() { printf("C"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct CX // CHECK-NEXT: 0 | (CX vftable pointer) // CHECK-NEXT: 4 | struct B0X (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B2X (base) // CHECK-NEXT: 8 | (B2X vbtable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | struct B1X (virtual base) // CHECK-NEXT: 20 | (B1X vftable pointer) // CHECK-NEXT: 24 | int a // CHECK-NEXT: | [sizeof=28, align=4 // CHECK-NEXT: | nvsize=20, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct CX // CHECK-X64-NEXT: 0 | (CX vftable pointer) // CHECK-X64-NEXT: 8 | struct B0X (base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B2X (base) // CHECK-X64-NEXT: 16 | (B2X vbtable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 40 | struct B1X (virtual base) // CHECK-X64-NEXT: 40 | (B1X vftable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=56, align=8 // CHECK-X64-NEXT: | nvsize=40, nvalign=8] struct DX : virtual B1X { int a; DX() : a(0xf000000D) {} virtual void f() { printf("D"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct DX // CHECK-NEXT: 0 | (DX vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (vtordisp for vbase B1X) // CHECK-NEXT: 12 | struct B1X (virtual base) // CHECK-NEXT: 12 | (B1X vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct DX // CHECK-X64-NEXT: 0 | (DX vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 20 | (vtordisp for vbase B1X) // CHECK-X64-NEXT: 24 | struct B1X (virtual base) // CHECK-X64-NEXT: 24 | (B1X vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct EX : virtual B1X { int a; EX() : a(0xf000000E) {} virtual void g() { printf("E"); } }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct EX // CHECK-NEXT: 0 | (EX vftable pointer) // CHECK-NEXT: 4 | (EX vbtable pointer) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 12 | struct B1X (virtual base) // CHECK-NEXT: 12 | (B1X vftable pointer) // CHECK-NEXT: 16 | int a // CHECK-NEXT: | [sizeof=20, align=4 // CHECK-NEXT: | nvsize=12, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct EX // CHECK-X64-NEXT: 0 | (EX vftable pointer) // CHECK-X64-NEXT: 8 | (EX vbtable pointer) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | struct B1X (virtual base) // CHECK-X64-NEXT: 24 | (B1X vftable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: | [sizeof=40, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] struct FX : virtual B1X { int a; FX() : a(0xf000000F) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct FX // CHECK-NEXT: 0 | (FX vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B1X (virtual base) // CHECK-NEXT: 8 | (B1X vftable pointer) // CHECK-NEXT: 12 | int a // CHECK-NEXT: | [sizeof=16, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct FX // CHECK-X64-NEXT: 0 | (FX vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B1X (virtual base) // CHECK-X64-NEXT: 16 | (B1X vftable pointer) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: | [sizeof=32, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)+ sizeof(AX)+ sizeof(BX)+ sizeof(CX)+ sizeof(DX)+ sizeof(EX)+ sizeof(FX)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-misalignedarray.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>&1 \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 struct T0 { char c; }; struct T2 : virtual T0 { }; struct T3 { T2 a[1]; char c; }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct T3 // CHECK-NEXT: 0 | struct T2 [1] a // CHECK-NEXT: 5 | char c // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct T3 // CHECK-X64-NEXT: 0 | struct T2 [1] a // CHECK-X64-NEXT: 16 | char c // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=24, nvalign=8] int a[sizeof(T3)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-vfvb-sharing.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>&1 \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { int a; B0() : a(0xf00000B0) { printf("B0 = %p\n", this); } }; struct B1 { int a; B1() : a(0xf00000B1) { printf("B1 = %p\n", this); } }; struct B2 { B2() { printf("B2 = %p\n", this); } virtual void g() { printf("B2"); } }; struct B3 : virtual B1 { B3() { printf("B3 = %p\n", this); } }; struct B4 : virtual B1 { B4() { printf("B4 = %p\n", this); } virtual void g() { printf("B4"); } }; struct A : B0, virtual B1 { __declspec(align(16)) int a; A() : a(0xf000000A) { printf(" A = %p\n\n", this); } virtual void f() { printf("A"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vftable pointer) // CHECK-NEXT: 16 | struct B0 (base) // CHECK-NEXT: 16 | int a // CHECK-NEXT: 20 | (A vbtable pointer) // CHECK-NEXT: 48 | int a // CHECK-NEXT: 64 | struct B1 (virtual base) // CHECK-NEXT: 64 | int a // CHECK-NEXT: | [sizeof=80, align=16 // CHECK-NEXT: | nvsize=64, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vftable pointer) // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 24 | (A vbtable pointer) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: 64 | struct B1 (virtual base) // CHECK-X64-NEXT: 64 | int a // CHECK-X64-NEXT: | [sizeof=80, align=16 // CHECK-X64-NEXT: | nvsize=64, nvalign=16] struct B : B2, B0, virtual B1 { __declspec(align(16)) int a; B() : a(0xf000000B) { printf(" B = %p\n\n", this); } virtual void f() { printf("B"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | struct B2 (primary base) // CHECK-NEXT: 0 | (B2 vftable pointer) // CHECK-NEXT: 4 | struct B0 (base) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | (B vbtable pointer) // CHECK-NEXT: 32 | int a // CHECK-NEXT: 48 | struct B1 (virtual base) // CHECK-NEXT: 48 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | struct B2 (primary base) // CHECK-X64-NEXT: 0 | (B2 vftable pointer) // CHECK-X64-NEXT: 8 | struct B0 (base) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | (B vbtable pointer) // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | struct B1 (virtual base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct C : B3, B0, virtual B1 { __declspec(align(16)) int a; C() : a(0xf000000C) { printf(" C = %p\n\n", this); } virtual void f() { printf("C"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vftable pointer) // CHECK-NEXT: 16 | struct B3 (base) // CHECK-NEXT: 16 | (B3 vbtable pointer) // CHECK-NEXT: 20 | struct B0 (base) // CHECK-NEXT: 20 | int a // CHECK-NEXT: 32 | int a // CHECK-NEXT: 48 | struct B1 (virtual base) // CHECK-NEXT: 48 | int a // CHECK-NEXT: | [sizeof=64, align=16 // CHECK-NEXT: | nvsize=48, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vftable pointer) // CHECK-X64-NEXT: 16 | struct B3 (base) // CHECK-X64-NEXT: 16 | (B3 vbtable pointer) // CHECK-X64-NEXT: 24 | struct B0 (base) // CHECK-X64-NEXT: 24 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | struct B1 (virtual base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] struct D : B4, B0, virtual B1 { __declspec(align(16)) int a; D() : a(0xf000000D) { printf(" D = %p\n\n", this); } virtual void f() { printf("D"); } }; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | struct B4 (primary base) // CHECK-NEXT: 0 | (B4 vftable pointer) // CHECK-NEXT: 4 | (B4 vbtable pointer) // CHECK-NEXT: 8 | struct B0 (base) // CHECK-NEXT: 8 | int a // CHECK-NEXT: 16 | int a // CHECK-NEXT: 32 | struct B1 (virtual base) // CHECK-NEXT: 32 | int a // CHECK-NEXT: | [sizeof=48, align=16 // CHECK-NEXT: | nvsize=32, nvalign=16] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | struct B4 (primary base) // CHECK-X64-NEXT: 0 | (B4 vftable pointer) // CHECK-X64-NEXT: 8 | (B4 vbtable pointer) // CHECK-X64-NEXT: 16 | struct B0 (base) // CHECK-X64-NEXT: 16 | int a // CHECK-X64-NEXT: 32 | int a // CHECK-X64-NEXT: 48 | struct B1 (virtual base) // CHECK-X64-NEXT: 48 | int a // CHECK-X64-NEXT: | [sizeof=64, align=16 // CHECK-X64-NEXT: | nvsize=48, nvalign=16] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/ms-x86-size-alignment-fail.cpp
// RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts %s 2>/dev/null \ // RUN: | FileCheck %s // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts %s 2>/dev/null \ // RUN: | FileCheck %s -check-prefix CHECK-X64 extern "C" int printf(const char *fmt, ...); struct B0 { char a; B0() : a(0xB0) {} }; struct __declspec(align(1)) B1 {}; struct A : virtual B0 {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct A // CHECK-NEXT: 0 | (A vbtable pointer) // CHECK-NEXT: 4 | struct B0 (virtual base) // CHECK-NEXT: 4 | char a // CHECK-NEXT: | [sizeof=5, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct A // CHECK-X64-NEXT: 0 | (A vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 (virtual base) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct __declspec(align(1)) B : virtual B0 {}; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct B // CHECK-NEXT: 0 | (B vbtable pointer) // CHECK-NEXT: 4 | struct B0 (virtual base) // CHECK-NEXT: 4 | char a // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct B // CHECK-X64-NEXT: 0 | (B vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 (virtual base) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct C : virtual B0 { int a; C() : a(0xC) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct C // CHECK-NEXT: 0 | (C vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | char a // CHECK-NEXT: | [sizeof=9, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct C // CHECK-X64-NEXT: 0 | (C vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct D : virtual B0 { __declspec(align(1)) int a; D() : a(0xD) {} }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct D // CHECK-NEXT: 0 | (D vbtable pointer) // CHECK-NEXT: 4 | int a // CHECK-NEXT: 8 | struct B0 (virtual base) // CHECK-NEXT: 8 | char a // CHECK-NEXT: | [sizeof=12, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct D // CHECK-X64-NEXT: 0 | (D vbtable pointer) // CHECK-X64-NEXT: 8 | int a // CHECK-X64-NEXT: 16 | struct B0 (virtual base) // CHECK-X64-NEXT: 16 | char a // CHECK-X64-NEXT: | [sizeof=24, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] struct E : virtual B0, virtual B1 {}; // CHECK: *** Dumping AST Record Layout // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct E // CHECK-NEXT: 0 | (E vbtable pointer) // CHECK-NEXT: 4 | struct B0 (virtual base) // CHECK-NEXT: 4 | char a // CHECK-NEXT: 5 | struct B1 (virtual base) (empty) // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=4, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct E // CHECK-X64-NEXT: 0 | (E vbtable pointer) // CHECK-X64-NEXT: 8 | struct B0 (virtual base) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: 9 | struct B1 (virtual base) (empty) // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=8, nvalign=8] struct F { char a; virtual ~F(); }; // CHECK: *** Dumping AST Record Layout // CHECK-NEXT: 0 | struct F // CHECK-NEXT: 0 | (F vftable pointer) // CHECK-NEXT: 4 | char a // CHECK-NEXT: | [sizeof=8, align=4 // CHECK-NEXT: | nvsize=8, nvalign=4] // CHECK-X64: *** Dumping AST Record Layout // CHECK-X64-NEXT: 0 | struct F // CHECK-X64-NEXT: 0 | (F vftable pointer) // CHECK-X64-NEXT: 8 | char a // CHECK-X64-NEXT: | [sizeof=16, align=8 // CHECK-X64-NEXT: | nvsize=16, nvalign=8] int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ sizeof(E)+ sizeof(F)];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Layout/itanium-union-bitfield.cpp
// RUN: %clang_cc1 -emit-llvm-only -triple %itanium_abi_triple -fdump-record-layouts %s 2>/dev/null \ // RUN: | FileCheck %s union A { int f1: 3; A(); }; A::A() {} union B { char f1: 35; B(); }; B::B() {} // CHECK:*** Dumping AST Record Layout // CHECK-NEXT: 0 | union A // CHECK-NEXT: 0 | int f1 // CHECK-NEXT: | [sizeof=4, dsize=1, align=4 // CHECK-NEXT: | nvsize=1, nvalign=4] // CHECK:*** Dumping AST Record Layout // CHECK-NEXT: 0 | union B // CHECK-NEXT: 0 | char f1 // CHECK-NEXT: | [sizeof=8, dsize=5, align=4 // CHECK-NEXT: | nvsize=5, nvalign=4]
0
repos/DirectXShaderCompiler/tools/clang/cmake
repos/DirectXShaderCompiler/tools/clang/cmake/modules/ClangConfig.cmake
# This file allows users to call find_package(Clang) and pick up our targets. # Clang doesn't have any CMake configuration settings yet because it mostly # uses LLVM's. When it does, we should move this file to ClangConfig.cmake.in # and call configure_file() on it. # Provide all our library targets to users. include("${CMAKE_CURRENT_LIST_DIR}/ClangTargets.cmake")
0
repos/DirectXShaderCompiler/tools/clang
repos/DirectXShaderCompiler/tools/clang/tools/CMakeLists.txt
add_subdirectory(driver) # add_subdirectory(clang-format) # HLSL Change # add_subdirectory(clang-format-vs) # HLSL Change # add_subdirectory(clang-fuzzer) # HLSL Change # add_subdirectory(c-index-test) # HLSL Change add_subdirectory(libclang) if(0 AND CLANG_ENABLE_ARCMT) # HLSL Change add_subdirectory(arcmt-test) add_subdirectory(c-arcmt-test) endif() if(CLANG_ENABLE_STATIC_ANALYZER) add_subdirectory(clang-check) endif() # We support checking out the clang-tools-extra repository into the 'extra' # subdirectory. It contains tools developed as part of the Clang/LLVM project # on top of the Clang tooling platform. We keep them in a separate repository # to keep the primary Clang repository small and focused. # It also may be included by LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR. add_llvm_external_project(clang-tools-extra extra) # HLSL Change Starts add_subdirectory(dxcompiler) add_subdirectory(dxclib) add_subdirectory(dxc) add_subdirectory(dxcvalidator) add_subdirectory(dxa) add_subdirectory(dxopt) add_subdirectory(dxl) add_subdirectory(dxr) add_subdirectory(dxv) # These targets can currently only be built on Windows. if (MSVC) add_subdirectory(d3dcomp) add_subdirectory(dxrfallbackcompiler) add_subdirectory(dxlib-sample) # UI powered by .NET. add_subdirectory(dotnetc) endif (MSVC) # HLSL Change Ends
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxv/dxv.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxv.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides the entry point for the dxv console program. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/Global.h" #include "dxc/Support/Unicode.h" #include "dxc/Support/WinIncludes.h" #include "dxc/DxilContainer/DxilContainer.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/dxcapi.use.h" #include "dxc/dxcapi.h" #include "dxc/dxcapi.internal.h" #include "llvm/Support//MSFileSystem.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" using namespace dxc; using namespace llvm; using namespace llvm::opt; using namespace hlsl::options; static cl::opt<bool> Help("help", cl::desc("Print help")); static cl::alias Help_h("h", cl::aliasopt(Help)); static cl::alias Help_q("?", cl::aliasopt(Help)); static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input dxil file>")); static cl::opt<std::string> OutputFilename("o", cl::desc("Override output filename for signed container"), cl::value_desc("filename")); class DxvContext { private: DxcDllSupport &m_dxcSupport; public: DxvContext(DxcDllSupport &dxcSupport) : m_dxcSupport(dxcSupport) {} void Validate(); }; void DxvContext::Validate() { { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); bool bSourceIsDxilContainer = hlsl::IsValidDxilContainer( hlsl::IsDxilContainerLike(pSource->GetBufferPointer(), pSource->GetBufferSize()), pSource->GetBufferSize()); hlsl::DxilContainerHash origHash = {}; CComPtr<IDxcBlob> pContainerBlob; if (bSourceIsDxilContainer) { pContainerBlob = pSource; const hlsl::DxilContainerHeader *pHeader = hlsl::IsDxilContainerLike( pSource->GetBufferPointer(), pSource->GetBufferSize()); // Copy hash into origHash memcpy(&origHash, &pHeader->Hash, sizeof(hlsl::DxilContainerHash)); } else { // Otherwise assume assembly to container is required. CComPtr<IDxcAssembler> pAssembler; CComPtr<IDxcOperationResult> pAsmResult; HRESULT resultStatus; IFT(m_dxcSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler)); IFT(pAssembler->AssembleToContainer(pSource, &pAsmResult)); IFT(pAsmResult->GetStatus(&resultStatus)); if (FAILED(resultStatus)) { CComPtr<IDxcBlobEncoding> text; IFT(pAsmResult->GetErrorBuffer(&text)); const char *pStart = (const char *)text->GetBufferPointer(); std::string msg(pStart); IFTMSG(resultStatus, msg); return; } IFT(pAsmResult->GetResult(&pContainerBlob)); } CComPtr<IDxcValidator> pValidator; CComPtr<IDxcOperationResult> pResult; IFT(m_dxcSupport.CreateInstance(CLSID_DxcValidator, &pValidator)); IFT(pValidator->Validate(pContainerBlob, DxcValidatorFlags_InPlaceEdit, &pResult)); HRESULT status; IFT(pResult->GetStatus(&status)); if (FAILED(status)) { CComPtr<IDxcBlobEncoding> text; IFT(pResult->GetErrorBuffer(&text)); const char *pStart = (const char *)text->GetBufferPointer(); std::string msg(pStart); IFTMSG(status, msg); } else { // Source was unsigned DxilContainer, write signed container if it's now // signed: if (!OutputFilename.empty()) { if (bSourceIsDxilContainer) { const hlsl::DxilContainerHeader *pHeader = hlsl::IsDxilContainerLike( pSource->GetBufferPointer(), pSource->GetBufferSize()); WriteBlobToFile(pSource, StringRefWide(OutputFilename), CP_ACP); if (memcmp(&pHeader->Hash, &origHash, sizeof(hlsl::DxilContainerHash)) != 0) { printf("Signed DxilContainer written to \"%s\"\n", OutputFilename.c_str()); } else { printf("Unchanged DxilContainer written to \"%s\"\n", OutputFilename.c_str()); } } else { printf("Source was not a DxilContainer, no output file written.\n"); } } printf("Validation succeeded."); } } } #ifdef _WIN32 int __cdecl main(int argc, const char **argv) { #else int main(int argc, const char **argv) { #endif const char *pStage = "Operation"; if (llvm::sys::fs::SetupPerThreadFileSystem()) return 1; llvm::sys::fs::AutoCleanupPerThreadFileSystem auto_cleanup_fs; if (FAILED(DxcInitThreadMalloc())) return 1; DxcSetThreadMallocToDefault(); try { llvm::sys::fs::MSFileSystem *msfPtr; IFT(CreateMSFileSystemForDisk(&msfPtr)); std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr); ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get()); IFTLLVM(pts.error_code()); pStage = "Argument processing"; // Parse command line options. cl::ParseCommandLineOptions(argc, argv, "dxil validator\n"); if (InputFilename == "" || Help) { cl::PrintHelpMessage(); return 2; } DxcDllSupport dxcSupport; dxc::EnsureEnabled(dxcSupport); DxvContext context(dxcSupport); pStage = "Validation"; context.Validate(); } catch (const ::hlsl::Exception &hlslException) { try { const char *msg = hlslException.what(); Unicode::acp_char printBuffer[128]; // printBuffer is safe to treat as // UTF-8 because we use ASCII only // errors only if (msg == nullptr || *msg == '\0') { sprintf_s(printBuffer, _countof(printBuffer), "Validation failed - error code 0x%08x.", hlslException.hr); msg = printBuffer; } printf("%s\n", msg); } catch (...) { printf("%s failed - unable to retrieve error message.\n", pStage); } return 1; } catch (std::bad_alloc &) { printf("%s failed - out of memory.\n", pStage); return 1; } catch (...) { printf("%s failed - unknown error.\n", pStage); return 1; } return 0; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxv/CMakeLists.txt
# Copyright (C) Microsoft Corporation. All rights reserved. # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. # Builds dxv.exe set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} dxcsupport Option # option library MSSupport # for CreateMSFileSystemForDisk dxilcontainer ) add_clang_executable(dxv dxv.cpp ) target_link_libraries(dxv dxcompiler ) set_target_properties(dxv PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION}) add_dependencies(dxv dxcompiler) if(UNIX) set(CLANGXX_LINK_OR_COPY create_symlink) # Create a relative symlink set(dxv_binary "dxv${CMAKE_EXECUTABLE_SUFFIX}") else() set(CLANGXX_LINK_OR_COPY copy) set(dxv_binary "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/dxv${CMAKE_EXECUTABLE_SUFFIX}") endif() install(TARGETS dxv RUNTIME DESTINATION bin)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxv/dxv.rc
// Copyright (c) Microsoft Corporation. All rights reserved. // #include <windows.h> #include <ntverp.h> #define VER_FILETYPE VFT_DLL #define VER_FILESUBTYPE VFT_UNKNOWN #define VER_FILEDESCRIPTION_STR "DX Validator" #define VER_INTERNALNAME_STR "DX Validator" #define VER_ORIGINALFILENAME_STR "dxv.exe" #include <common.ver>
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-check/CMakeLists.txt
set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} Option Support ) add_clang_executable(clang-check ClangCheck.cpp ) target_link_libraries(clang-check clangAST clangBasic clangDriver clangFrontend clangRewriteFrontend clangStaticAnalyzerFrontend clangTooling ) install(TARGETS clang-check RUNTIME DESTINATION bin)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-check/ClangCheck.cpp
//===--- tools/clang-check/ClangCheck.cpp - Clang check tool --------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements a clang-check tool that runs clang based on the info // stored in a compilation database. // // This tool uses the Clang Tooling infrastructure, see // http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html // for details on setting it up with LLVM source tree. // //===----------------------------------------------------------------------===// #include "clang/AST/ASTConsumer.h" #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" #include "clang/Driver/Options.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Rewrite/Frontend/FixItRewriter.h" #include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Option/OptTable.h" #include "llvm/Support/Path.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetSelect.h" using namespace clang::driver; using namespace clang::tooling; using namespace llvm; static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); static cl::extrahelp MoreHelp( "\tFor example, to run clang-check on all files in a subtree of the\n" "\tsource tree, use:\n" "\n" "\t find path/in/subtree -name '*.cpp'|xargs clang-check\n" "\n" "\tor using a specific build path:\n" "\n" "\t find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path\n" "\n" "\tNote, that path/in/subtree and current directory should follow the\n" "\trules described above.\n" "\n" ); static cl::OptionCategory ClangCheckCategory("clang-check options"); static std::unique_ptr<opt::OptTable> Options(createDriverOptTable()); static cl::opt<bool> ASTDump("ast-dump", cl::desc(Options->getOptionHelpText(options::OPT_ast_dump)), cl::cat(ClangCheckCategory)); static cl::opt<bool> ASTList("ast-list", cl::desc(Options->getOptionHelpText(options::OPT_ast_list)), cl::cat(ClangCheckCategory)); static cl::opt<bool> ASTPrint("ast-print", cl::desc(Options->getOptionHelpText(options::OPT_ast_print)), cl::cat(ClangCheckCategory)); static cl::opt<std::string> ASTDumpFilter( "ast-dump-filter", cl::desc(Options->getOptionHelpText(options::OPT_ast_dump_filter)), cl::cat(ClangCheckCategory)); static cl::opt<bool> Analyze("analyze", cl::desc(Options->getOptionHelpText(options::OPT_analyze)), cl::cat(ClangCheckCategory)); static cl::opt<bool> Fixit("fixit", cl::desc(Options->getOptionHelpText(options::OPT_fixit)), cl::cat(ClangCheckCategory)); static cl::opt<bool> FixWhatYouCan( "fix-what-you-can", cl::desc(Options->getOptionHelpText(options::OPT_fix_what_you_can)), cl::cat(ClangCheckCategory)); namespace { // FIXME: Move FixItRewriteInPlace from lib/Rewrite/Frontend/FrontendActions.cpp // into a header file and reuse that. class FixItOptions : public clang::FixItOptions { public: FixItOptions() { FixWhatYouCan = ::FixWhatYouCan; } std::string RewriteFilename(const std::string& filename, int &fd) override { assert(llvm::sys::path::is_absolute(filename) && "clang-fixit expects absolute paths only."); // We don't need to do permission checking here since clang will diagnose // any I/O errors itself. fd = -1; // No file descriptor for file. return filename; } }; /// \brief Subclasses \c clang::FixItRewriter to not count fixed errors/warnings /// in the final error counts. /// /// This has the side-effect that clang-check -fixit exits with code 0 on /// successfully fixing all errors. class FixItRewriter : public clang::FixItRewriter { public: FixItRewriter(clang::DiagnosticsEngine& Diags, clang::SourceManager& SourceMgr, const clang::LangOptions& LangOpts, clang::FixItOptions* FixItOpts) : clang::FixItRewriter(Diags, SourceMgr, LangOpts, FixItOpts) { } bool IncludeInDiagnosticCounts() const override { return false; } }; /// \brief Subclasses \c clang::FixItAction so that we can install the custom /// \c FixItRewriter. class FixItAction : public clang::FixItAction { public: bool BeginSourceFileAction(clang::CompilerInstance& CI, StringRef Filename) override { FixItOpts.reset(new FixItOptions); Rewriter.reset(new FixItRewriter(CI.getDiagnostics(), CI.getSourceManager(), CI.getLangOpts(), FixItOpts.get())); return true; } }; class ClangCheckActionFactory { public: std::unique_ptr<clang::ASTConsumer> newASTConsumer() { if (ASTList) return clang::CreateASTDeclNodeLister(); if (ASTDump) return clang::CreateASTDumper(ASTDumpFilter, /*DumpDecls=*/true, /*DumpLookups=*/false); if (ASTPrint) return clang::CreateASTPrinter(&llvm::outs(), ASTDumpFilter); return llvm::make_unique<clang::ASTConsumer>(); } }; } // namespace int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); // Initialize targets for clang module support. llvm::InitializeAllTargets(); llvm::InitializeAllTargetMCs(); llvm::InitializeAllAsmPrinters(); llvm::InitializeAllAsmParsers(); CommonOptionsParser OptionsParser(argc, argv, ClangCheckCategory); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); // Clear adjusters because -fsyntax-only is inserted by the default chain. Tool.clearArgumentsAdjusters(); Tool.appendArgumentsAdjuster(getClangStripOutputAdjuster()); // Running the analyzer requires --analyze. Other modes can work with the // -fsyntax-only option. Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster( Analyze ? "--analyze" : "-fsyntax-only", ArgumentInsertPosition::BEGIN)); ClangCheckActionFactory CheckFactory; std::unique_ptr<FrontendActionFactory> FrontendFactory; // Choose the correct factory based on the selected mode. if (Analyze) FrontendFactory = newFrontendActionFactory<clang::ento::AnalysisAction>(); else if (Fixit) FrontendFactory = newFrontendActionFactory<FixItAction>(); else FrontendFactory = newFrontendActionFactory(&CheckFactory); return Tool.run(FrontendFactory.get()); }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/dxlib_sample.def
LIBRARY dxlib_sample EXPORTS DxilD3DCompile=DxilD3DCompile DxilD3DCompile2=DxilD3DCompile2
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/lib_share_compile.cpp
/////////////////////////////////////////////////////////////////////////////// // // // lib_share_compile.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Compile function split shader to lib then link. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/DXIL/DxilShaderModel.h" #include "dxc/DxilContainer/DxilContainer.h" #include "dxc/Support/Global.h" #include "dxc/Support/WinIncludes.h" #include "dxc/dxcapi.h" #include "dxc/Support/FileIOHelper.h" #include "dxc/Support/Unicode.h" #include "lib_share_helper.h" #include <d3dcompiler.h> #include <string> #include <vector> using namespace libshare; using namespace hlsl; using namespace llvm; HRESULT CreateLibrary(IDxcLibrary **pLibrary) { return DxcCreateInstance(CLSID_DxcLibrary, __uuidof(IDxcLibrary), (void **)pLibrary); } HRESULT CreateCompiler(IDxcCompiler **ppCompiler) { return DxcCreateInstance(CLSID_DxcCompiler, __uuidof(IDxcCompiler), (void **)ppCompiler); } HRESULT CreateLinker(IDxcLinker **ppLinker) { return DxcCreateInstance(CLSID_DxcLinker, __uuidof(IDxcLinker), (void **)ppLinker); } HRESULT CreateContainerReflection(IDxcContainerReflection **ppReflection) { return DxcCreateInstance(CLSID_DxcContainerReflection, __uuidof(IDxcContainerReflection), (void **)ppReflection); } HRESULT CompileToLib(IDxcBlob *pSource, std::vector<DxcDefine> &defines, IDxcIncludeHandler *pInclude, std::vector<LPCWSTR> &arguments, IDxcBlob **ppCode, IDxcBlobEncoding **ppErrorMsgs) { CComPtr<IDxcCompiler> compiler; CComPtr<IDxcOperationResult> operationResult; IFR(CreateCompiler(&compiler)); IFR(compiler->Compile(pSource, L"input.hlsl", L"", L"lib_6_x", arguments.data(), (UINT)arguments.size(), defines.data(), (UINT)defines.size(), pInclude, &operationResult)); HRESULT hr; operationResult->GetStatus(&hr); if (SUCCEEDED(hr)) { return operationResult->GetResult(ppCode); } else { if (ppErrorMsgs) operationResult->GetErrorBuffer(ppErrorMsgs); return hr; } return hr; } #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/dxcapi.impl.h" static void ReadOptsAndValidate(hlsl::options::MainArgs &mainArgs, hlsl::options::DxcOpts &opts, AbstractMemoryStream *pOutputStream, IDxcOperationResult **ppResult, bool &finished) { const llvm::opt::OptTable *table = ::options::getHlslOptTable(); raw_stream_ostream outStream(pOutputStream); if (0 != hlsl::options::ReadDxcOpts(table, hlsl::options::CompilerFlags, mainArgs, opts, outStream)) { CComPtr<IDxcBlob> pErrorBlob; IFT(pOutputStream->QueryInterface(&pErrorBlob)); outStream.flush(); IFT(DxcResult::Create( E_INVALIDARG, DXC_OUT_NONE, {DxcOutputObject::ErrorOutput(opts.DefaultTextCodePage, (LPCSTR)pErrorBlob->GetBufferPointer(), pErrorBlob->GetBufferSize())}, ppResult)); finished = true; return; } DXASSERT(opts.HLSLVersion > hlsl::LangStd::v2015, "else ReadDxcOpts didn't fail for non-isense"); finished = false; } HRESULT CompileFromBlob(IDxcBlobEncoding *pSource, LPCWSTR pSourceName, std::vector<DxcDefine> &defines, IDxcIncludeHandler *pInclude, LPCSTR pEntrypoint, LPCSTR pTarget, std::vector<LPCWSTR> &arguments, IDxcOperationResult **ppOperationResult) { CComPtr<IDxcCompiler> compiler; CComPtr<IDxcLinker> linker; // Upconvert legacy targets const hlsl::ShaderModel *SM = hlsl::ShaderModel::GetByName(pTarget); const char *Target = pTarget; if (SM->IsValid() && SM->GetMajor() < 6) { Target = hlsl::ShaderModel::Get(SM->GetKind(), 6, 0)->GetName(); } HRESULT hr = S_OK; try { CA2W pEntrypointW(pEntrypoint); CA2W pTargetProfileW(Target); // Preprocess. std::unique_ptr<IncludeToLibPreprocessor> preprocessor = IncludeToLibPreprocessor::CreateIncludeToLibPreprocessor(pInclude); if (arguments.size()) { CComPtr<AbstractMemoryStream> pOutputStream; IFT(CreateMemoryStream(GetGlobalHeapMalloc(), &pOutputStream)); hlsl::options::MainArgs mainArgs(arguments.size(), arguments.data(), 0); hlsl::options::DxcOpts opts; bool finished; ReadOptsAndValidate(mainArgs, opts, pOutputStream, ppOperationResult, finished); if (finished) { return E_FAIL; } for (const llvm::opt::Arg *A : opts.Args.filtered(options::OPT_I)) { if (dxcutil::IsAbsoluteOrCurDirRelative(A->getValue())) { preprocessor->AddIncPath(A->getValue()); } else { std::string s("./"); s += A->getValue(); preprocessor->AddIncPath(s); } } } preprocessor->Preprocess(pSource, pSourceName, arguments.data(), arguments.size(), defines.data(), defines.size()); CompileInput compilerInput{defines, arguments}; LibCacheManager &libCache = LibCacheManager::GetLibCacheManager(); IFR(CreateLinker(&linker)); IDxcIncludeHandler *const kNoIncHandler = nullptr; const auto &snippets = preprocessor->GetSnippets(); std::string processedHeader = ""; std::vector<std::wstring> hashStrList; std::vector<LPCWSTR> hashList; // #define LIB_SHARE_DBG #ifdef LIB_SHARE_DBG std::vector<std::wstring> defineList; defineList.emplace_back(L""); for (auto &def : defines) { std::wstring strDef = std::wstring(L"#define ") + std::wstring(def.Name); if (def.Value) { strDef.push_back(L' '); strDef += std::wstring(def.Value); strDef.push_back(L'\n'); } defineList[0] += strDef; defineList.emplace_back(strDef); } std::string contents; std::vector<std::wstring> contentStrList; std::vector<LPCWSTR> contentList; #endif for (const auto &snippet : snippets) { CComPtr<IDxcBlob> pOutputBlob; size_t hash; #ifdef LIB_SHARE_DBG contents = processedHeader + snippet; CA2W tmpContents(contents.c_str()); contentStrList.emplace_back(tmpContents.m_psz); contentList.emplace_back(contentStrList.back().c_str()); #endif if (!libCache.GetLibBlob(processedHeader, snippet, compilerInput, hash, &pOutputBlob)) { // Cannot find existing blob, create from pSource. IDxcBlob **ppCode = &pOutputBlob; auto compileFn = [&](IDxcBlob *pSource) { IFT(CompileToLib(pSource, defines, kNoIncHandler, arguments, ppCode, nullptr)); }; libCache.AddLibBlob(processedHeader, snippet, compilerInput, hash, &pOutputBlob, compileFn); } hashStrList.emplace_back(std::to_wstring(hash)); hashList.emplace_back(hashStrList.back().c_str()); linker->RegisterLibrary(hashList.back(), pOutputBlob); pOutputBlob.Detach(); // Ownership is in libCache. } std::wstring wEntry = Unicode::UTF8ToWideStringOrThrow(pEntrypoint); std::wstring wTarget = Unicode::UTF8ToWideStringOrThrow(Target); // Link #ifdef LIB_SHARE_DBG return linker->Link(wEntry.c_str(), wTarget.c_str(), hashList.data(), hashList.size(), contentList.data(), 0, ppOperationResult); #else return linker->Link(wEntry.c_str(), wTarget.c_str(), hashList.data(), hashList.size(), nullptr, 0, ppOperationResult); #endif } CATCH_CPP_ASSIGN_HRESULT(); return hr; } HRESULT WINAPI DxilD3DCompile(LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName, const D3D_SHADER_MACRO *pDefines, IDxcIncludeHandler *pInclude, LPCSTR pEntrypoint, LPCSTR pTarget, UINT Flags1, UINT Flags2, ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs) { CComPtr<IDxcLibrary> library; CComPtr<IDxcBlobEncoding> source; CComPtr<IDxcOperationResult> operationResult; *ppCode = nullptr; if (ppErrorMsgs != nullptr) *ppErrorMsgs = nullptr; IFR(CreateLibrary(&library)); IFR(library->CreateBlobWithEncodingFromPinned(pSrcData, SrcDataSize, CP_ACP, &source)); HRESULT hr = S_OK; CComPtr<IMalloc> m_pMalloc(GetGlobalHeapMalloc()); DxcThreadMalloc TM(m_pMalloc); try { CA2W pFileName(pSourceName); std::vector<std::wstring> defineValues; std::vector<DxcDefine> defines; if (pDefines) { CONST D3D_SHADER_MACRO *pCursor = pDefines; // Convert to UTF-16. while (pCursor->Name) { defineValues.push_back(std::wstring(CA2W(pCursor->Name))); if (pCursor->Definition) defineValues.push_back(std::wstring(CA2W(pCursor->Definition))); else defineValues.push_back(std::wstring()); ++pCursor; } // Build up array. pCursor = pDefines; size_t i = 0; while (pCursor->Name) { defines.push_back( DxcDefine{defineValues[i++].c_str(), defineValues[i++].c_str()}); ++pCursor; } } std::vector<LPCWSTR> arguments; if (Flags1 & D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY) arguments.push_back(L"/Gec"); // /Ges Not implemented: // if (Flags1 & D3DCOMPILE_ENABLE_STRICTNESS) // arguments.push_back(L"/Ges"); if (Flags1 & D3DCOMPILE_IEEE_STRICTNESS) arguments.push_back(L"/Gis"); if (Flags1 & D3DCOMPILE_OPTIMIZATION_LEVEL2) { switch (Flags1 & D3DCOMPILE_OPTIMIZATION_LEVEL2) { case D3DCOMPILE_OPTIMIZATION_LEVEL0: arguments.push_back(L"/O0"); break; case D3DCOMPILE_OPTIMIZATION_LEVEL2: arguments.push_back(L"/O2"); break; case D3DCOMPILE_OPTIMIZATION_LEVEL3: arguments.push_back(L"/O3"); break; } } // Currently, /Od turns off too many optimization passes, causing incorrect // DXIL to be generated. Re-enable once /Od is implemented properly: // if(Flags1 & D3DCOMPILE_SKIP_OPTIMIZATION) arguments.push_back(L"/Od"); if (Flags1 & D3DCOMPILE_DEBUG) arguments.push_back(L"/Zi"); if (Flags1 & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR) arguments.push_back(L"/Zpr"); if (Flags1 & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR) arguments.push_back(L"/Zpc"); if (Flags1 & D3DCOMPILE_AVOID_FLOW_CONTROL) arguments.push_back(L"/Gfa"); if (Flags1 & D3DCOMPILE_PREFER_FLOW_CONTROL) arguments.push_back(L"/Gfp"); // We don't implement this: // if(Flags1 & D3DCOMPILE_PARTIAL_PRECISION) arguments.push_back(L"/Gpp"); if (Flags1 & D3DCOMPILE_RESOURCES_MAY_ALIAS) arguments.push_back(L"/res_may_alias"); CompileFromBlob(source, pFileName, defines, pInclude, pEntrypoint, pTarget, arguments, &operationResult); operationResult->GetStatus(&hr); if (SUCCEEDED(hr)) { return operationResult->GetResult((IDxcBlob **)ppCode); } else { if (ppErrorMsgs) operationResult->GetErrorBuffer((IDxcBlobEncoding **)ppErrorMsgs); return hr; } } CATCH_CPP_ASSIGN_HRESULT(); return hr; } HRESULT WINAPI DxilD3DCompile2( LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName, LPCSTR pEntrypoint, LPCSTR pTarget, const DxcDefine *pDefines, // Array of defines UINT32 defineCount, // Number of defines LPCWSTR *pArguments, // Array of pointers to arguments UINT32 argCount, // Number of arguments IDxcIncludeHandler *pInclude, IDxcOperationResult **ppOperationResult) { CComPtr<IDxcLibrary> library; CComPtr<IDxcBlobEncoding> source; *ppOperationResult = nullptr; IFR(CreateLibrary(&library)); IFR(library->CreateBlobWithEncodingFromPinned(pSrcData, SrcDataSize, CP_ACP, &source)); HRESULT hr = S_OK; CComPtr<IMalloc> m_pMalloc(GetGlobalHeapMalloc()); DxcThreadMalloc TM(m_pMalloc); try { CA2W pFileName(pSourceName); std::vector<DxcDefine> defines(pDefines, pDefines + defineCount); std::vector<LPCWSTR> arguments(pArguments, pArguments + argCount); return CompileFromBlob(source, pFileName, defines, pInclude, pEntrypoint, pTarget, arguments, ppOperationResult); } CATCH_CPP_ASSIGN_HRESULT(); return hr; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/dxlib_sample.rc
// Copyright (c) Microsoft Corporation. All rights reserved. // #include <windows.h> #include <ntverp.h> #define VER_FILETYPE VFT_DLL #define VER_FILESUBTYPE VFT_UNKNOWN #define VER_FILEDESCRIPTION_STR "DX Library Sample" #define VER_INTERNALNAME_STR "DX Library Sample" #define VER_ORIGINALFILENAME_STR "dxlib_sample.dll" #include <common.ver>
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/lib_share_helper.h
/////////////////////////////////////////////////////////////////////////////// // // // lib_share_helper.h // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Helper header for lib_shaer. // // // /////////////////////////////////////////////////////////////////////////////// #pragma once #include "llvm/ADT/StringRef.h" #include <functional> #include <memory> #include <string> #include <vector> namespace llvm { class Twine; } namespace dxcutil { bool IsAbsoluteOrCurDirRelative(const llvm::Twine &T); } namespace libshare { struct CompileInput { std::vector<DxcDefine> &defines; std::vector<LPCWSTR> &arguments; }; class LibCacheManager { public: virtual ~LibCacheManager() {} virtual HRESULT AddLibBlob(std::string &header, const std::string &snippet, CompileInput &compiler, size_t &hash, IDxcBlob **pResultLib, std::function<void(IDxcBlob *pSource)> compileFn) = 0; virtual bool GetLibBlob(std::string &processedHeader, const std::string &snippet, CompileInput &compiler, size_t &hash, IDxcBlob **pResultLib) = 0; static LibCacheManager &GetLibCacheManager(); static void ReleaseLibCacheManager(); }; class IncludeToLibPreprocessor { public: virtual ~IncludeToLibPreprocessor() {} virtual void AddIncPath(llvm::StringRef path) = 0; virtual HRESULT Preprocess(IDxcBlob *pSource, LPCWSTR pFilename, LPCWSTR *pArguments, UINT32 argCount, const DxcDefine *pDefines, unsigned defineCount) = 0; virtual const std::vector<std::string> &GetSnippets() const = 0; static std::unique_ptr<IncludeToLibPreprocessor> CreateIncludeToLibPreprocessor(IDxcIncludeHandler *handler); }; } // namespace libshare
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/CMakeLists.txt
# Copyright (C) Microsoft Corporation. All rights reserved. # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. # Build a dxlib_sample.dll as a sample for library and link. set(SOURCES ../dxcompiler/dxcfilesystem.cpp lib_cache_manager.cpp lib_share_compile.cpp lib_share_preprocessor.cpp dxlib_sample.cpp dxlib_sample.def ) set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} analysis ipa dxcsupport DXIL HLSL Option # option library Support # just for assert and raw streams ) add_clang_library(dxlib_sample SHARED ${SOURCES}) target_link_libraries(dxlib_sample PRIVATE dxcompiler ) add_dependencies(dxlib_sample dxcompiler) set_target_properties(dxlib_sample PROPERTIES OUTPUT_NAME "dxlib_sample" VERSION ${LIBCLANG_LIBRARY_VERSION})
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/dxlib_sample.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxlib_sample.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements compile function which compile shader to lib then link. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/Global.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/WinIncludes.h" #include "lib_share_helper.h" using namespace hlsl; // Overwrite new delete copy from DXCompiler.cpp // C++ exception specification ignored except to indicate a function is not // __declspec(nothrow) #pragma warning(disable : 4290) // operator new and friends. void *__CRTDECL operator new(std::size_t size) noexcept(false) { void *ptr = DxcNew(size); if (ptr == nullptr) throw std::bad_alloc(); return ptr; } void *__CRTDECL operator new(std::size_t size, const std::nothrow_t &nothrow_value) throw() { return DxcNew(size); } void __CRTDECL operator delete(void *ptr) throw() { DxcDelete(ptr); } void __CRTDECL operator delete(void *ptr, const std::nothrow_t &nothrow_constant) throw() { DxcDelete(ptr); } // Finish of new delete. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID) { BOOL result = TRUE; if (Reason == DLL_PROCESS_ATTACH) { DxcInitThreadMalloc(); DxcSetThreadMallocToDefault(); if (hlsl::options::initHlslOptTable()) { DxcClearThreadMalloc(); return FALSE; } else { DxcClearThreadMalloc(); return TRUE; } } else if (Reason == DLL_PROCESS_DETACH) { DxcSetThreadMallocToDefault(); libshare::LibCacheManager::ReleaseLibCacheManager(); ::hlsl::options::cleanupHlslOptTable(); DxcClearThreadMalloc(); DxcCleanupThreadMalloc(); } return result; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp
/////////////////////////////////////////////////////////////////////////////// // // // lib_cache_manager.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements lib blob cache manager. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/FileIOHelper.h" #include "dxc/Support/Global.h" #include "dxc/Support/WinIncludes.h" #include "dxc/dxcapi.h" #include "lib_share_helper.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/STLExtras.h" #include <mutex> #include <shared_mutex> #include <unordered_map> using namespace llvm; using namespace libshare; #include "dxc/Support/dxcapi.use.h" #include "dxc/dxctools.h" namespace { class NoFuncBodyRewriter { public: NoFuncBodyRewriter() { if (!m_dllSupport.IsEnabled()) m_dllSupport.Initialize(); m_dllSupport.CreateInstance(CLSID_DxcRewriter, &m_pRewriter); } HRESULT RewriteToNoFuncBody(LPCWSTR pFilename, IDxcBlobEncoding *pSource, std::vector<DxcDefine> &m_defines, IDxcBlob **ppNoFuncBodySource); private: CComPtr<IDxcRewriter> m_pRewriter; dxc::DxcDllSupport m_dllSupport; }; HRESULT NoFuncBodyRewriter::RewriteToNoFuncBody( LPCWSTR pFilename, IDxcBlobEncoding *pSource, std::vector<DxcDefine> &m_defines, IDxcBlob **ppNoFuncBodySource) { // Create header with no function body. CComPtr<IDxcOperationResult> pRewriteResult; IFT(m_pRewriter->RewriteUnchangedWithInclude( pSource, pFilename, m_defines.data(), m_defines.size(), // Don't need include handler here, include already read in // RewriteIncludesToSnippet nullptr, RewriterOptionMask::SkipFunctionBody | RewriterOptionMask::KeepUserMacro, &pRewriteResult)); HRESULT status; if (!SUCCEEDED(pRewriteResult->GetStatus(&status)) || !SUCCEEDED(status)) { CComPtr<IDxcBlobEncoding> pErr; IFT(pRewriteResult->GetErrorBuffer(&pErr)); std::string errString = std::string((char *)pErr->GetBufferPointer(), pErr->GetBufferSize()); IFTMSG(E_FAIL, errString); return E_FAIL; }; // Get result. IFT(pRewriteResult->GetResult(ppNoFuncBodySource)); return S_OK; } } // namespace namespace { struct KeyHash { std::size_t operator()(const hash_code &k) const { return k; } }; struct KeyEqual { bool operator()(const hash_code &l, const hash_code &r) const { return l == r; } }; class LibCacheManagerImpl : public libshare::LibCacheManager { public: ~LibCacheManagerImpl() {} HRESULT AddLibBlob(std::string &processedHeader, const std::string &snippet, CompileInput &compiler, size_t &hash, IDxcBlob **pResultLib, std::function<void(IDxcBlob *pSource)> compileFn) override; bool GetLibBlob(std::string &processedHeader, const std::string &snippet, CompileInput &compiler, size_t &hash, IDxcBlob **pResultLib) override; void Release() { m_libCache.clear(); } private: hash_code GetHash(const std::string &header, const std::string &snippet, CompileInput &compiler); using libCacheType = std::unordered_map<hash_code, CComPtr<IDxcBlob>, KeyHash, KeyEqual>; libCacheType m_libCache; using headerCacheType = std::unordered_map<hash_code, std::string, KeyHash, KeyEqual>; headerCacheType m_headerCache; std::shared_mutex m_mutex; NoFuncBodyRewriter m_rewriter; }; static hash_code CombineWStr(hash_code hash, LPCWSTR Arg) { CW2A pUtf8Arg(Arg); unsigned length = strlen(pUtf8Arg.m_psz); return hash_combine(hash, StringRef(pUtf8Arg.m_psz, length)); } hash_code LibCacheManagerImpl::GetHash(const std::string &header, const std::string &snippet, CompileInput &compiler) { hash_code libHash = hash_value(header); libHash = hash_combine(libHash, snippet); // Combine compile input. for (auto &Arg : compiler.arguments) { libHash = CombineWStr(libHash, Arg); } // snippet has been processed so don't add define to hash. return libHash; } using namespace hlsl; HRESULT LibCacheManagerImpl::AddLibBlob( std::string &processedHeader, const std::string &snippet, CompileInput &compiler, size_t &hash, IDxcBlob **pResultLib, std::function<void(IDxcBlob *pSource)> compileFn) { if (!pResultLib) { return E_FAIL; } std::unique_lock<std::shared_mutex> lk(m_mutex); auto it = m_libCache.find(hash); if (it != m_libCache.end()) { *pResultLib = it->second; DXASSERT(m_headerCache.count(hash), "else mismatch header and lib"); processedHeader = m_headerCache[hash]; return S_OK; } std::string shader = processedHeader + snippet; CComPtr<IDxcBlobEncoding> pSource; IFT(DxcCreateBlobWithEncodingOnMallocCopy( GetGlobalHeapMalloc(), shader.data(), shader.size(), CP_UTF8, &pSource)); compileFn(pSource); m_libCache[hash] = *pResultLib; // Rewrite curHeader to remove function body. CComPtr<IDxcBlob> result; IFT(m_rewriter.RewriteToNoFuncBody(L"input.hlsl", pSource, compiler.defines, &result)); processedHeader = std::string((char *)(result)->GetBufferPointer(), (result)->GetBufferSize()); m_headerCache[hash] = processedHeader; return S_OK; } bool LibCacheManagerImpl::GetLibBlob(std::string &processedHeader, const std::string &snippet, CompileInput &compiler, size_t &hash, IDxcBlob **pResultLib) { if (!pResultLib) { return false; } // Create hash from source. hash_code libHash = GetHash(processedHeader, snippet, compiler); hash = libHash; // lock std::shared_lock<std::shared_mutex> lk(m_mutex); auto it = m_libCache.find(libHash); if (it != m_libCache.end()) { *pResultLib = it->second; DXASSERT(m_headerCache.count(libHash), "else mismatch header and lib"); processedHeader = m_headerCache[libHash]; return true; } else { return false; } } LibCacheManager *GetLibCacheManagerPtr(bool bFree) { static std::unique_ptr<LibCacheManagerImpl> g_LibCache = llvm::make_unique<LibCacheManagerImpl>(); if (bFree) g_LibCache.reset(); return g_LibCache.get(); } } // namespace LibCacheManager &LibCacheManager::GetLibCacheManager() { return *GetLibCacheManagerPtr(/*bFree*/ false); } void LibCacheManager::ReleaseLibCacheManager() { GetLibCacheManagerPtr(/*bFree*/ true); }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxlib-sample/lib_share_preprocessor.cpp
/////////////////////////////////////////////////////////////////////////////// // // // lib_share_preprocessor.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements preprocessor to split shader based on include. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/FileIOHelper.h" #include "dxc/Support/Global.h" #include "dxc/Support/WinIncludes.h" #include "dxc/Support/microcom.h" #include "dxc/Support/dxcfilesystem.h" #include "lib_share_helper.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <unordered_set> using namespace libshare; using namespace hlsl; using namespace llvm; namespace dxcutil { bool IsAbsoluteOrCurDirRelative(const Twine &T) { if (llvm::sys::path::is_absolute(T)) { return true; } if (T.isSingleStringRef()) { StringRef r = T.getSingleStringRef(); if (r.size() < 2) return false; const char *pData = r.data(); return pData[0] == '.' && (pData[1] == '\\' || pData[1] == '/'); } DXASSERT(false, "twine kind not supported"); return false; } } // namespace dxcutil namespace { const StringRef file_region = "\n#pragma region\n"; class IncPathIncludeHandler : public IDxcIncludeHandler { public: DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) virtual ~IncPathIncludeHandler() {} HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override { return DoBasicQueryInterface<::IDxcIncludeHandler>(this, riid, ppvObject); } IncPathIncludeHandler(IDxcIncludeHandler *handler, std::vector<std::string> &includePathList) : m_dwRef(0), m_pIncludeHandler(handler), m_includePathList(includePathList) {} HRESULT STDMETHODCALLTYPE LoadSource( LPCWSTR pFilename, // Candidate filename. IDxcBlob **ppIncludeSource // Resultant // source object // for included // file, nullptr // if not found. ) override { CW2A pUtf8Filename(pFilename); if (m_loadedFileNames.find(pUtf8Filename.m_psz) != m_loadedFileNames.end()) { // Already include this file. // Just return empty content. static const char kEmptyStr[] = " "; CComPtr<IDxcBlobEncoding> pEncodingIncludeSource; IFT(DxcCreateBlobWithEncodingOnMalloc(kEmptyStr, GetGlobalHeapMalloc(), 1, CP_UTF8, &pEncodingIncludeSource)); *ppIncludeSource = pEncodingIncludeSource.Detach(); return S_OK; } // Read file. CComPtr<IDxcBlob> pIncludeSource; if (m_includePathList.empty()) { IFT(m_pIncludeHandler->LoadSource(pFilename, ppIncludeSource)); } else { bool bLoaded = false; // Not support same filename in different directory. for (std::string &path : m_includePathList) { std::string tmpFilenameStr = path + StringRef(pUtf8Filename.m_psz).str(); CA2W pWTmpFilename(tmpFilenameStr.c_str()); if (S_OK == m_pIncludeHandler->LoadSource(pWTmpFilename.m_psz, ppIncludeSource)) { bLoaded = true; break; } } if (!bLoaded) { IFT(m_pIncludeHandler->LoadSource(pFilename, ppIncludeSource)); } } CComPtr<IDxcBlobUtf8> utf8Source; IFT(hlsl::DxcGetBlobAsUtf8(*ppIncludeSource, DxcGetThreadMallocNoRef(), &utf8Source)); StringRef Data(utf8Source->GetStringPointer(), utf8Source->GetStringLength()); std::string strRegionData = (Twine(file_region) + Data + file_region).str(); CComPtr<IDxcBlobEncoding> pEncodingIncludeSource; IFT(DxcCreateBlobWithEncodingOnMallocCopy( GetGlobalHeapMalloc(), strRegionData.c_str(), strRegionData.size(), CP_UTF8, &pEncodingIncludeSource)); *ppIncludeSource = pEncodingIncludeSource.Detach(); m_loadedFileNames.insert(pUtf8Filename.m_psz); return S_OK; } private: DXC_MICROCOM_REF_FIELD(m_dwRef) IDxcIncludeHandler *m_pIncludeHandler; std::unordered_set<std::string> m_loadedFileNames; std::vector<std::string> &m_includePathList; }; } // namespace HRESULT CreateCompiler(IDxcCompiler **ppCompiler); namespace { class IncludeToLibPreprocessorImpl : public IncludeToLibPreprocessor { public: virtual ~IncludeToLibPreprocessorImpl() {} IncludeToLibPreprocessorImpl(IDxcIncludeHandler *handler) : m_pIncludeHandler(handler) {} void AddIncPath(StringRef path) override; HRESULT Preprocess(IDxcBlob *pSource, LPCWSTR pFilename, LPCWSTR *pArguments, UINT32 argCount, const DxcDefine *pDefines, unsigned defineCount) override; const std::vector<std::string> &GetSnippets() const override { return m_snippets; } private: HRESULT SplitShaderIntoSnippets(IDxcBlob *pSource); IDxcIncludeHandler *m_pIncludeHandler; // Snippets split by #include. std::vector<std::string> m_snippets; std::vector<std::string> m_includePathList; }; HRESULT IncludeToLibPreprocessorImpl::SplitShaderIntoSnippets(IDxcBlob *pSource) { CComPtr<IDxcBlobUtf8> utf8Source; IFT(hlsl::DxcGetBlobAsUtf8(pSource, DxcGetThreadMallocNoRef(), &utf8Source)); StringRef Data(utf8Source->GetStringPointer(), utf8Source->GetStringLength()); SmallVector<StringRef, 8> splitResult; Data.split(splitResult, file_region, /*maxSplit*/ -1, /*keepEmpty*/ false); for (StringRef snippet : splitResult) { m_snippets.emplace_back(snippet); } return S_OK; } void IncludeToLibPreprocessorImpl::AddIncPath(StringRef path) { m_includePathList.emplace_back(path); } HRESULT IncludeToLibPreprocessorImpl::Preprocess( IDxcBlob *pSource, LPCWSTR pFilename, LPCWSTR *pArguments, UINT32 argCount, const DxcDefine *pDefines, unsigned defineCount) { std::string s, warnings; raw_string_ostream o(s); raw_string_ostream w(warnings); CW2A pUtf8Name(pFilename); IncPathIncludeHandler incPathIncludeHandler(m_pIncludeHandler, m_includePathList); // AddRef to hold incPathIncludeHandler. // If not, DxcArgsFileSystem will kill it. incPathIncludeHandler.AddRef(); CComPtr<IDxcCompiler> compiler; CComPtr<IDxcOperationResult> pPreprocessResult; IFR(CreateCompiler(&compiler)); IFR(compiler->Preprocess(pSource, L"input.hlsl", pArguments, argCount, pDefines, defineCount, &incPathIncludeHandler, &pPreprocessResult)); HRESULT status; IFT(pPreprocessResult->GetStatus(&status)); if (SUCCEEDED(status)) { CComPtr<IDxcBlob> pProgram; IFT(pPreprocessResult->GetResult(&pProgram)); IFT(SplitShaderIntoSnippets(pProgram)); } return S_OK; } } // namespace std::unique_ptr<IncludeToLibPreprocessor> IncludeToLibPreprocessor::CreateIncludeToLibPreprocessor( IDxcIncludeHandler *handler) { return llvm::make_unique<IncludeToLibPreprocessorImpl>(handler); }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/diag-build/diag-build.sh
#!/bin/bash # diag-build: a tool showing enabled warnings in a project. # # diag-build acts as a wrapper for 'diagtool show-enabled', in the same way # that scan-build acts as a wrapper for the static analyzer. The common case is # simple: use 'diag-build make' or 'diag-build xcodebuild' to list the warnings # enabled for the first compilation command we see. Other build systems require # you to manually specify "dry-run" and "use $CC and $CXX"; if there is a build # system you are interested in, please add it to the switch statement. print_usage () { echo 'Usage: diag-build.sh [-v] xcodebuild [flags]' echo ' diag-build.sh [-v] make [flags]' echo ' diag-build.sh [-v] <other build command>' echo echo 'diagtool must be in your PATH' echo 'If using an alternate build command, you must ensure that' echo 'the compiler used matches the CC environment variable.' } # Mac OS X's BSD sed uses -E for extended regular expressions, # but GNU sed uses -r. Find out which one this system accepts. EXTENDED_SED_FLAG='-E' echo -n | sed $EXTENDED_SED_FLAG 's/a/b/' 2>/dev/null || EXTENDED_SED_FLAG='-r' if [[ "$1" == "-v" ]]; then verbose=$1 shift fi guessing_cc=0 if [[ -z "$CC" ]]; then guessing_cc=1 if [[ -x $(dirname $0)/clang ]]; then CC=$(dirname $0)/clang elif [[ ! -z $(which clang) ]]; then CC=$(which clang) else echo -n 'Error: could not find an appropriate compiler' echo ' to generate build commands.' 1>&2 echo 'Use the CC environment variable to set one explicitly.' 1>&2 exit 1 fi fi if [[ -z "$CXX" ]]; then if [[ -x $(dirname $0)/clang++ ]]; then CXX=$(dirname $0)/clang++ elif [[ ! -z $(which clang++) ]]; then CXX=$(which clang++) else CXX=$CC fi fi diagtool=$(which diagtool) if [[ -z "$diagtool" ]]; then if [[ -x $(dirname $0)/diagtool ]]; then diagtool=$(dirname $0)/diagtool else echo 'Error: could not find diagtool.' 1>&2 exit 1 fi fi tool=$1 shift if [[ -z "$tool" ]]; then print_usage exit 1 elif [[ "$tool" == "xcodebuild" ]]; then dry_run='-dry-run' set_compiler="CC='$CC' CXX='$CXX'" elif [[ "$tool" == "make" ]]; then dry_run='-n' set_compiler="CC='$CC' CXX='$CXX'" else echo "Warning: unknown build system '$tool'" 1>&2 if [[ $guessing_cc -eq 1 ]]; then # FIXME: We really only need $CC /or/ $CXX echo 'Error: $CC must be set for other build systems' 1>&2 exit 1 fi fi escape () { echo $@ | sed 's:[]:\\|/.+*?^$(){}[]:\\&:g' } escCC=$(escape $CC) escCXX=$(escape $CXX) command=$( eval $tool $dry_run $set_compiler $@ 2>/dev/null | # Remove "if" early on so we can find the right command line. sed $EXTENDED_SED_FLAG "s:^[[:blank:]]*if[[:blank:]]{1,}::g" | # Combine lines with trailing backslashes sed -e :a -e '/\\$/N; s/\\\n//; ta' | grep -E "^[[:blank:]]*($escCC|$escCXX)" | head -n1 | sed $EXTENDED_SED_FLAG "s:($escCC|$escCXX):${diagtool//:/\\:} show-enabled:g" ) if [[ -z "$command" ]]; then echo 'Error: could not find any build commands.' 1>&2 if [[ "$tool" != "xcodebuild" ]]; then # xcodebuild always echoes the compile commands on their own line, # but other tools give no such guarantees. echo -n 'This may occur if your build system embeds the call to ' 2>&1 echo -n 'the compiler in a larger expression. ' 2>&1 fi exit 2 fi # Chop off trailing '&&', '||', and ';' command=${command%%&&*} command=${command%%||*} command=${command%%;*} [[ -n "$verbose" ]] && echo $command eval $command
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxr/dxr.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxr.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides the entry point for the dxr console program. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/Global.h" #include "dxc/Support/Unicode.h" #include "dxc/Support/WinFunctions.h" #include "dxc/Support/WinIncludes.h" #include "dxc/Support/microcom.h" #include "dxclib/dxc.h" #include <string> #include <vector> #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/WinFunctions.h" #include "dxc/Support/dxcapi.use.h" #include "dxc/dxcapi.h" #include "dxc/dxctools.h" #include "llvm/Support/raw_ostream.h" inline bool wcsieq(LPCWSTR a, LPCWSTR b) { return _wcsicmp(a, b) == 0; } using namespace dxc; using namespace llvm::opt; using namespace hlsl::options; #ifdef _WIN32 int __cdecl wmain(int argc, const wchar_t **argv_) { #else int main(int argc, const char **argv) { // Convert argv to wchar. WArgV ArgV(argc, argv); const wchar_t **argv_ = ArgV.argv(); #endif if (FAILED(DxcInitThreadMalloc())) return 1; DxcSetThreadMallocToDefault(); try { if (initHlslOptTable()) throw std::bad_alloc(); // Parse command line options. const OptTable *optionTable = getHlslOptTable(); MainArgs argStrings(argc, argv_); DxcOpts dxcOpts; DxcDllSupport dxcSupport; // Read options and check errors. { std::string errorString; llvm::raw_string_ostream errorStream(errorString); int optResult = ReadDxcOpts(optionTable, DxrFlags, argStrings, dxcOpts, errorStream); errorStream.flush(); if (errorString.size()) { fprintf(stderr, "dxc failed : %s\n", errorString.data()); } if (optResult != 0) { return optResult; } } // Apply defaults. if (dxcOpts.EntryPoint.empty() && !dxcOpts.RecompileFromBinary) { dxcOpts.EntryPoint = "main"; } // Setup a helper DLL. { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); int dllResult = SetupDxcDllSupport(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); } if (dllResult) return dllResult; } EnsureEnabled(dxcSupport); // Handle help request, which overrides any other processing. if (dxcOpts.ShowHelp) { std::string helpString; llvm::raw_string_ostream helpStream(helpString); std::string version; llvm::raw_string_ostream versionStream(version); WriteDxCompilerVersionInfo( versionStream, dxcOpts.ExternalLib.empty() ? (LPCSTR) nullptr : dxcOpts.ExternalLib.data(), dxcOpts.ExternalFn.empty() ? (LPCSTR) nullptr : dxcOpts.ExternalFn.data(), dxcSupport); versionStream.flush(); optionTable->PrintHelp(helpStream, "dxr.exe", "HLSL Rewriter", version.c_str(), hlsl::options::RewriteOption, (dxcOpts.ShowHelpHidden ? 0 : HelpHidden)); helpStream.flush(); WriteUtf8ToConsoleSizeT(helpString.data(), helpString.size()); return 0; } if (dxcOpts.ShowVersion) { std::string version; llvm::raw_string_ostream versionStream(version); WriteDxCompilerVersionInfo( versionStream, dxcOpts.ExternalLib.empty() ? (LPCSTR) nullptr : dxcOpts.ExternalLib.data(), dxcOpts.ExternalFn.empty() ? (LPCSTR) nullptr : dxcOpts.ExternalFn.data(), dxcSupport); versionStream.flush(); WriteUtf8ToConsoleSizeT(version.data(), version.size()); return 0; } CComPtr<IDxcRewriter2> pRewriter; CComPtr<IDxcOperationResult> pRewriteResult; CComPtr<IDxcBlobEncoding> pSource; std::wstring wName( CA2W(dxcOpts.InputFile.empty() ? "" : dxcOpts.InputFile.data())); if (!dxcOpts.InputFile.empty()) ReadFileIntoBlob(dxcSupport, wName.c_str(), &pSource); CComPtr<IDxcLibrary> pLibrary; CComPtr<IDxcIncludeHandler> pIncludeHandler; IFT(dxcSupport.CreateInstance(CLSID_DxcLibrary, &pLibrary)); IFT(pLibrary->CreateIncludeHandler(&pIncludeHandler)); IFT(dxcSupport.CreateInstance(CLSID_DxcRewriter, &pRewriter)); IFT(pRewriter->RewriteWithOptions(pSource, wName.c_str(), argv_, argc, nullptr, 0, pIncludeHandler, &pRewriteResult)); if (dxcOpts.OutputObject.empty()) { // No -Fo, print to console WriteOperationResultToConsole(pRewriteResult, !dxcOpts.OutputWarnings); } else { WriteOperationErrorsToConsole(pRewriteResult, !dxcOpts.OutputWarnings); HRESULT hr; IFT(pRewriteResult->GetStatus(&hr)); if (SUCCEEDED(hr)) { CA2W wOutputObject(dxcOpts.OutputObject.data()); CComPtr<IDxcBlob> pObject; IFT(pRewriteResult->GetResult(&pObject)); WriteBlobToFile(pObject, wOutputObject.m_psz, dxcOpts.DefaultTextCodePage); printf("Rewrite output: %s", dxcOpts.OutputObject.data()); } } } catch (const ::hlsl::Exception &hlslException) { try { const char *msg = hlslException.what(); Unicode::acp_char printBuffer[128]; // printBuffer is safe to treat as UTF-8 because we // use ASCII contents only if (msg == nullptr || *msg == '\0') { sprintf_s(printBuffer, _countof(printBuffer), "Compilation failed - error code 0x%08x.", hlslException.hr); msg = printBuffer; } std::string textMessage; bool lossy; if (!Unicode::UTF8ToConsoleString(msg, &textMessage, &lossy) || lossy) { // Do a direct assignment as a last-ditch effort and print out as UTF-8. textMessage = msg; } printf("%s\n", textMessage.c_str()); } catch (...) { printf("Compilation failed - unable to retrieve error message.\n"); } return 1; } catch (std::bad_alloc &) { printf("Compilation failed - out of memory.\n"); return 1; } catch (...) { printf("Compilation failed - unable to retrieve error message.\n"); return 1; } return 0; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxr/CMakeLists.txt
# Copyright (C) Microsoft Corporation. All rights reserved. # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. # Builds dxr.exe set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} dxcsupport Option # option library Support # For Atomic increment/decrement ) add_clang_executable(dxr dxr.cpp # dxr.rc ) target_link_libraries(dxr dxclib dxcompiler ) set_target_properties(dxr PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION}) # set_target_properties(dxr PROPERTIES ENABLE_EXPORTS 1) include_directories(${LLVM_SOURCE_DIR}/tools/clang/tools) add_dependencies(dxr dxclib dxcompiler) if(UNIX) set(CLANGXX_LINK_OR_COPY create_symlink) # Create a relative symlink set(dxr_binary "dxr${CMAKE_EXECUTABLE_SUFFIX}") else() set(CLANGXX_LINK_OR_COPY copy) set(dxr_binary "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/dxr${CMAKE_EXECUTABLE_SUFFIX}") endif() install(TARGETS dxr RUNTIME DESTINATION bin)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxr/dxr.rc
// Copyright (c) Microsoft Corporation. All rights reserved. // #include <windows.h> #include <ntverp.h> #define VER_FILETYPE VFT_DLL #define VER_FILESUBTYPE VFT_UNKNOWN #define VER_FILEDESCRIPTION_STR "DX Rewriter" #define VER_INTERNALNAME_STR "DX Rewriter" #define VER_ORIGINALFILENAME_STR "dxr.exe" #include <common.ver>
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/c-index-test/CMakeLists.txt
add_clang_executable(c-index-test c-index-test.c ) if(NOT MSVC) set_property( SOURCE c-index-test.c PROPERTY COMPILE_FLAGS "-std=gnu89" ) endif() if (LLVM_BUILD_STATIC) target_link_libraries(c-index-test libclang_static ) else() target_link_libraries(c-index-test libclang ) endif() set_target_properties(c-index-test PROPERTIES LINKER_LANGUAGE CXX) # If libxml2 is available, make it available for c-index-test. if (CLANG_HAVE_LIBXML) include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR}) target_link_libraries(c-index-test ${LIBXML2_LIBRARIES}) endif()
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/c-index-test/c-index-test.c
/* c-index-test.c */ #include "clang/Config/config.h" #include "clang-c/Index.h" #include "clang-c/CXCompilationDatabase.h" #include "clang-c/BuildSystem.h" #include "clang-c/Documentation.h" #include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <assert.h> #ifdef CLANG_HAVE_LIBXML #include <libxml/parser.h> #include <libxml/relaxng.h> #include <libxml/xmlerror.h> #endif #ifdef _WIN32 # include <direct.h> #else # include <unistd.h> #endif /******************************************************************************/ /* Utility functions. */ /******************************************************************************/ #ifdef _MSC_VER char *basename(const char* path) { char* base1 = (char*)strrchr(path, '/'); char* base2 = (char*)strrchr(path, '\\'); if (base1 && base2) return((base1 > base2) ? base1 + 1 : base2 + 1); else if (base1) return(base1 + 1); else if (base2) return(base2 + 1); return((char*)path); } char *dirname(char* path) { char* base1 = (char*)strrchr(path, '/'); char* base2 = (char*)strrchr(path, '\\'); if (base1 && base2) if (base1 > base2) *base1 = 0; else *base2 = 0; else if (base1) *base1 = 0; else if (base2) *base2 = 0; return path; } #else extern char *basename(const char *); extern char *dirname(char *); #endif /** \brief Return the default parsing options. */ static unsigned getDefaultParsingOptions() { unsigned options = CXTranslationUnit_DetailedPreprocessingRecord; if (getenv("CINDEXTEST_EDITING")) options |= clang_defaultEditingTranslationUnitOptions(); if (getenv("CINDEXTEST_COMPLETION_CACHING")) options |= CXTranslationUnit_CacheCompletionResults; if (getenv("CINDEXTEST_COMPLETION_NO_CACHING")) options &= ~CXTranslationUnit_CacheCompletionResults; if (getenv("CINDEXTEST_SKIP_FUNCTION_BODIES")) options |= CXTranslationUnit_SkipFunctionBodies; if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS")) options |= CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; return options; } /** \brief Returns 0 in case of success, non-zero in case of a failure. */ static int checkForErrors(CXTranslationUnit TU); static void describeLibclangFailure(enum CXErrorCode Err) { switch (Err) { case CXError_Success: fprintf(stderr, "Success\n"); return; case CXError_Failure: fprintf(stderr, "Failure (no details available)\n"); return; case CXError_Crashed: fprintf(stderr, "Failure: libclang crashed\n"); return; case CXError_InvalidArguments: fprintf(stderr, "Failure: invalid arguments passed to a libclang routine\n"); return; case CXError_ASTReadError: fprintf(stderr, "Failure: AST deserialization error occurred\n"); return; } } static void PrintExtent(FILE *out, unsigned begin_line, unsigned begin_column, unsigned end_line, unsigned end_column) { fprintf(out, "[%d:%d - %d:%d]", begin_line, begin_column, end_line, end_column); } static unsigned CreateTranslationUnit(CXIndex Idx, const char *file, CXTranslationUnit *TU) { enum CXErrorCode Err = clang_createTranslationUnit2(Idx, file, TU); if (Err != CXError_Success) { fprintf(stderr, "Unable to load translation unit from '%s'!\n", file); describeLibclangFailure(Err); *TU = 0; return 0; } return 1; } void free_remapped_files(struct CXUnsavedFile *unsaved_files, int num_unsaved_files) { int i; for (i = 0; i != num_unsaved_files; ++i) { free((char *)unsaved_files[i].Filename); free((char *)unsaved_files[i].Contents); } free(unsaved_files); } static int parse_remapped_files_with_opt(const char *opt_name, int argc, const char **argv, int start_arg, struct CXUnsavedFile **unsaved_files, int *num_unsaved_files) { int i; int arg; int prefix_len = strlen(opt_name); int arg_indices[20]; *unsaved_files = 0; *num_unsaved_files = 0; /* Count the number of remapped files. */ for (arg = start_arg; arg < argc; ++arg) { if (strncmp(argv[arg], opt_name, prefix_len)) continue; assert(*num_unsaved_files < (int)(sizeof(arg_indices)/sizeof(int))); arg_indices[*num_unsaved_files] = arg; ++*num_unsaved_files; } if (*num_unsaved_files == 0) return 0; *unsaved_files = (struct CXUnsavedFile *)malloc(sizeof(struct CXUnsavedFile) * *num_unsaved_files); for (i = 0; i != *num_unsaved_files; ++i) { struct CXUnsavedFile *unsaved = *unsaved_files + i; const char *arg_string = argv[arg_indices[i]] + prefix_len; int filename_len; char *filename; char *contents; FILE *to_file; const char *sep = strchr(arg_string, ','); if (!sep) { fprintf(stderr, "error: %sfrom:to argument is missing comma\n", opt_name); free_remapped_files(*unsaved_files, i); *unsaved_files = 0; *num_unsaved_files = 0; return -1; } /* Open the file that we're remapping to. */ to_file = fopen(sep + 1, "rb"); if (!to_file) { fprintf(stderr, "error: cannot open file %s that we are remapping to\n", sep + 1); free_remapped_files(*unsaved_files, i); *unsaved_files = 0; *num_unsaved_files = 0; return -1; } /* Determine the length of the file we're remapping to. */ fseek(to_file, 0, SEEK_END); unsaved->Length = ftell(to_file); fseek(to_file, 0, SEEK_SET); /* Read the contents of the file we're remapping to. */ contents = (char *)malloc(unsaved->Length + 1); if (fread(contents, 1, unsaved->Length, to_file) != unsaved->Length) { fprintf(stderr, "error: unexpected %s reading 'to' file %s\n", (feof(to_file) ? "EOF" : "error"), sep + 1); fclose(to_file); free_remapped_files(*unsaved_files, i); free(contents); *unsaved_files = 0; *num_unsaved_files = 0; return -1; } contents[unsaved->Length] = 0; unsaved->Contents = contents; /* Close the file. */ fclose(to_file); /* Copy the file name that we're remapping from. */ filename_len = sep - arg_string; filename = (char *)malloc(filename_len + 1); memcpy(filename, arg_string, filename_len); filename[filename_len] = 0; unsaved->Filename = filename; } return 0; } static int parse_remapped_files(int argc, const char **argv, int start_arg, struct CXUnsavedFile **unsaved_files, int *num_unsaved_files) { return parse_remapped_files_with_opt("-remap-file=", argc, argv, start_arg, unsaved_files, num_unsaved_files); } static int parse_remapped_files_with_try(int try_idx, int argc, const char **argv, int start_arg, struct CXUnsavedFile **unsaved_files, int *num_unsaved_files) { struct CXUnsavedFile *unsaved_files_no_try_idx; int num_unsaved_files_no_try_idx; struct CXUnsavedFile *unsaved_files_try_idx; int num_unsaved_files_try_idx; int ret; char opt_name[32]; ret = parse_remapped_files(argc, argv, start_arg, &unsaved_files_no_try_idx, &num_unsaved_files_no_try_idx); if (ret) return ret; sprintf(opt_name, "-remap-file-%d=", try_idx); ret = parse_remapped_files_with_opt(opt_name, argc, argv, start_arg, &unsaved_files_try_idx, &num_unsaved_files_try_idx); if (ret) return ret; if (num_unsaved_files_no_try_idx == 0) { *unsaved_files = unsaved_files_try_idx; *num_unsaved_files = num_unsaved_files_try_idx; return 0; } if (num_unsaved_files_try_idx == 0) { *unsaved_files = unsaved_files_no_try_idx; *num_unsaved_files = num_unsaved_files_no_try_idx; return 0; } *num_unsaved_files = num_unsaved_files_no_try_idx + num_unsaved_files_try_idx; *unsaved_files = (struct CXUnsavedFile *)realloc(unsaved_files_no_try_idx, sizeof(struct CXUnsavedFile) * *num_unsaved_files); memcpy(*unsaved_files + num_unsaved_files_no_try_idx, unsaved_files_try_idx, sizeof(struct CXUnsavedFile) * num_unsaved_files_try_idx); free(unsaved_files_try_idx); return 0; } static const char *parse_comments_schema(int argc, const char **argv) { const char *CommentsSchemaArg = "-comments-xml-schema="; const char *CommentSchemaFile = NULL; if (argc == 0) return CommentSchemaFile; if (!strncmp(argv[0], CommentsSchemaArg, strlen(CommentsSchemaArg))) CommentSchemaFile = argv[0] + strlen(CommentsSchemaArg); return CommentSchemaFile; } /******************************************************************************/ /* Pretty-printing. */ /******************************************************************************/ static const char *FileCheckPrefix = "CHECK"; static void PrintCString(const char *CStr) { if (CStr != NULL && CStr[0] != '\0') { for ( ; *CStr; ++CStr) { const char C = *CStr; switch (C) { case '\n': printf("\\n"); break; case '\r': printf("\\r"); break; case '\t': printf("\\t"); break; case '\v': printf("\\v"); break; case '\f': printf("\\f"); break; default: putchar(C); break; } } } } static void PrintCStringWithPrefix(const char *Prefix, const char *CStr) { printf(" %s=[", Prefix); PrintCString(CStr); printf("]"); } static void PrintCXStringAndDispose(CXString Str) { PrintCString(clang_getCString(Str)); clang_disposeString(Str); } static void PrintCXStringWithPrefix(const char *Prefix, CXString Str) { PrintCStringWithPrefix(Prefix, clang_getCString(Str)); } static void PrintCXStringWithPrefixAndDispose(const char *Prefix, CXString Str) { PrintCStringWithPrefix(Prefix, clang_getCString(Str)); clang_disposeString(Str); } static void PrintRange(CXSourceRange R, const char *str) { CXFile begin_file, end_file; unsigned begin_line, begin_column, end_line, end_column; clang_getSpellingLocation(clang_getRangeStart(R), &begin_file, &begin_line, &begin_column, 0); clang_getSpellingLocation(clang_getRangeEnd(R), &end_file, &end_line, &end_column, 0); if (!begin_file || !end_file) return; if (str) printf(" %s=", str); PrintExtent(stdout, begin_line, begin_column, end_line, end_column); } int want_display_name = 0; static void printVersion(const char *Prefix, CXVersion Version) { if (Version.Major < 0) return; printf("%s%d", Prefix, Version.Major); if (Version.Minor < 0) return; printf(".%d", Version.Minor); if (Version.Subminor < 0) return; printf(".%d", Version.Subminor); } struct CommentASTDumpingContext { int IndentLevel; }; static void DumpCXCommentInternal(struct CommentASTDumpingContext *Ctx, CXComment Comment) { unsigned i; unsigned e; enum CXCommentKind Kind = clang_Comment_getKind(Comment); Ctx->IndentLevel++; for (i = 0, e = Ctx->IndentLevel; i != e; ++i) printf(" "); printf("("); switch (Kind) { case CXComment_Null: printf("CXComment_Null"); break; case CXComment_Text: printf("CXComment_Text"); PrintCXStringWithPrefixAndDispose("Text", clang_TextComment_getText(Comment)); if (clang_Comment_isWhitespace(Comment)) printf(" IsWhitespace"); if (clang_InlineContentComment_hasTrailingNewline(Comment)) printf(" HasTrailingNewline"); break; case CXComment_InlineCommand: printf("CXComment_InlineCommand"); PrintCXStringWithPrefixAndDispose( "CommandName", clang_InlineCommandComment_getCommandName(Comment)); switch (clang_InlineCommandComment_getRenderKind(Comment)) { case CXCommentInlineCommandRenderKind_Normal: printf(" RenderNormal"); break; case CXCommentInlineCommandRenderKind_Bold: printf(" RenderBold"); break; case CXCommentInlineCommandRenderKind_Monospaced: printf(" RenderMonospaced"); break; case CXCommentInlineCommandRenderKind_Emphasized: printf(" RenderEmphasized"); break; } for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment); i != e; ++i) { printf(" Arg[%u]=", i); PrintCXStringAndDispose( clang_InlineCommandComment_getArgText(Comment, i)); } if (clang_InlineContentComment_hasTrailingNewline(Comment)) printf(" HasTrailingNewline"); break; case CXComment_HTMLStartTag: { unsigned NumAttrs; printf("CXComment_HTMLStartTag"); PrintCXStringWithPrefixAndDispose( "Name", clang_HTMLTagComment_getTagName(Comment)); NumAttrs = clang_HTMLStartTag_getNumAttrs(Comment); if (NumAttrs != 0) { printf(" Attrs:"); for (i = 0; i != NumAttrs; ++i) { printf(" "); PrintCXStringAndDispose(clang_HTMLStartTag_getAttrName(Comment, i)); printf("="); PrintCXStringAndDispose(clang_HTMLStartTag_getAttrValue(Comment, i)); } } if (clang_HTMLStartTagComment_isSelfClosing(Comment)) printf(" SelfClosing"); if (clang_InlineContentComment_hasTrailingNewline(Comment)) printf(" HasTrailingNewline"); break; } case CXComment_HTMLEndTag: printf("CXComment_HTMLEndTag"); PrintCXStringWithPrefixAndDispose( "Name", clang_HTMLTagComment_getTagName(Comment)); if (clang_InlineContentComment_hasTrailingNewline(Comment)) printf(" HasTrailingNewline"); break; case CXComment_Paragraph: printf("CXComment_Paragraph"); if (clang_Comment_isWhitespace(Comment)) printf(" IsWhitespace"); break; case CXComment_BlockCommand: printf("CXComment_BlockCommand"); PrintCXStringWithPrefixAndDispose( "CommandName", clang_BlockCommandComment_getCommandName(Comment)); for (i = 0, e = clang_BlockCommandComment_getNumArgs(Comment); i != e; ++i) { printf(" Arg[%u]=", i); PrintCXStringAndDispose( clang_BlockCommandComment_getArgText(Comment, i)); } break; case CXComment_ParamCommand: printf("CXComment_ParamCommand"); switch (clang_ParamCommandComment_getDirection(Comment)) { case CXCommentParamPassDirection_In: printf(" in"); break; case CXCommentParamPassDirection_Out: printf(" out"); break; case CXCommentParamPassDirection_InOut: printf(" in,out"); break; } if (clang_ParamCommandComment_isDirectionExplicit(Comment)) printf(" explicitly"); else printf(" implicitly"); PrintCXStringWithPrefixAndDispose( "ParamName", clang_ParamCommandComment_getParamName(Comment)); if (clang_ParamCommandComment_isParamIndexValid(Comment)) printf(" ParamIndex=%u", clang_ParamCommandComment_getParamIndex(Comment)); else printf(" ParamIndex=Invalid"); break; case CXComment_TParamCommand: printf("CXComment_TParamCommand"); PrintCXStringWithPrefixAndDispose( "ParamName", clang_TParamCommandComment_getParamName(Comment)); if (clang_TParamCommandComment_isParamPositionValid(Comment)) { printf(" ParamPosition={"); for (i = 0, e = clang_TParamCommandComment_getDepth(Comment); i != e; ++i) { printf("%u", clang_TParamCommandComment_getIndex(Comment, i)); if (i != e - 1) printf(", "); } printf("}"); } else printf(" ParamPosition=Invalid"); break; case CXComment_VerbatimBlockCommand: printf("CXComment_VerbatimBlockCommand"); PrintCXStringWithPrefixAndDispose( "CommandName", clang_BlockCommandComment_getCommandName(Comment)); break; case CXComment_VerbatimBlockLine: printf("CXComment_VerbatimBlockLine"); PrintCXStringWithPrefixAndDispose( "Text", clang_VerbatimBlockLineComment_getText(Comment)); break; case CXComment_VerbatimLine: printf("CXComment_VerbatimLine"); PrintCXStringWithPrefixAndDispose( "Text", clang_VerbatimLineComment_getText(Comment)); break; case CXComment_FullComment: printf("CXComment_FullComment"); break; } if (Kind != CXComment_Null) { const unsigned NumChildren = clang_Comment_getNumChildren(Comment); unsigned i; for (i = 0; i != NumChildren; ++i) { printf("\n// %s: ", FileCheckPrefix); DumpCXCommentInternal(Ctx, clang_Comment_getChild(Comment, i)); } } printf(")"); Ctx->IndentLevel--; } static void DumpCXComment(CXComment Comment) { struct CommentASTDumpingContext Ctx; Ctx.IndentLevel = 1; printf("\n// %s: CommentAST=[\n// %s:", FileCheckPrefix, FileCheckPrefix); DumpCXCommentInternal(&Ctx, Comment); printf("]"); } static void ValidateCommentXML(const char *Str, const char *CommentSchemaFile) { #ifdef CLANG_HAVE_LIBXML xmlRelaxNGParserCtxtPtr RNGParser; xmlRelaxNGPtr Schema; xmlDocPtr Doc; xmlRelaxNGValidCtxtPtr ValidationCtxt; int status; if (!CommentSchemaFile) return; RNGParser = xmlRelaxNGNewParserCtxt(CommentSchemaFile); if (!RNGParser) { printf(" libXMLError"); return; } Schema = xmlRelaxNGParse(RNGParser); Doc = xmlParseDoc((const xmlChar *) Str); if (!Doc) { xmlErrorPtr Error = xmlGetLastError(); printf(" CommentXMLInvalid [not well-formed XML: %s]", Error->message); return; } ValidationCtxt = xmlRelaxNGNewValidCtxt(Schema); status = xmlRelaxNGValidateDoc(ValidationCtxt, Doc); if (!status) printf(" CommentXMLValid"); else if (status > 0) { xmlErrorPtr Error = xmlGetLastError(); printf(" CommentXMLInvalid [not vaild XML: %s]", Error->message); } else printf(" libXMLError"); xmlRelaxNGFreeValidCtxt(ValidationCtxt); xmlFreeDoc(Doc); xmlRelaxNGFree(Schema); xmlRelaxNGFreeParserCtxt(RNGParser); #endif } static void PrintCursorComments(CXCursor Cursor, const char *CommentSchemaFile) { { CXString RawComment; const char *RawCommentCString; CXString BriefComment; const char *BriefCommentCString; RawComment = clang_Cursor_getRawCommentText(Cursor); RawCommentCString = clang_getCString(RawComment); if (RawCommentCString != NULL && RawCommentCString[0] != '\0') { PrintCStringWithPrefix("RawComment", RawCommentCString); PrintRange(clang_Cursor_getCommentRange(Cursor), "RawCommentRange"); BriefComment = clang_Cursor_getBriefCommentText(Cursor); BriefCommentCString = clang_getCString(BriefComment); if (BriefCommentCString != NULL && BriefCommentCString[0] != '\0') PrintCStringWithPrefix("BriefComment", BriefCommentCString); clang_disposeString(BriefComment); } clang_disposeString(RawComment); } { CXComment Comment = clang_Cursor_getParsedComment(Cursor); if (clang_Comment_getKind(Comment) != CXComment_Null) { PrintCXStringWithPrefixAndDispose("FullCommentAsHTML", clang_FullComment_getAsHTML(Comment)); { CXString XML; XML = clang_FullComment_getAsXML(Comment); PrintCXStringWithPrefix("FullCommentAsXML", XML); ValidateCommentXML(clang_getCString(XML), CommentSchemaFile); clang_disposeString(XML); } DumpCXComment(Comment); } } } typedef struct { unsigned line; unsigned col; } LineCol; static int lineCol_cmp(const void *p1, const void *p2) { const LineCol *lhs = p1; const LineCol *rhs = p2; if (lhs->line != rhs->line) return (int)lhs->line - (int)rhs->line; return (int)lhs->col - (int)rhs->col; } static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor); if (clang_isInvalid(Cursor.kind)) { CXString ks = clang_getCursorKindSpelling(Cursor.kind); printf("Invalid Cursor => %s", clang_getCString(ks)); clang_disposeString(ks); } else { CXString string, ks; CXCursor Referenced; unsigned line, column; CXCursor SpecializationOf; CXCursor *overridden; unsigned num_overridden; unsigned RefNameRangeNr; CXSourceRange CursorExtent; CXSourceRange RefNameRange; int AlwaysUnavailable; int AlwaysDeprecated; CXString UnavailableMessage; CXString DeprecatedMessage; CXPlatformAvailability PlatformAvailability[2]; int NumPlatformAvailability; int I; ks = clang_getCursorKindSpelling(Cursor.kind); string = want_display_name? clang_getCursorDisplayName(Cursor) : clang_getCursorSpelling(Cursor); printf("%s=%s", clang_getCString(ks), clang_getCString(string)); clang_disposeString(ks); clang_disposeString(string); Referenced = clang_getCursorReferenced(Cursor); if (!clang_equalCursors(Referenced, clang_getNullCursor())) { if (clang_getCursorKind(Referenced) == CXCursor_OverloadedDeclRef) { unsigned I, N = clang_getNumOverloadedDecls(Referenced); printf("["); for (I = 0; I != N; ++I) { CXCursor Ovl = clang_getOverloadedDecl(Referenced, I); CXSourceLocation Loc; if (I) printf(", "); Loc = clang_getCursorLocation(Ovl); clang_getSpellingLocation(Loc, 0, &line, &column, 0); printf("%d:%d", line, column); } printf("]"); } else { CXSourceLocation Loc = clang_getCursorLocation(Referenced); clang_getSpellingLocation(Loc, 0, &line, &column, 0); printf(":%d:%d", line, column); } } if (clang_isCursorDefinition(Cursor)) printf(" (Definition)"); switch (clang_getCursorAvailability(Cursor)) { case CXAvailability_Available: break; case CXAvailability_Deprecated: printf(" (deprecated)"); break; case CXAvailability_NotAvailable: printf(" (unavailable)"); break; case CXAvailability_NotAccessible: printf(" (inaccessible)"); break; } NumPlatformAvailability = clang_getCursorPlatformAvailability(Cursor, &AlwaysDeprecated, &DeprecatedMessage, &AlwaysUnavailable, &UnavailableMessage, PlatformAvailability, 2); if (AlwaysUnavailable) { printf(" (always unavailable: \"%s\")", clang_getCString(UnavailableMessage)); } else if (AlwaysDeprecated) { printf(" (always deprecated: \"%s\")", clang_getCString(DeprecatedMessage)); } else { for (I = 0; I != NumPlatformAvailability; ++I) { if (I >= 2) break; printf(" (%s", clang_getCString(PlatformAvailability[I].Platform)); if (PlatformAvailability[I].Unavailable) printf(", unavailable"); else { printVersion(", introduced=", PlatformAvailability[I].Introduced); printVersion(", deprecated=", PlatformAvailability[I].Deprecated); printVersion(", obsoleted=", PlatformAvailability[I].Obsoleted); } if (clang_getCString(PlatformAvailability[I].Message)[0]) printf(", message=\"%s\"", clang_getCString(PlatformAvailability[I].Message)); printf(")"); } } for (I = 0; I != NumPlatformAvailability; ++I) { if (I >= 2) break; clang_disposeCXPlatformAvailability(PlatformAvailability + I); } clang_disposeString(DeprecatedMessage); clang_disposeString(UnavailableMessage); if (clang_CXXMethod_isStatic(Cursor)) printf(" (static)"); if (clang_CXXMethod_isVirtual(Cursor)) printf(" (virtual)"); if (clang_CXXMethod_isConst(Cursor)) printf(" (const)"); if (clang_CXXMethod_isPureVirtual(Cursor)) printf(" (pure)"); if (clang_Cursor_isVariadic(Cursor)) printf(" (variadic)"); if (clang_Cursor_isObjCOptional(Cursor)) printf(" (@optional)"); if (Cursor.kind == CXCursor_IBOutletCollectionAttr) { CXType T = clang_getCanonicalType(clang_getIBOutletCollectionType(Cursor)); CXString S = clang_getTypeKindSpelling(T.kind); printf(" [IBOutletCollection=%s]", clang_getCString(S)); clang_disposeString(S); } if (Cursor.kind == CXCursor_CXXBaseSpecifier) { enum CX_CXXAccessSpecifier access = clang_getCXXAccessSpecifier(Cursor); unsigned isVirtual = clang_isVirtualBase(Cursor); const char *accessStr = 0; switch (access) { case CX_CXXInvalidAccessSpecifier: accessStr = "invalid"; break; case CX_CXXPublic: accessStr = "public"; break; case CX_CXXProtected: accessStr = "protected"; break; case CX_CXXPrivate: accessStr = "private"; break; } printf(" [access=%s isVirtual=%s]", accessStr, isVirtual ? "true" : "false"); } SpecializationOf = clang_getSpecializedCursorTemplate(Cursor); if (!clang_equalCursors(SpecializationOf, clang_getNullCursor())) { CXSourceLocation Loc = clang_getCursorLocation(SpecializationOf); CXString Name = clang_getCursorSpelling(SpecializationOf); clang_getSpellingLocation(Loc, 0, &line, &column, 0); printf(" [Specialization of %s:%d:%d]", clang_getCString(Name), line, column); clang_disposeString(Name); if (Cursor.kind == CXCursor_FunctionDecl) { /* Collect the template parameter kinds from the base template. */ unsigned NumTemplateArgs = clang_Cursor_getNumTemplateArguments(Cursor); unsigned I; for (I = 0; I < NumTemplateArgs; I++) { enum CXTemplateArgumentKind TAK = clang_Cursor_getTemplateArgumentKind(Cursor, I); switch(TAK) { case CXTemplateArgumentKind_Type: { CXType T = clang_Cursor_getTemplateArgumentType(Cursor, I); CXString S = clang_getTypeSpelling(T); printf(" [Template arg %d: kind: %d, type: %s]", I, TAK, clang_getCString(S)); clang_disposeString(S); } break; case CXTemplateArgumentKind_Integral: printf(" [Template arg %d: kind: %d, intval: %lld]", I, TAK, clang_Cursor_getTemplateArgumentValue(Cursor, I)); break; default: printf(" [Template arg %d: kind: %d]\n", I, TAK); } } } } clang_getOverriddenCursors(Cursor, &overridden, &num_overridden); if (num_overridden) { unsigned I; LineCol lineCols[50]; assert(num_overridden <= 50); printf(" [Overrides "); for (I = 0; I != num_overridden; ++I) { CXSourceLocation Loc = clang_getCursorLocation(overridden[I]); clang_getSpellingLocation(Loc, 0, &line, &column, 0); lineCols[I].line = line; lineCols[I].col = column; } /* Make the order of the override list deterministic. */ qsort(lineCols, num_overridden, sizeof(LineCol), lineCol_cmp); for (I = 0; I != num_overridden; ++I) { if (I) printf(", "); printf("@%d:%d", lineCols[I].line, lineCols[I].col); } printf("]"); clang_disposeOverriddenCursors(overridden); } if (Cursor.kind == CXCursor_InclusionDirective) { CXFile File = clang_getIncludedFile(Cursor); CXString Included = clang_getFileName(File); printf(" (%s)", clang_getCString(Included)); clang_disposeString(Included); if (clang_isFileMultipleIncludeGuarded(TU, File)) printf(" [multi-include guarded]"); } CursorExtent = clang_getCursorExtent(Cursor); RefNameRange = clang_getCursorReferenceNameRange(Cursor, CXNameRange_WantQualifier | CXNameRange_WantSinglePiece | CXNameRange_WantTemplateArgs, 0); if (!clang_equalRanges(CursorExtent, RefNameRange)) PrintRange(RefNameRange, "SingleRefName"); for (RefNameRangeNr = 0; 1; RefNameRangeNr++) { RefNameRange = clang_getCursorReferenceNameRange(Cursor, CXNameRange_WantQualifier | CXNameRange_WantTemplateArgs, RefNameRangeNr); if (clang_equalRanges(clang_getNullRange(), RefNameRange)) break; if (!clang_equalRanges(CursorExtent, RefNameRange)) PrintRange(RefNameRange, "RefName"); } PrintCursorComments(Cursor, CommentSchemaFile); { unsigned PropAttrs = clang_Cursor_getObjCPropertyAttributes(Cursor, 0); if (PropAttrs != CXObjCPropertyAttr_noattr) { printf(" ["); #define PRINT_PROP_ATTR(A) \ if (PropAttrs & CXObjCPropertyAttr_##A) printf(#A ",") PRINT_PROP_ATTR(readonly); PRINT_PROP_ATTR(getter); PRINT_PROP_ATTR(assign); PRINT_PROP_ATTR(readwrite); PRINT_PROP_ATTR(retain); PRINT_PROP_ATTR(copy); PRINT_PROP_ATTR(nonatomic); PRINT_PROP_ATTR(setter); PRINT_PROP_ATTR(atomic); PRINT_PROP_ATTR(weak); PRINT_PROP_ATTR(strong); PRINT_PROP_ATTR(unsafe_unretained); printf("]"); } } { unsigned QT = clang_Cursor_getObjCDeclQualifiers(Cursor); if (QT != CXObjCDeclQualifier_None) { printf(" ["); #define PRINT_OBJC_QUAL(A) \ if (QT & CXObjCDeclQualifier_##A) printf(#A ",") PRINT_OBJC_QUAL(In); PRINT_OBJC_QUAL(Inout); PRINT_OBJC_QUAL(Out); PRINT_OBJC_QUAL(Bycopy); PRINT_OBJC_QUAL(Byref); PRINT_OBJC_QUAL(Oneway); printf("]"); } } } } static const char* GetCursorSource(CXCursor Cursor) { CXSourceLocation Loc = clang_getCursorLocation(Cursor); CXString source; CXFile file; clang_getExpansionLocation(Loc, &file, 0, 0, 0); source = clang_getFileName(file); if (!clang_getCString(source)) { clang_disposeString(source); return "<invalid loc>"; } else { const char *b = basename(clang_getCString(source)); clang_disposeString(source); return b; } } /******************************************************************************/ /* Callbacks. */ /******************************************************************************/ typedef void (*PostVisitTU)(CXTranslationUnit); void PrintDiagnostic(CXDiagnostic Diagnostic) { FILE *out = stderr; CXFile file; CXString Msg; unsigned display_opts = CXDiagnostic_DisplaySourceLocation | CXDiagnostic_DisplayColumn | CXDiagnostic_DisplaySourceRanges | CXDiagnostic_DisplayOption; unsigned i, num_fixits; if (clang_getDiagnosticSeverity(Diagnostic) == CXDiagnostic_Ignored) return; Msg = clang_formatDiagnostic(Diagnostic, display_opts); fprintf(stderr, "%s\n", clang_getCString(Msg)); clang_disposeString(Msg); clang_getSpellingLocation(clang_getDiagnosticLocation(Diagnostic), &file, 0, 0, 0); if (!file) return; num_fixits = clang_getDiagnosticNumFixIts(Diagnostic); fprintf(stderr, "Number FIX-ITs = %d\n", num_fixits); for (i = 0; i != num_fixits; ++i) { CXSourceRange range; CXString insertion_text = clang_getDiagnosticFixIt(Diagnostic, i, &range); CXSourceLocation start = clang_getRangeStart(range); CXSourceLocation end = clang_getRangeEnd(range); unsigned start_line, start_column, end_line, end_column; CXFile start_file, end_file; clang_getSpellingLocation(start, &start_file, &start_line, &start_column, 0); clang_getSpellingLocation(end, &end_file, &end_line, &end_column, 0); if (clang_equalLocations(start, end)) { /* Insertion. */ if (start_file == file) fprintf(out, "FIX-IT: Insert \"%s\" at %d:%d\n", clang_getCString(insertion_text), start_line, start_column); } else if (strcmp(clang_getCString(insertion_text), "") == 0) { /* Removal. */ if (start_file == file && end_file == file) { fprintf(out, "FIX-IT: Remove "); PrintExtent(out, start_line, start_column, end_line, end_column); fprintf(out, "\n"); } } else { /* Replacement. */ if (start_file == end_file) { fprintf(out, "FIX-IT: Replace "); PrintExtent(out, start_line, start_column, end_line, end_column); fprintf(out, " with \"%s\"\n", clang_getCString(insertion_text)); } } clang_disposeString(insertion_text); } } void PrintDiagnosticSet(CXDiagnosticSet Set) { int i = 0, n = clang_getNumDiagnosticsInSet(Set); for ( ; i != n ; ++i) { CXDiagnostic Diag = clang_getDiagnosticInSet(Set, i); CXDiagnosticSet ChildDiags = clang_getChildDiagnostics(Diag); PrintDiagnostic(Diag); if (ChildDiags) PrintDiagnosticSet(ChildDiags); } } void PrintDiagnostics(CXTranslationUnit TU) { CXDiagnosticSet TUSet = clang_getDiagnosticSetFromTU(TU); PrintDiagnosticSet(TUSet); clang_disposeDiagnosticSet(TUSet); } void PrintMemoryUsage(CXTranslationUnit TU) { unsigned long total = 0; unsigned i = 0; CXTUResourceUsage usage = clang_getCXTUResourceUsage(TU); fprintf(stderr, "Memory usage:\n"); for (i = 0 ; i != usage.numEntries; ++i) { const char *name = clang_getTUResourceUsageName(usage.entries[i].kind); unsigned long amount = usage.entries[i].amount; total += amount; fprintf(stderr, " %s : %ld bytes (%f MBytes)\n", name, amount, ((double) amount)/(1024*1024)); } fprintf(stderr, " TOTAL = %ld bytes (%f MBytes)\n", total, ((double) total)/(1024*1024)); clang_disposeCXTUResourceUsage(usage); } /******************************************************************************/ /* Logic for testing traversal. */ /******************************************************************************/ static void PrintCursorExtent(CXCursor C) { CXSourceRange extent = clang_getCursorExtent(C); PrintRange(extent, "Extent"); } /* Data used by the visitors. */ typedef struct { CXTranslationUnit TU; enum CXCursorKind *Filter; const char *CommentSchemaFile; } VisitorData; enum CXChildVisitResult FilteredPrintingVisitor(CXCursor Cursor, CXCursor Parent, CXClientData ClientData) { VisitorData *Data = (VisitorData *)ClientData; if (!Data->Filter || (Cursor.kind == *(enum CXCursorKind *)Data->Filter)) { CXSourceLocation Loc = clang_getCursorLocation(Cursor); unsigned line, column; clang_getSpellingLocation(Loc, 0, &line, &column, 0); printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Cursor), line, column); PrintCursor(Cursor, Data->CommentSchemaFile); PrintCursorExtent(Cursor); if (clang_isDeclaration(Cursor.kind)) { enum CX_CXXAccessSpecifier access = clang_getCXXAccessSpecifier(Cursor); const char *accessStr = 0; switch (access) { case CX_CXXInvalidAccessSpecifier: break; case CX_CXXPublic: accessStr = "public"; break; case CX_CXXProtected: accessStr = "protected"; break; case CX_CXXPrivate: accessStr = "private"; break; } if (accessStr) printf(" [access=%s]", accessStr); } printf("\n"); return CXChildVisit_Recurse; } return CXChildVisit_Continue; } static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor, CXCursor Parent, CXClientData ClientData) { const char *startBuf, *endBuf; unsigned startLine, startColumn, endLine, endColumn, curLine, curColumn; CXCursor Ref; VisitorData *Data = (VisitorData *)ClientData; if (Cursor.kind != CXCursor_FunctionDecl || !clang_isCursorDefinition(Cursor)) return CXChildVisit_Continue; clang_getDefinitionSpellingAndExtent(Cursor, &startBuf, &endBuf, &startLine, &startColumn, &endLine, &endColumn); /* Probe the entire body, looking for both decls and refs. */ curLine = startLine; curColumn = startColumn; while (startBuf < endBuf) { CXSourceLocation Loc; CXFile file; CXString source; if (*startBuf == '\n') { startBuf++; curLine++; curColumn = 1; } else if (*startBuf != '\t') curColumn++; Loc = clang_getCursorLocation(Cursor); clang_getSpellingLocation(Loc, &file, 0, 0, 0); source = clang_getFileName(file); if (clang_getCString(source)) { CXSourceLocation RefLoc = clang_getLocation(Data->TU, file, curLine, curColumn); Ref = clang_getCursor(Data->TU, RefLoc); if (Ref.kind == CXCursor_NoDeclFound) { /* Nothing found here; that's fine. */ } else if (Ref.kind != CXCursor_FunctionDecl) { printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Ref), curLine, curColumn); PrintCursor(Ref, Data->CommentSchemaFile); printf("\n"); } } clang_disposeString(source); startBuf++; } return CXChildVisit_Continue; } /******************************************************************************/ /* USR testing. */ /******************************************************************************/ enum CXChildVisitResult USRVisitor(CXCursor C, CXCursor parent, CXClientData ClientData) { VisitorData *Data = (VisitorData *)ClientData; if (!Data->Filter || (C.kind == *(enum CXCursorKind *)Data->Filter)) { CXString USR = clang_getCursorUSR(C); const char *cstr = clang_getCString(USR); if (!cstr || cstr[0] == '\0') { clang_disposeString(USR); return CXChildVisit_Recurse; } printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C), cstr); PrintCursorExtent(C); printf("\n"); clang_disposeString(USR); return CXChildVisit_Recurse; } return CXChildVisit_Continue; } /******************************************************************************/ /* Inclusion stack testing. */ /******************************************************************************/ void InclusionVisitor(CXFile includedFile, CXSourceLocation *includeStack, unsigned includeStackLen, CXClientData data) { unsigned i; CXString fname; fname = clang_getFileName(includedFile); printf("file: %s\nincluded by:\n", clang_getCString(fname)); clang_disposeString(fname); for (i = 0; i < includeStackLen; ++i) { CXFile includingFile; unsigned line, column; clang_getSpellingLocation(includeStack[i], &includingFile, &line, &column, 0); fname = clang_getFileName(includingFile); printf(" %s:%d:%d\n", clang_getCString(fname), line, column); clang_disposeString(fname); } printf("\n"); } void PrintInclusionStack(CXTranslationUnit TU) { clang_getInclusions(TU, InclusionVisitor, NULL); } /******************************************************************************/ /* Linkage testing. */ /******************************************************************************/ static enum CXChildVisitResult PrintLinkage(CXCursor cursor, CXCursor p, CXClientData d) { const char *linkage = 0; if (clang_isInvalid(clang_getCursorKind(cursor))) return CXChildVisit_Recurse; switch (clang_getCursorLinkage(cursor)) { case CXLinkage_Invalid: break; case CXLinkage_NoLinkage: linkage = "NoLinkage"; break; case CXLinkage_Internal: linkage = "Internal"; break; case CXLinkage_UniqueExternal: linkage = "UniqueExternal"; break; case CXLinkage_External: linkage = "External"; break; } if (linkage) { PrintCursor(cursor, NULL); printf("linkage=%s\n", linkage); } return CXChildVisit_Recurse; } /******************************************************************************/ /* Typekind testing. */ /******************************************************************************/ static void PrintTypeAndTypeKind(CXType T, const char *Format) { CXString TypeSpelling, TypeKindSpelling; TypeSpelling = clang_getTypeSpelling(T); TypeKindSpelling = clang_getTypeKindSpelling(T.kind); printf(Format, clang_getCString(TypeSpelling), clang_getCString(TypeKindSpelling)); clang_disposeString(TypeSpelling); clang_disposeString(TypeKindSpelling); } static enum CXVisitorResult FieldVisitor(CXCursor C, CXClientData client_data) { (*(int *) client_data)+=1; return CXVisit_Continue; } static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, CXClientData d) { if (!clang_isInvalid(clang_getCursorKind(cursor))) { CXType T = clang_getCursorType(cursor); enum CXRefQualifierKind RQ = clang_Type_getCXXRefQualifier(T); PrintCursor(cursor, NULL); PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]"); if (clang_isConstQualifiedType(T)) printf(" const"); if (clang_isVolatileQualifiedType(T)) printf(" volatile"); if (clang_isRestrictQualifiedType(T)) printf(" restrict"); if (RQ == CXRefQualifier_LValue) printf(" lvalue-ref-qualifier"); if (RQ == CXRefQualifier_RValue) printf(" rvalue-ref-qualifier"); /* Print the canonical type if it is different. */ { CXType CT = clang_getCanonicalType(T); if (!clang_equalTypes(T, CT)) { PrintTypeAndTypeKind(CT, " [canonicaltype=%s] [canonicaltypekind=%s]"); } } /* Print the return type if it exists. */ { CXType RT = clang_getCursorResultType(cursor); if (RT.kind != CXType_Invalid) { PrintTypeAndTypeKind(RT, " [resulttype=%s] [resulttypekind=%s]"); } } /* Print the argument types if they exist. */ { int NumArgs = clang_Cursor_getNumArguments(cursor); if (NumArgs != -1 && NumArgs != 0) { int i; printf(" [args="); for (i = 0; i < NumArgs; ++i) { CXType T = clang_getCursorType(clang_Cursor_getArgument(cursor, i)); if (T.kind != CXType_Invalid) { PrintTypeAndTypeKind(T, " [%s] [%s]"); } } printf("]"); } } /* Print the template argument types if they exist. */ { int NumTArgs = clang_Type_getNumTemplateArguments(T); if (NumTArgs != -1 && NumTArgs != 0) { int i; printf(" [templateargs/%d=", NumTArgs); for (i = 0; i < NumTArgs; ++i) { CXType TArg = clang_Type_getTemplateArgumentAsType(T, i); if (TArg.kind != CXType_Invalid) { PrintTypeAndTypeKind(TArg, " [type=%s] [typekind=%s]"); } } printf("]"); } } /* Print if this is a non-POD type. */ printf(" [isPOD=%d]", clang_isPODType(T)); /* Print the pointee type. */ { CXType PT = clang_getPointeeType(T); if (PT.kind != CXType_Invalid) { PrintTypeAndTypeKind(PT, " [pointeetype=%s] [pointeekind=%s]"); } } /* Print the number of fields if they exist. */ { int numFields = 0; if (clang_Type_visitFields(T, FieldVisitor, &numFields)){ if (numFields != 0) { printf(" [nbFields=%d]", numFields); } /* Print if it is an anonymous record. */ { unsigned isAnon = clang_Cursor_isAnonymous(cursor); if (isAnon != 0) { printf(" [isAnon=%d]", isAnon); } } } } printf("\n"); } return CXChildVisit_Recurse; } static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p, CXClientData d) { CXType T; enum CXCursorKind K = clang_getCursorKind(cursor); if (clang_isInvalid(K)) return CXChildVisit_Recurse; T = clang_getCursorType(cursor); PrintCursor(cursor, NULL); PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]"); /* Print the type sizeof if applicable. */ { long long Size = clang_Type_getSizeOf(T); if (Size >= 0 || Size < -1 ) { printf(" [sizeof=%lld]", Size); } } /* Print the type alignof if applicable. */ { long long Align = clang_Type_getAlignOf(T); if (Align >= 0 || Align < -1) { printf(" [alignof=%lld]", Align); } } /* Print the record field offset if applicable. */ { CXString FieldSpelling = clang_getCursorSpelling(cursor); const char *FieldName = clang_getCString(FieldSpelling); /* recurse to get the first parent record that is not anonymous. */ CXCursor Parent, Record; unsigned RecordIsAnonymous = 0; if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) { Record = Parent = p; do { Record = Parent; Parent = clang_getCursorSemanticParent(Record); RecordIsAnonymous = clang_Cursor_isAnonymous(Record); /* Recurse as long as the parent is a CXType_Record and the Record is anonymous */ } while ( clang_getCursorType(Parent).kind == CXType_Record && RecordIsAnonymous > 0); { long long Offset = clang_Type_getOffsetOf(clang_getCursorType(Record), FieldName); long long Offset2 = clang_Cursor_getOffsetOfField(cursor); if (Offset == Offset2){ printf(" [offsetof=%lld]", Offset); } else { /* Offsets will be different in anonymous records. */ printf(" [offsetof=%lld/%lld]", Offset, Offset2); } } } clang_disposeString(FieldSpelling); } /* Print if its a bitfield */ { int IsBitfield = clang_Cursor_isBitField(cursor); if (IsBitfield) printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor)); } printf("\n"); return CXChildVisit_Recurse; } /******************************************************************************/ /* Mangling testing. */ /******************************************************************************/ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); printf(" [mangled=%s]\n", clang_getCString(MangledName)); clang_disposeString(MangledName); return CXChildVisit_Continue; } /******************************************************************************/ /* Bitwidth testing. */ /******************************************************************************/ static enum CXChildVisitResult PrintBitWidth(CXCursor cursor, CXCursor p, CXClientData d) { int Bitwidth; if (clang_getCursorKind(cursor) != CXCursor_FieldDecl) return CXChildVisit_Recurse; Bitwidth = clang_getFieldDeclBitWidth(cursor); if (Bitwidth >= 0) { PrintCursor(cursor, NULL); printf(" bitwidth=%d\n", Bitwidth); } return CXChildVisit_Recurse; } /******************************************************************************/ /* Loading ASTs/source. */ /******************************************************************************/ static int perform_test_load(CXIndex Idx, CXTranslationUnit TU, const char *filter, const char *prefix, CXCursorVisitor Visitor, PostVisitTU PV, const char *CommentSchemaFile) { if (prefix) FileCheckPrefix = prefix; if (Visitor) { enum CXCursorKind K = CXCursor_NotImplemented; enum CXCursorKind *ck = &K; VisitorData Data; /* Perform some simple filtering. */ if (!strcmp(filter, "all") || !strcmp(filter, "local")) ck = NULL; else if (!strcmp(filter, "all-display") || !strcmp(filter, "local-display")) { ck = NULL; want_display_name = 1; } else if (!strcmp(filter, "none")) K = (enum CXCursorKind) ~0; else if (!strcmp(filter, "category")) K = CXCursor_ObjCCategoryDecl; else if (!strcmp(filter, "interface")) K = CXCursor_ObjCInterfaceDecl; else if (!strcmp(filter, "protocol")) K = CXCursor_ObjCProtocolDecl; else if (!strcmp(filter, "function")) K = CXCursor_FunctionDecl; else if (!strcmp(filter, "typedef")) K = CXCursor_TypedefDecl; else if (!strcmp(filter, "scan-function")) Visitor = FunctionScanVisitor; else { fprintf(stderr, "Unknown filter for -test-load-tu: %s\n", filter); return 1; } Data.TU = TU; Data.Filter = ck; Data.CommentSchemaFile = CommentSchemaFile; clang_visitChildren(clang_getTranslationUnitCursor(TU), Visitor, &Data); } if (PV) PV(TU); PrintDiagnostics(TU); if (checkForErrors(TU) != 0) { clang_disposeTranslationUnit(TU); return -1; } clang_disposeTranslationUnit(TU); return 0; } int perform_test_load_tu(const char *file, const char *filter, const char *prefix, CXCursorVisitor Visitor, PostVisitTU PV) { CXIndex Idx; CXTranslationUnit TU; int result; Idx = clang_createIndex(/* excludeDeclsFromPCH */ !strcmp(filter, "local") ? 1 : 0, /* displayDiagnostics=*/1); if (!CreateTranslationUnit(Idx, file, &TU)) { clang_disposeIndex(Idx); return 1; } result = perform_test_load(Idx, TU, filter, prefix, Visitor, PV, NULL); clang_disposeIndex(Idx); return result; } int perform_test_load_source(int argc, const char **argv, const char *filter, CXCursorVisitor Visitor, PostVisitTU PV) { CXIndex Idx; CXTranslationUnit TU; const char *CommentSchemaFile; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; enum CXErrorCode Err; int result; Idx = clang_createIndex(/* excludeDeclsFromPCH */ (!strcmp(filter, "local") || !strcmp(filter, "local-display"))? 1 : 0, /* displayDiagnostics=*/1); if ((CommentSchemaFile = parse_comments_schema(argc, argv))) { argc--; argv++; } if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) { clang_disposeIndex(Idx); return -1; } Err = clang_parseTranslationUnit2(Idx, 0, argv + num_unsaved_files, argc - num_unsaved_files, unsaved_files, num_unsaved_files, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "Unable to load translation unit!\n"); describeLibclangFailure(Err); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeIndex(Idx); return 1; } result = perform_test_load(Idx, TU, filter, NULL, Visitor, PV, CommentSchemaFile); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeIndex(Idx); return result; } int perform_test_reparse_source(int argc, const char **argv, int trials, const char *filter, CXCursorVisitor Visitor, PostVisitTU PV) { CXIndex Idx; CXTranslationUnit TU; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; int compiler_arg_idx = 0; enum CXErrorCode Err; int result, i; int trial; int remap_after_trial = 0; char *endptr = 0; Idx = clang_createIndex(/* excludeDeclsFromPCH */ !strcmp(filter, "local") ? 1 : 0, /* displayDiagnostics=*/1); if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) { clang_disposeIndex(Idx); return -1; } for (i = 0; i < argc; ++i) { if (strcmp(argv[i], "--") == 0) break; } if (i < argc) compiler_arg_idx = i+1; if (num_unsaved_files > compiler_arg_idx) compiler_arg_idx = num_unsaved_files; /* Load the initial translation unit -- we do this without honoring remapped * files, so that we have a way to test results after changing the source. */ Err = clang_parseTranslationUnit2(Idx, 0, argv + compiler_arg_idx, argc - compiler_arg_idx, 0, 0, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "Unable to load translation unit!\n"); describeLibclangFailure(Err); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeIndex(Idx); return 1; } if (checkForErrors(TU) != 0) return -1; if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) { remap_after_trial = strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), &endptr, 10); } for (trial = 0; trial < trials; ++trial) { free_remapped_files(unsaved_files, num_unsaved_files); if (parse_remapped_files_with_try(trial, argc, argv, 0, &unsaved_files, &num_unsaved_files)) { clang_disposeTranslationUnit(TU); clang_disposeIndex(Idx); return -1; } Err = clang_reparseTranslationUnit( TU, trial >= remap_after_trial ? num_unsaved_files : 0, trial >= remap_after_trial ? unsaved_files : 0, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { fprintf(stderr, "Unable to reparse translation unit!\n"); describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeIndex(Idx); return -1; } if (checkForErrors(TU) != 0) return -1; } result = perform_test_load(Idx, TU, filter, NULL, Visitor, PV, NULL); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeIndex(Idx); return result; } /******************************************************************************/ /* Logic for testing clang_getCursor(). */ /******************************************************************************/ static void print_cursor_file_scan(CXTranslationUnit TU, CXCursor cursor, unsigned start_line, unsigned start_col, unsigned end_line, unsigned end_col, const char *prefix) { printf("// %s: ", FileCheckPrefix); if (prefix) printf("-%s", prefix); PrintExtent(stdout, start_line, start_col, end_line, end_col); printf(" "); PrintCursor(cursor, NULL); printf("\n"); } static int perform_file_scan(const char *ast_file, const char *source_file, const char *prefix) { CXIndex Idx; CXTranslationUnit TU; FILE *fp; CXCursor prevCursor = clang_getNullCursor(); CXFile file; unsigned line = 1, col = 1; unsigned start_line = 1, start_col = 1; if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1, /* displayDiagnostics=*/1))) { fprintf(stderr, "Could not create Index\n"); return 1; } if (!CreateTranslationUnit(Idx, ast_file, &TU)) return 1; if ((fp = fopen(source_file, "r")) == NULL) { fprintf(stderr, "Could not open '%s'\n", source_file); clang_disposeTranslationUnit(TU); return 1; } file = clang_getFile(TU, source_file); for (;;) { CXCursor cursor; int c = fgetc(fp); if (c == '\n') { ++line; col = 1; } else ++col; /* Check the cursor at this position, and dump the previous one if we have * found something new. */ cursor = clang_getCursor(TU, clang_getLocation(TU, file, line, col)); if ((c == EOF || !clang_equalCursors(cursor, prevCursor)) && prevCursor.kind != CXCursor_InvalidFile) { print_cursor_file_scan(TU, prevCursor, start_line, start_col, line, col, prefix); start_line = line; start_col = col; } if (c == EOF) break; prevCursor = cursor; } fclose(fp); clang_disposeTranslationUnit(TU); clang_disposeIndex(Idx); return 0; } /******************************************************************************/ /* Logic for testing clang code completion. */ /******************************************************************************/ /* Parse file:line:column from the input string. Returns 0 on success, non-zero on failure. If successful, the pointer *filename will contain newly-allocated memory (that will be owned by the caller) to store the file name. */ int parse_file_line_column(const char *input, char **filename, unsigned *line, unsigned *column, unsigned *second_line, unsigned *second_column) { /* Find the second colon. */ const char *last_colon = strrchr(input, ':'); unsigned values[4], i; unsigned num_values = (second_line && second_column)? 4 : 2; char *endptr = 0; if (!last_colon || last_colon == input) { if (num_values == 4) fprintf(stderr, "could not parse filename:line:column:line:column in " "'%s'\n", input); else fprintf(stderr, "could not parse filename:line:column in '%s'\n", input); return 1; } for (i = 0; i != num_values; ++i) { const char *prev_colon; /* Parse the next line or column. */ values[num_values - i - 1] = strtol(last_colon + 1, &endptr, 10); if (*endptr != 0 && *endptr != ':') { fprintf(stderr, "could not parse %s in '%s'\n", (i % 2 ? "column" : "line"), input); return 1; } if (i + 1 == num_values) break; /* Find the previous colon. */ prev_colon = last_colon - 1; while (prev_colon != input && *prev_colon != ':') --prev_colon; if (prev_colon == input) { fprintf(stderr, "could not parse %s in '%s'\n", (i % 2 == 0? "column" : "line"), input); return 1; } last_colon = prev_colon; } *line = values[0]; *column = values[1]; if (second_line && second_column) { *second_line = values[2]; *second_column = values[3]; } /* Copy the file name. */ *filename = (char*)malloc(last_colon - input + 1); memcpy(*filename, input, last_colon - input); (*filename)[last_colon - input] = 0; return 0; } const char * clang_getCompletionChunkKindSpelling(enum CXCompletionChunkKind Kind) { switch (Kind) { case CXCompletionChunk_Optional: return "Optional"; case CXCompletionChunk_TypedText: return "TypedText"; case CXCompletionChunk_Text: return "Text"; case CXCompletionChunk_Placeholder: return "Placeholder"; case CXCompletionChunk_Informative: return "Informative"; case CXCompletionChunk_CurrentParameter: return "CurrentParameter"; case CXCompletionChunk_LeftParen: return "LeftParen"; case CXCompletionChunk_RightParen: return "RightParen"; case CXCompletionChunk_LeftBracket: return "LeftBracket"; case CXCompletionChunk_RightBracket: return "RightBracket"; case CXCompletionChunk_LeftBrace: return "LeftBrace"; case CXCompletionChunk_RightBrace: return "RightBrace"; case CXCompletionChunk_LeftAngle: return "LeftAngle"; case CXCompletionChunk_RightAngle: return "RightAngle"; case CXCompletionChunk_Comma: return "Comma"; case CXCompletionChunk_ResultType: return "ResultType"; case CXCompletionChunk_Colon: return "Colon"; case CXCompletionChunk_SemiColon: return "SemiColon"; case CXCompletionChunk_Equal: return "Equal"; case CXCompletionChunk_HorizontalSpace: return "HorizontalSpace"; case CXCompletionChunk_VerticalSpace: return "VerticalSpace"; } return "Unknown"; } static int checkForErrors(CXTranslationUnit TU) { unsigned Num, i; CXDiagnostic Diag; CXString DiagStr; if (!getenv("CINDEXTEST_FAILONERROR")) return 0; Num = clang_getNumDiagnostics(TU); for (i = 0; i != Num; ++i) { Diag = clang_getDiagnostic(TU, i); if (clang_getDiagnosticSeverity(Diag) >= CXDiagnostic_Error) { DiagStr = clang_formatDiagnostic(Diag, clang_defaultDiagnosticDisplayOptions()); fprintf(stderr, "%s\n", clang_getCString(DiagStr)); clang_disposeString(DiagStr); clang_disposeDiagnostic(Diag); return -1; } clang_disposeDiagnostic(Diag); } return 0; } static void print_completion_string(CXCompletionString completion_string, FILE *file) { int I, N; N = clang_getNumCompletionChunks(completion_string); for (I = 0; I != N; ++I) { CXString text; const char *cstr; enum CXCompletionChunkKind Kind = clang_getCompletionChunkKind(completion_string, I); if (Kind == CXCompletionChunk_Optional) { fprintf(file, "{Optional "); print_completion_string( clang_getCompletionChunkCompletionString(completion_string, I), file); fprintf(file, "}"); continue; } if (Kind == CXCompletionChunk_VerticalSpace) { fprintf(file, "{VerticalSpace }"); continue; } text = clang_getCompletionChunkText(completion_string, I); cstr = clang_getCString(text); fprintf(file, "{%s %s}", clang_getCompletionChunkKindSpelling(Kind), cstr ? cstr : ""); clang_disposeString(text); } } static void print_completion_result(CXCompletionResult *completion_result, FILE *file) { CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind); unsigned annotationCount; enum CXCursorKind ParentKind; CXString ParentName; CXString BriefComment; const char *BriefCommentCString; fprintf(file, "%s:", clang_getCString(ks)); clang_disposeString(ks); print_completion_string(completion_result->CompletionString, file); fprintf(file, " (%u)", clang_getCompletionPriority(completion_result->CompletionString)); switch (clang_getCompletionAvailability(completion_result->CompletionString)){ case CXAvailability_Available: break; case CXAvailability_Deprecated: fprintf(file, " (deprecated)"); break; case CXAvailability_NotAvailable: fprintf(file, " (unavailable)"); break; case CXAvailability_NotAccessible: fprintf(file, " (inaccessible)"); break; } annotationCount = clang_getCompletionNumAnnotations( completion_result->CompletionString); if (annotationCount) { unsigned i; fprintf(file, " ("); for (i = 0; i < annotationCount; ++i) { if (i != 0) fprintf(file, ", "); fprintf(file, "\"%s\"", clang_getCString(clang_getCompletionAnnotation( completion_result->CompletionString, i))); } fprintf(file, ")"); } if (!getenv("CINDEXTEST_NO_COMPLETION_PARENTS")) { ParentName = clang_getCompletionParent(completion_result->CompletionString, &ParentKind); if (ParentKind != CXCursor_NotImplemented) { CXString KindSpelling = clang_getCursorKindSpelling(ParentKind); fprintf(file, " (parent: %s '%s')", clang_getCString(KindSpelling), clang_getCString(ParentName)); clang_disposeString(KindSpelling); } clang_disposeString(ParentName); } BriefComment = clang_getCompletionBriefComment( completion_result->CompletionString); BriefCommentCString = clang_getCString(BriefComment); if (BriefCommentCString && *BriefCommentCString != '\0') { fprintf(file, "(brief comment: %s)", BriefCommentCString); } clang_disposeString(BriefComment); fprintf(file, "\n"); } void print_completion_contexts(unsigned long long contexts, FILE *file) { fprintf(file, "Completion contexts:\n"); if (contexts == CXCompletionContext_Unknown) { fprintf(file, "Unknown\n"); } if (contexts & CXCompletionContext_AnyType) { fprintf(file, "Any type\n"); } if (contexts & CXCompletionContext_AnyValue) { fprintf(file, "Any value\n"); } if (contexts & CXCompletionContext_ObjCObjectValue) { fprintf(file, "Objective-C object value\n"); } if (contexts & CXCompletionContext_ObjCSelectorValue) { fprintf(file, "Objective-C selector value\n"); } if (contexts & CXCompletionContext_CXXClassTypeValue) { fprintf(file, "C++ class type value\n"); } if (contexts & CXCompletionContext_DotMemberAccess) { fprintf(file, "Dot member access\n"); } if (contexts & CXCompletionContext_ArrowMemberAccess) { fprintf(file, "Arrow member access\n"); } if (contexts & CXCompletionContext_ObjCPropertyAccess) { fprintf(file, "Objective-C property access\n"); } if (contexts & CXCompletionContext_EnumTag) { fprintf(file, "Enum tag\n"); } if (contexts & CXCompletionContext_UnionTag) { fprintf(file, "Union tag\n"); } if (contexts & CXCompletionContext_StructTag) { fprintf(file, "Struct tag\n"); } if (contexts & CXCompletionContext_ClassTag) { fprintf(file, "Class name\n"); } if (contexts & CXCompletionContext_Namespace) { fprintf(file, "Namespace or namespace alias\n"); } if (contexts & CXCompletionContext_NestedNameSpecifier) { fprintf(file, "Nested name specifier\n"); } if (contexts & CXCompletionContext_ObjCInterface) { fprintf(file, "Objective-C interface\n"); } if (contexts & CXCompletionContext_ObjCProtocol) { fprintf(file, "Objective-C protocol\n"); } if (contexts & CXCompletionContext_ObjCCategory) { fprintf(file, "Objective-C category\n"); } if (contexts & CXCompletionContext_ObjCInstanceMessage) { fprintf(file, "Objective-C instance method\n"); } if (contexts & CXCompletionContext_ObjCClassMessage) { fprintf(file, "Objective-C class method\n"); } if (contexts & CXCompletionContext_ObjCSelectorName) { fprintf(file, "Objective-C selector name\n"); } if (contexts & CXCompletionContext_MacroName) { fprintf(file, "Macro name\n"); } if (contexts & CXCompletionContext_NaturalLanguage) { fprintf(file, "Natural language\n"); } } int my_stricmp(const char *s1, const char *s2) { while (*s1 && *s2) { int c1 = tolower((unsigned char)*s1), c2 = tolower((unsigned char)*s2); if (c1 < c2) return -1; else if (c1 > c2) return 1; ++s1; ++s2; } if (*s1) return 1; else if (*s2) return -1; return 0; } int perform_code_completion(int argc, const char **argv, int timing_only) { const char *input = argv[1]; char *filename = 0; unsigned line; unsigned column; CXIndex CIdx; int errorCode; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; CXCodeCompleteResults *results = 0; enum CXErrorCode Err; CXTranslationUnit TU; unsigned I, Repeats = 1; unsigned completionOptions = clang_defaultCodeCompleteOptions(); if (getenv("CINDEXTEST_CODE_COMPLETE_PATTERNS")) completionOptions |= CXCodeComplete_IncludeCodePatterns; if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS")) completionOptions |= CXCodeComplete_IncludeBriefComments; if (timing_only) input += strlen("-code-completion-timing="); else input += strlen("-code-completion-at="); if ((errorCode = parse_file_line_column(input, &filename, &line, &column, 0, 0))) return errorCode; if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files)) return -1; CIdx = clang_createIndex(0, 0); if (getenv("CINDEXTEST_EDITING")) Repeats = 5; Err = clang_parseTranslationUnit2(CIdx, 0, argv + num_unsaved_files + 2, argc - num_unsaved_files - 2, 0, 0, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "Unable to load translation unit!\n"); describeLibclangFailure(Err); return 1; } Err = clang_reparseTranslationUnit(TU, 0, 0, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { fprintf(stderr, "Unable to reparse translation unit!\n"); describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); return 1; } for (I = 0; I != Repeats; ++I) { results = clang_codeCompleteAt(TU, filename, line, column, unsaved_files, num_unsaved_files, completionOptions); if (!results) { fprintf(stderr, "Unable to perform code completion!\n"); return 1; } if (I != Repeats-1) clang_disposeCodeCompleteResults(results); } if (results) { unsigned i, n = results->NumResults, containerIsIncomplete = 0; unsigned long long contexts; enum CXCursorKind containerKind; CXString objCSelector; const char *selectorString; if (!timing_only) { /* Sort the code-completion results based on the typed text. */ clang_sortCodeCompletionResults(results->Results, results->NumResults); for (i = 0; i != n; ++i) print_completion_result(results->Results + i, stdout); } n = clang_codeCompleteGetNumDiagnostics(results); for (i = 0; i != n; ++i) { CXDiagnostic diag = clang_codeCompleteGetDiagnostic(results, i); PrintDiagnostic(diag); clang_disposeDiagnostic(diag); } contexts = clang_codeCompleteGetContexts(results); print_completion_contexts(contexts, stdout); containerKind = clang_codeCompleteGetContainerKind(results, &containerIsIncomplete); if (containerKind != CXCursor_InvalidCode) { /* We have found a container */ CXString containerUSR, containerKindSpelling; containerKindSpelling = clang_getCursorKindSpelling(containerKind); printf("Container Kind: %s\n", clang_getCString(containerKindSpelling)); clang_disposeString(containerKindSpelling); if (containerIsIncomplete) { printf("Container is incomplete\n"); } else { printf("Container is complete\n"); } containerUSR = clang_codeCompleteGetContainerUSR(results); printf("Container USR: %s\n", clang_getCString(containerUSR)); clang_disposeString(containerUSR); } objCSelector = clang_codeCompleteGetObjCSelector(results); selectorString = clang_getCString(objCSelector); if (selectorString && strlen(selectorString) > 0) { printf("Objective-C selector: %s\n", selectorString); } clang_disposeString(objCSelector); clang_disposeCodeCompleteResults(results); } clang_disposeTranslationUnit(TU); clang_disposeIndex(CIdx); free(filename); free_remapped_files(unsaved_files, num_unsaved_files); return 0; } typedef struct { char *filename; unsigned line; unsigned column; } CursorSourceLocation; static int inspect_cursor_at(int argc, const char **argv) { CXIndex CIdx; int errorCode; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; enum CXErrorCode Err; CXTranslationUnit TU; CXCursor Cursor; CursorSourceLocation *Locations = 0; unsigned NumLocations = 0, Loc; unsigned Repeats = 1; unsigned I; /* Count the number of locations. */ while (strstr(argv[NumLocations+1], "-cursor-at=") == argv[NumLocations+1]) ++NumLocations; /* Parse the locations. */ assert(NumLocations > 0 && "Unable to count locations?"); Locations = (CursorSourceLocation *)malloc( NumLocations * sizeof(CursorSourceLocation)); for (Loc = 0; Loc < NumLocations; ++Loc) { const char *input = argv[Loc + 1] + strlen("-cursor-at="); if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename, &Locations[Loc].line, &Locations[Loc].column, 0, 0))) return errorCode; } if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files, &num_unsaved_files)) return -1; if (getenv("CINDEXTEST_EDITING")) Repeats = 5; /* Parse the translation unit. When we're testing clang_getCursor() after reparsing, don't remap unsaved files until the second parse. */ CIdx = clang_createIndex(1, 1); Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1], argv + num_unsaved_files + 1 + NumLocations, argc - num_unsaved_files - 2 - NumLocations, unsaved_files, Repeats > 1? 0 : num_unsaved_files, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "unable to parse input\n"); describeLibclangFailure(Err); return -1; } if (checkForErrors(TU) != 0) return -1; for (I = 0; I != Repeats; ++I) { if (Repeats > 1) { Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); return 1; } } if (checkForErrors(TU) != 0) return -1; for (Loc = 0; Loc < NumLocations; ++Loc) { CXFile file = clang_getFile(TU, Locations[Loc].filename); if (!file) continue; Cursor = clang_getCursor(TU, clang_getLocation(TU, file, Locations[Loc].line, Locations[Loc].column)); if (checkForErrors(TU) != 0) return -1; if (I + 1 == Repeats) { CXCompletionString completionString = clang_getCursorCompletionString( Cursor); CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor); CXString Spelling; const char *cspell; unsigned line, column; clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0); printf("%d:%d ", line, column); PrintCursor(Cursor, NULL); PrintCursorExtent(Cursor); Spelling = clang_getCursorSpelling(Cursor); cspell = clang_getCString(Spelling); if (cspell && strlen(cspell) != 0) { unsigned pieceIndex; printf(" Spelling=%s (", cspell); for (pieceIndex = 0; ; ++pieceIndex) { CXSourceRange range = clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0); if (clang_Range_isNull(range)) break; PrintRange(range, 0); } printf(")"); } clang_disposeString(Spelling); if (clang_Cursor_getObjCSelectorIndex(Cursor) != -1) printf(" Selector index=%d", clang_Cursor_getObjCSelectorIndex(Cursor)); if (clang_Cursor_isDynamicCall(Cursor)) printf(" Dynamic-call"); if (Cursor.kind == CXCursor_ObjCMessageExpr) { CXType T = clang_Cursor_getReceiverType(Cursor); CXString S = clang_getTypeKindSpelling(T.kind); printf(" Receiver-type=%s", clang_getCString(S)); clang_disposeString(S); } { CXModule mod = clang_Cursor_getModule(Cursor); CXFile astFile; CXString name, astFilename; unsigned i, numHeaders; if (mod) { astFile = clang_Module_getASTFile(mod); astFilename = clang_getFileName(astFile); name = clang_Module_getFullName(mod); numHeaders = clang_Module_getNumTopLevelHeaders(TU, mod); printf(" ModuleName=%s (%s) system=%d Headers(%d):", clang_getCString(name), clang_getCString(astFilename), clang_Module_isSystem(mod), numHeaders); clang_disposeString(name); clang_disposeString(astFilename); for (i = 0; i < numHeaders; ++i) { CXFile file = clang_Module_getTopLevelHeader(TU, mod, i); CXString filename = clang_getFileName(file); printf("\n%s", clang_getCString(filename)); clang_disposeString(filename); } } } if (completionString != NULL) { printf("\nCompletion string: "); print_completion_string(completionString, stdout); } printf("\n"); free(Locations[Loc].filename); } } } PrintDiagnostics(TU); clang_disposeTranslationUnit(TU); clang_disposeIndex(CIdx); free(Locations); free_remapped_files(unsaved_files, num_unsaved_files); return 0; } static enum CXVisitorResult findFileRefsVisit(void *context, CXCursor cursor, CXSourceRange range) { if (clang_Range_isNull(range)) return CXVisit_Continue; PrintCursor(cursor, NULL); PrintRange(range, ""); printf("\n"); return CXVisit_Continue; } static int find_file_refs_at(int argc, const char **argv) { CXIndex CIdx; int errorCode; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; enum CXErrorCode Err; CXTranslationUnit TU; CXCursor Cursor; CursorSourceLocation *Locations = 0; unsigned NumLocations = 0, Loc; unsigned Repeats = 1; unsigned I; /* Count the number of locations. */ while (strstr(argv[NumLocations+1], "-file-refs-at=") == argv[NumLocations+1]) ++NumLocations; /* Parse the locations. */ assert(NumLocations > 0 && "Unable to count locations?"); Locations = (CursorSourceLocation *)malloc( NumLocations * sizeof(CursorSourceLocation)); for (Loc = 0; Loc < NumLocations; ++Loc) { const char *input = argv[Loc + 1] + strlen("-file-refs-at="); if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename, &Locations[Loc].line, &Locations[Loc].column, 0, 0))) return errorCode; } if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files, &num_unsaved_files)) return -1; if (getenv("CINDEXTEST_EDITING")) Repeats = 5; /* Parse the translation unit. When we're testing clang_getCursor() after reparsing, don't remap unsaved files until the second parse. */ CIdx = clang_createIndex(1, 1); Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1], argv + num_unsaved_files + 1 + NumLocations, argc - num_unsaved_files - 2 - NumLocations, unsaved_files, Repeats > 1? 0 : num_unsaved_files, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "unable to parse input\n"); describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); return -1; } if (checkForErrors(TU) != 0) return -1; for (I = 0; I != Repeats; ++I) { if (Repeats > 1) { Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); return 1; } } if (checkForErrors(TU) != 0) return -1; for (Loc = 0; Loc < NumLocations; ++Loc) { CXFile file = clang_getFile(TU, Locations[Loc].filename); if (!file) continue; Cursor = clang_getCursor(TU, clang_getLocation(TU, file, Locations[Loc].line, Locations[Loc].column)); if (checkForErrors(TU) != 0) return -1; if (I + 1 == Repeats) { CXCursorAndRangeVisitor visitor = { 0, findFileRefsVisit }; PrintCursor(Cursor, NULL); printf("\n"); clang_findReferencesInFile(Cursor, file, visitor); free(Locations[Loc].filename); if (checkForErrors(TU) != 0) return -1; } } } PrintDiagnostics(TU); clang_disposeTranslationUnit(TU); clang_disposeIndex(CIdx); free(Locations); free_remapped_files(unsaved_files, num_unsaved_files); return 0; } static enum CXVisitorResult findFileIncludesVisit(void *context, CXCursor cursor, CXSourceRange range) { PrintCursor(cursor, NULL); PrintRange(range, ""); printf("\n"); return CXVisit_Continue; } static int find_file_includes_in(int argc, const char **argv) { CXIndex CIdx; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; enum CXErrorCode Err; CXTranslationUnit TU; const char **Filenames = 0; unsigned NumFilenames = 0; unsigned Repeats = 1; unsigned I, FI; /* Count the number of locations. */ while (strstr(argv[NumFilenames+1], "-file-includes-in=") == argv[NumFilenames+1]) ++NumFilenames; /* Parse the locations. */ assert(NumFilenames > 0 && "Unable to count filenames?"); Filenames = (const char **)malloc(NumFilenames * sizeof(const char *)); for (I = 0; I < NumFilenames; ++I) { const char *input = argv[I + 1] + strlen("-file-includes-in="); /* Copy the file name. */ Filenames[I] = input; } if (parse_remapped_files(argc, argv, NumFilenames + 1, &unsaved_files, &num_unsaved_files)) return -1; if (getenv("CINDEXTEST_EDITING")) Repeats = 2; /* Parse the translation unit. When we're testing clang_getCursor() after reparsing, don't remap unsaved files until the second parse. */ CIdx = clang_createIndex(1, 1); Err = clang_parseTranslationUnit2( CIdx, argv[argc - 1], argv + num_unsaved_files + 1 + NumFilenames, argc - num_unsaved_files - 2 - NumFilenames, unsaved_files, Repeats > 1 ? 0 : num_unsaved_files, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "unable to parse input\n"); describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); return -1; } if (checkForErrors(TU) != 0) return -1; for (I = 0; I != Repeats; ++I) { if (Repeats > 1) { Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { describeLibclangFailure(Err); clang_disposeTranslationUnit(TU); return 1; } } if (checkForErrors(TU) != 0) return -1; for (FI = 0; FI < NumFilenames; ++FI) { CXFile file = clang_getFile(TU, Filenames[FI]); if (!file) continue; if (checkForErrors(TU) != 0) return -1; if (I + 1 == Repeats) { CXCursorAndRangeVisitor visitor = { 0, findFileIncludesVisit }; clang_findIncludesInFile(TU, file, visitor); if (checkForErrors(TU) != 0) return -1; } } } PrintDiagnostics(TU); clang_disposeTranslationUnit(TU); clang_disposeIndex(CIdx); free((void *)Filenames); free_remapped_files(unsaved_files, num_unsaved_files); return 0; } #define MAX_IMPORTED_ASTFILES 200 typedef struct { char **filenames; unsigned num_files; } ImportedASTFilesData; static ImportedASTFilesData *importedASTs_create() { ImportedASTFilesData *p; p = malloc(sizeof(ImportedASTFilesData)); p->filenames = malloc(MAX_IMPORTED_ASTFILES * sizeof(const char *)); p->num_files = 0; return p; } static void importedASTs_dispose(ImportedASTFilesData *p) { unsigned i; if (!p) return; for (i = 0; i < p->num_files; ++i) free(p->filenames[i]); free(p->filenames); free(p); } static void importedASTS_insert(ImportedASTFilesData *p, const char *file) { unsigned i; assert(p && file); for (i = 0; i < p->num_files; ++i) if (strcmp(file, p->filenames[i]) == 0) return; assert(p->num_files + 1 < MAX_IMPORTED_ASTFILES); p->filenames[p->num_files++] = strdup(file); } typedef struct IndexDataStringList_ { struct IndexDataStringList_ *next; char data[1]; /* Dynamically sized. */ } IndexDataStringList; typedef struct { const char *check_prefix; int first_check_printed; int fail_for_error; int abort; const char *main_filename; ImportedASTFilesData *importedASTs; IndexDataStringList *strings; CXTranslationUnit TU; } IndexData; static void free_client_data(IndexData *index_data) { IndexDataStringList *node = index_data->strings; while (node) { IndexDataStringList *next = node->next; free(node); node = next; } index_data->strings = NULL; } static void printCheck(IndexData *data) { if (data->check_prefix) { if (data->first_check_printed) { printf("// %s-NEXT: ", data->check_prefix); } else { printf("// %s : ", data->check_prefix); data->first_check_printed = 1; } } } static void printCXIndexFile(CXIdxClientFile file) { CXString filename = clang_getFileName((CXFile)file); printf("%s", clang_getCString(filename)); clang_disposeString(filename); } static void printCXIndexLoc(CXIdxLoc loc, CXClientData client_data) { IndexData *index_data; CXString filename; const char *cname; CXIdxClientFile file; unsigned line, column; int isMainFile; index_data = (IndexData *)client_data; clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0); if (line == 0) { printf("<invalid>"); return; } if (!file) { printf("<no idxfile>"); return; } filename = clang_getFileName((CXFile)file); cname = clang_getCString(filename); if (strcmp(cname, index_data->main_filename) == 0) isMainFile = 1; else isMainFile = 0; clang_disposeString(filename); if (!isMainFile) { printCXIndexFile(file); printf(":"); } printf("%d:%d", line, column); } static unsigned digitCount(unsigned val) { unsigned c = 1; while (1) { if (val < 10) return c; ++c; val /= 10; } } static CXIdxClientContainer makeClientContainer(CXClientData *client_data, const CXIdxEntityInfo *info, CXIdxLoc loc) { IndexData *index_data; IndexDataStringList *node; const char *name; char *newStr; CXIdxClientFile file; unsigned line, column; name = info->name; if (!name) name = "<anon-tag>"; clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0); node = (IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) + digitCount(line) + digitCount(column) + 2); newStr = node->data; sprintf(newStr, "%s:%d:%d", name, line, column); /* Remember string so it can be freed later. */ index_data = (IndexData *)client_data; node->next = index_data->strings; index_data->strings = node; return (CXIdxClientContainer)newStr; } static void printCXIndexContainer(const CXIdxContainerInfo *info) { CXIdxClientContainer container; container = clang_index_getClientContainer(info); if (!container) printf("[<<NULL>>]"); else printf("[%s]", (const char *)container); } static const char *getEntityKindString(CXIdxEntityKind kind) { switch (kind) { case CXIdxEntity_Unexposed: return "<<UNEXPOSED>>"; case CXIdxEntity_Typedef: return "typedef"; case CXIdxEntity_Function: return "function"; case CXIdxEntity_Variable: return "variable"; case CXIdxEntity_Field: return "field"; case CXIdxEntity_EnumConstant: return "enumerator"; case CXIdxEntity_ObjCClass: return "objc-class"; case CXIdxEntity_ObjCProtocol: return "objc-protocol"; case CXIdxEntity_ObjCCategory: return "objc-category"; case CXIdxEntity_ObjCInstanceMethod: return "objc-instance-method"; case CXIdxEntity_ObjCClassMethod: return "objc-class-method"; case CXIdxEntity_ObjCProperty: return "objc-property"; case CXIdxEntity_ObjCIvar: return "objc-ivar"; case CXIdxEntity_Enum: return "enum"; case CXIdxEntity_Struct: return "struct"; case CXIdxEntity_Union: return "union"; case CXIdxEntity_CXXClass: return "c++-class"; case CXIdxEntity_CXXNamespace: return "namespace"; case CXIdxEntity_CXXNamespaceAlias: return "namespace-alias"; case CXIdxEntity_CXXStaticVariable: return "c++-static-var"; case CXIdxEntity_CXXStaticMethod: return "c++-static-method"; case CXIdxEntity_CXXInstanceMethod: return "c++-instance-method"; case CXIdxEntity_CXXConstructor: return "constructor"; case CXIdxEntity_CXXDestructor: return "destructor"; case CXIdxEntity_CXXConversionFunction: return "conversion-func"; case CXIdxEntity_CXXTypeAlias: return "type-alias"; case CXIdxEntity_CXXInterface: return "c++-__interface"; } assert(0 && "Garbage entity kind"); return 0; } static const char *getEntityTemplateKindString(CXIdxEntityCXXTemplateKind kind) { switch (kind) { case CXIdxEntity_NonTemplate: return ""; case CXIdxEntity_Template: return "-template"; case CXIdxEntity_TemplatePartialSpecialization: return "-template-partial-spec"; case CXIdxEntity_TemplateSpecialization: return "-template-spec"; } assert(0 && "Garbage entity kind"); return 0; } static const char *getEntityLanguageString(CXIdxEntityLanguage kind) { switch (kind) { case CXIdxEntityLang_None: return "<none>"; case CXIdxEntityLang_C: return "C"; case CXIdxEntityLang_ObjC: return "ObjC"; case CXIdxEntityLang_CXX: return "C++"; } assert(0 && "Garbage language kind"); return 0; } static void printEntityInfo(const char *cb, CXClientData client_data, const CXIdxEntityInfo *info) { const char *name; IndexData *index_data; unsigned i; index_data = (IndexData *)client_data; printCheck(index_data); if (!info) { printf("%s: <<NULL>>", cb); return; } name = info->name; if (!name) name = "<anon-tag>"; printf("%s: kind: %s%s", cb, getEntityKindString(info->kind), getEntityTemplateKindString(info->templateKind)); printf(" | name: %s", name); printf(" | USR: %s", info->USR); printf(" | lang: %s", getEntityLanguageString(info->lang)); for (i = 0; i != info->numAttributes; ++i) { const CXIdxAttrInfo *Attr = info->attributes[i]; printf(" <attribute>: "); PrintCursor(Attr->cursor, NULL); } } static void printBaseClassInfo(CXClientData client_data, const CXIdxBaseClassInfo *info) { printEntityInfo(" <base>", client_data, info->base); printf(" | cursor: "); PrintCursor(info->cursor, NULL); printf(" | loc: "); printCXIndexLoc(info->loc, client_data); } static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo, CXClientData client_data) { unsigned i; for (i = 0; i < ProtoInfo->numProtocols; ++i) { printEntityInfo(" <protocol>", client_data, ProtoInfo->protocols[i]->protocol); printf(" | cursor: "); PrintCursor(ProtoInfo->protocols[i]->cursor, NULL); printf(" | loc: "); printCXIndexLoc(ProtoInfo->protocols[i]->loc, client_data); printf("\n"); } } static void index_diagnostic(CXClientData client_data, CXDiagnosticSet diagSet, void *reserved) { CXString str; const char *cstr; unsigned numDiags, i; CXDiagnostic diag; IndexData *index_data; index_data = (IndexData *)client_data; printCheck(index_data); numDiags = clang_getNumDiagnosticsInSet(diagSet); for (i = 0; i != numDiags; ++i) { diag = clang_getDiagnosticInSet(diagSet, i); str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions()); cstr = clang_getCString(str); printf("[diagnostic]: %s\n", cstr); clang_disposeString(str); if (getenv("CINDEXTEST_FAILONERROR") && clang_getDiagnosticSeverity(diag) >= CXDiagnostic_Error) { index_data->fail_for_error = 1; } } } static CXIdxClientFile index_enteredMainFile(CXClientData client_data, CXFile file, void *reserved) { IndexData *index_data; CXString filename; index_data = (IndexData *)client_data; printCheck(index_data); filename = clang_getFileName(file); index_data->main_filename = clang_getCString(filename); clang_disposeString(filename); printf("[enteredMainFile]: "); printCXIndexFile((CXIdxClientFile)file); printf("\n"); return (CXIdxClientFile)file; } static CXIdxClientFile index_ppIncludedFile(CXClientData client_data, const CXIdxIncludedFileInfo *info) { IndexData *index_data; CXModule Mod; index_data = (IndexData *)client_data; printCheck(index_data); printf("[ppIncludedFile]: "); printCXIndexFile((CXIdxClientFile)info->file); printf(" | name: \"%s\"", info->filename); printf(" | hash loc: "); printCXIndexLoc(info->hashLoc, client_data); printf(" | isImport: %d | isAngled: %d | isModule: %d", info->isImport, info->isAngled, info->isModuleImport); Mod = clang_getModuleForFile(index_data->TU, (CXFile)info->file); if (Mod) { CXString str = clang_Module_getFullName(Mod); const char *cstr = clang_getCString(str); printf(" | module: %s", cstr); clang_disposeString(str); } printf("\n"); return (CXIdxClientFile)info->file; } static CXIdxClientFile index_importedASTFile(CXClientData client_data, const CXIdxImportedASTFileInfo *info) { IndexData *index_data; index_data = (IndexData *)client_data; printCheck(index_data); if (index_data->importedASTs) { CXString filename = clang_getFileName(info->file); importedASTS_insert(index_data->importedASTs, clang_getCString(filename)); clang_disposeString(filename); } printf("[importedASTFile]: "); printCXIndexFile((CXIdxClientFile)info->file); if (info->mod) { CXString name = clang_Module_getFullName(info->mod); printf(" | loc: "); printCXIndexLoc(info->loc, client_data); printf(" | name: \"%s\"", clang_getCString(name)); printf(" | isImplicit: %d\n", info->isImplicit); clang_disposeString(name); } else { /* PCH file, the rest are not relevant. */ printf("\n"); } return (CXIdxClientFile)info->file; } static CXIdxClientContainer index_startedTranslationUnit(CXClientData client_data, void *reserved) { IndexData *index_data; index_data = (IndexData *)client_data; printCheck(index_data); printf("[startedTranslationUnit]\n"); return (CXIdxClientContainer)"TU"; } static void index_indexDeclaration(CXClientData client_data, const CXIdxDeclInfo *info) { IndexData *index_data; const CXIdxObjCCategoryDeclInfo *CatInfo; const CXIdxObjCInterfaceDeclInfo *InterInfo; const CXIdxObjCProtocolRefListInfo *ProtoInfo; const CXIdxObjCPropertyDeclInfo *PropInfo; const CXIdxCXXClassDeclInfo *CXXClassInfo; unsigned i; index_data = (IndexData *)client_data; printEntityInfo("[indexDeclaration]", client_data, info->entityInfo); printf(" | cursor: "); PrintCursor(info->cursor, NULL); printf(" | loc: "); printCXIndexLoc(info->loc, client_data); printf(" | semantic-container: "); printCXIndexContainer(info->semanticContainer); printf(" | lexical-container: "); printCXIndexContainer(info->lexicalContainer); printf(" | isRedecl: %d", info->isRedeclaration); printf(" | isDef: %d", info->isDefinition); if (info->flags & CXIdxDeclFlag_Skipped) { assert(!info->isContainer); printf(" | isContainer: skipped"); } else { printf(" | isContainer: %d", info->isContainer); } printf(" | isImplicit: %d\n", info->isImplicit); for (i = 0; i != info->numAttributes; ++i) { const CXIdxAttrInfo *Attr = info->attributes[i]; printf(" <attribute>: "); PrintCursor(Attr->cursor, NULL); printf("\n"); } if (clang_index_isEntityObjCContainerKind(info->entityInfo->kind)) { const char *kindName = 0; CXIdxObjCContainerKind K = clang_index_getObjCContainerDeclInfo(info)->kind; switch (K) { case CXIdxObjCContainer_ForwardRef: kindName = "forward-ref"; break; case CXIdxObjCContainer_Interface: kindName = "interface"; break; case CXIdxObjCContainer_Implementation: kindName = "implementation"; break; } printCheck(index_data); printf(" <ObjCContainerInfo>: kind: %s\n", kindName); } if ((CatInfo = clang_index_getObjCCategoryDeclInfo(info))) { printEntityInfo(" <ObjCCategoryInfo>: class", client_data, CatInfo->objcClass); printf(" | cursor: "); PrintCursor(CatInfo->classCursor, NULL); printf(" | loc: "); printCXIndexLoc(CatInfo->classLoc, client_data); printf("\n"); } if ((InterInfo = clang_index_getObjCInterfaceDeclInfo(info))) { if (InterInfo->superInfo) { printBaseClassInfo(client_data, InterInfo->superInfo); printf("\n"); } } if ((ProtoInfo = clang_index_getObjCProtocolRefListInfo(info))) { printProtocolList(ProtoInfo, client_data); } if ((PropInfo = clang_index_getObjCPropertyDeclInfo(info))) { if (PropInfo->getter) { printEntityInfo(" <getter>", client_data, PropInfo->getter); printf("\n"); } if (PropInfo->setter) { printEntityInfo(" <setter>", client_data, PropInfo->setter); printf("\n"); } } if ((CXXClassInfo = clang_index_getCXXClassDeclInfo(info))) { for (i = 0; i != CXXClassInfo->numBases; ++i) { printBaseClassInfo(client_data, CXXClassInfo->bases[i]); printf("\n"); } } if (info->declAsContainer) clang_index_setClientContainer( info->declAsContainer, makeClientContainer(client_data, info->entityInfo, info->loc)); } static void index_indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo *info) { printEntityInfo("[indexEntityReference]", client_data, info->referencedEntity); printf(" | cursor: "); PrintCursor(info->cursor, NULL); printf(" | loc: "); printCXIndexLoc(info->loc, client_data); printEntityInfo(" | <parent>:", client_data, info->parentEntity); printf(" | container: "); printCXIndexContainer(info->container); printf(" | refkind: "); switch (info->kind) { case CXIdxEntityRef_Direct: printf("direct"); break; case CXIdxEntityRef_Implicit: printf("implicit"); break; } printf("\n"); } static int index_abortQuery(CXClientData client_data, void *reserved) { IndexData *index_data; index_data = (IndexData *)client_data; return index_data->abort; } static IndexerCallbacks IndexCB = { index_abortQuery, index_diagnostic, index_enteredMainFile, index_ppIncludedFile, index_importedASTFile, index_startedTranslationUnit, index_indexDeclaration, index_indexEntityReference }; static unsigned getIndexOptions(void) { unsigned index_opts; index_opts = 0; if (getenv("CINDEXTEST_SUPPRESSREFS")) index_opts |= CXIndexOpt_SuppressRedundantRefs; if (getenv("CINDEXTEST_INDEXLOCALSYMBOLS")) index_opts |= CXIndexOpt_IndexFunctionLocalSymbols; if (!getenv("CINDEXTEST_DISABLE_SKIPPARSEDBODIES")) index_opts |= CXIndexOpt_SkipParsedBodiesInSession; return index_opts; } static int index_compile_args(int num_args, const char **args, CXIndexAction idxAction, ImportedASTFilesData *importedASTs, const char *check_prefix) { IndexData index_data; unsigned index_opts; int result; if (num_args == 0) { fprintf(stderr, "no compiler arguments\n"); return -1; } index_data.check_prefix = check_prefix; index_data.first_check_printed = 0; index_data.fail_for_error = 0; index_data.abort = 0; index_data.main_filename = ""; index_data.importedASTs = importedASTs; index_data.strings = NULL; index_data.TU = NULL; index_opts = getIndexOptions(); result = clang_indexSourceFile(idxAction, &index_data, &IndexCB,sizeof(IndexCB), index_opts, 0, args, num_args, 0, 0, 0, getDefaultParsingOptions()); if (result != CXError_Success) describeLibclangFailure(result); if (index_data.fail_for_error) result = -1; free_client_data(&index_data); return result; } static int index_ast_file(const char *ast_file, CXIndex Idx, CXIndexAction idxAction, ImportedASTFilesData *importedASTs, const char *check_prefix) { CXTranslationUnit TU; IndexData index_data; unsigned index_opts; int result; if (!CreateTranslationUnit(Idx, ast_file, &TU)) return -1; index_data.check_prefix = check_prefix; index_data.first_check_printed = 0; index_data.fail_for_error = 0; index_data.abort = 0; index_data.main_filename = ""; index_data.importedASTs = importedASTs; index_data.strings = NULL; index_data.TU = TU; index_opts = getIndexOptions(); result = clang_indexTranslationUnit(idxAction, &index_data, &IndexCB,sizeof(IndexCB), index_opts, TU); if (index_data.fail_for_error) result = -1; clang_disposeTranslationUnit(TU); free_client_data(&index_data); return result; } static int index_file(int argc, const char **argv, int full) { const char *check_prefix; CXIndex Idx; CXIndexAction idxAction; ImportedASTFilesData *importedASTs; int result; check_prefix = 0; if (argc > 0) { if (strstr(argv[0], "-check-prefix=") == argv[0]) { check_prefix = argv[0] + strlen("-check-prefix="); ++argv; --argc; } } if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1, /* displayDiagnostics=*/1))) { fprintf(stderr, "Could not create Index\n"); return 1; } idxAction = clang_IndexAction_create(Idx); importedASTs = 0; if (full) importedASTs = importedASTs_create(); result = index_compile_args(argc, argv, idxAction, importedASTs, check_prefix); if (result != 0) goto finished; if (full) { unsigned i; for (i = 0; i < importedASTs->num_files && result == 0; ++i) { result = index_ast_file(importedASTs->filenames[i], Idx, idxAction, importedASTs, check_prefix); } } finished: importedASTs_dispose(importedASTs); clang_IndexAction_dispose(idxAction); clang_disposeIndex(Idx); return result; } static int index_tu(int argc, const char **argv) { const char *check_prefix; CXIndex Idx; CXIndexAction idxAction; int result; check_prefix = 0; if (argc > 0) { if (strstr(argv[0], "-check-prefix=") == argv[0]) { check_prefix = argv[0] + strlen("-check-prefix="); ++argv; --argc; } } if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1, /* displayDiagnostics=*/1))) { fprintf(stderr, "Could not create Index\n"); return 1; } idxAction = clang_IndexAction_create(Idx); result = index_ast_file(argv[0], Idx, idxAction, /*importedASTs=*/0, check_prefix); clang_IndexAction_dispose(idxAction); clang_disposeIndex(Idx); return result; } static int index_compile_db(int argc, const char **argv) { const char *check_prefix; CXIndex Idx; CXIndexAction idxAction; int errorCode = 0; check_prefix = 0; if (argc > 0) { if (strstr(argv[0], "-check-prefix=") == argv[0]) { check_prefix = argv[0] + strlen("-check-prefix="); ++argv; --argc; } } if (argc == 0) { fprintf(stderr, "no compilation database\n"); return -1; } if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1, /* displayDiagnostics=*/1))) { fprintf(stderr, "Could not create Index\n"); return 1; } idxAction = clang_IndexAction_create(Idx); { const char *database = argv[0]; CXCompilationDatabase db = 0; CXCompileCommands CCmds = 0; CXCompileCommand CCmd; CXCompilationDatabase_Error ec; CXString wd; #define MAX_COMPILE_ARGS 512 CXString cxargs[MAX_COMPILE_ARGS]; const char *args[MAX_COMPILE_ARGS]; char *tmp; unsigned len; char *buildDir; int i, a, numCmds, numArgs; len = strlen(database); tmp = (char *) malloc(len+1); memcpy(tmp, database, len+1); buildDir = dirname(tmp); db = clang_CompilationDatabase_fromDirectory(buildDir, &ec); if (db) { if (ec!=CXCompilationDatabase_NoError) { printf("unexpected error %d code while loading compilation database\n", ec); errorCode = -1; goto cdb_end; } if (chdir(buildDir) != 0) { printf("Could not chdir to %s\n", buildDir); errorCode = -1; goto cdb_end; } CCmds = clang_CompilationDatabase_getAllCompileCommands(db); if (!CCmds) { printf("compilation db is empty\n"); errorCode = -1; goto cdb_end; } numCmds = clang_CompileCommands_getSize(CCmds); if (numCmds==0) { fprintf(stderr, "should not get an empty compileCommand set\n"); errorCode = -1; goto cdb_end; } for (i=0; i<numCmds && errorCode == 0; ++i) { CCmd = clang_CompileCommands_getCommand(CCmds, i); wd = clang_CompileCommand_getDirectory(CCmd); if (chdir(clang_getCString(wd)) != 0) { printf("Could not chdir to %s\n", clang_getCString(wd)); errorCode = -1; goto cdb_end; } clang_disposeString(wd); numArgs = clang_CompileCommand_getNumArgs(CCmd); if (numArgs > MAX_COMPILE_ARGS){ fprintf(stderr, "got more compile arguments than maximum\n"); errorCode = -1; goto cdb_end; } for (a=0; a<numArgs; ++a) { cxargs[a] = clang_CompileCommand_getArg(CCmd, a); args[a] = clang_getCString(cxargs[a]); } errorCode = index_compile_args(numArgs, args, idxAction, /*importedASTs=*/0, check_prefix); for (a=0; a<numArgs; ++a) clang_disposeString(cxargs[a]); } } else { printf("database loading failed with error code %d.\n", ec); errorCode = -1; } cdb_end: clang_CompileCommands_dispose(CCmds); clang_CompilationDatabase_dispose(db); free(tmp); } clang_IndexAction_dispose(idxAction); clang_disposeIndex(Idx); return errorCode; } int perform_token_annotation(int argc, const char **argv) { const char *input = argv[1]; char *filename = 0; unsigned line, second_line; unsigned column, second_column; CXIndex CIdx; CXTranslationUnit TU = 0; int errorCode; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; CXToken *tokens; unsigned num_tokens; CXSourceRange range; CXSourceLocation startLoc, endLoc; CXFile file = 0; CXCursor *cursors = 0; CXSourceRangeList *skipped_ranges = 0; enum CXErrorCode Err; unsigned i; input += strlen("-test-annotate-tokens="); if ((errorCode = parse_file_line_column(input, &filename, &line, &column, &second_line, &second_column))) return errorCode; if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files)) { free(filename); return -1; } CIdx = clang_createIndex(0, 1); Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1], argv + num_unsaved_files + 2, argc - num_unsaved_files - 3, unsaved_files, num_unsaved_files, getDefaultParsingOptions(), &TU); if (Err != CXError_Success) { fprintf(stderr, "unable to parse input\n"); describeLibclangFailure(Err); clang_disposeIndex(CIdx); free(filename); free_remapped_files(unsaved_files, num_unsaved_files); return -1; } errorCode = 0; if (checkForErrors(TU) != 0) { errorCode = -1; goto teardown; } if (getenv("CINDEXTEST_EDITING")) { for (i = 0; i < 5; ++i) { Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { fprintf(stderr, "Unable to reparse translation unit!\n"); describeLibclangFailure(Err); errorCode = -1; goto teardown; } } } if (checkForErrors(TU) != 0) { errorCode = -1; goto teardown; } file = clang_getFile(TU, filename); if (!file) { fprintf(stderr, "file %s is not in this translation unit\n", filename); errorCode = -1; goto teardown; } startLoc = clang_getLocation(TU, file, line, column); if (clang_equalLocations(clang_getNullLocation(), startLoc)) { fprintf(stderr, "invalid source location %s:%d:%d\n", filename, line, column); errorCode = -1; goto teardown; } endLoc = clang_getLocation(TU, file, second_line, second_column); if (clang_equalLocations(clang_getNullLocation(), endLoc)) { fprintf(stderr, "invalid source location %s:%d:%d\n", filename, second_line, second_column); errorCode = -1; goto teardown; } range = clang_getRange(startLoc, endLoc); clang_tokenize(TU, range, &tokens, &num_tokens); if (checkForErrors(TU) != 0) { errorCode = -1; goto teardown; } cursors = (CXCursor *)malloc(num_tokens * sizeof(CXCursor)); clang_annotateTokens(TU, tokens, num_tokens, cursors); if (checkForErrors(TU) != 0) { errorCode = -1; goto teardown; } skipped_ranges = clang_getSkippedRanges(TU, file); for (i = 0; i != skipped_ranges->count; ++i) { unsigned start_line, start_column, end_line, end_column; clang_getSpellingLocation(clang_getRangeStart(skipped_ranges->ranges[i]), 0, &start_line, &start_column, 0); clang_getSpellingLocation(clang_getRangeEnd(skipped_ranges->ranges[i]), 0, &end_line, &end_column, 0); printf("Skipping: "); PrintExtent(stdout, start_line, start_column, end_line, end_column); printf("\n"); } clang_disposeSourceRangeList(skipped_ranges); for (i = 0; i != num_tokens; ++i) { const char *kind = "<unknown>"; CXString spelling = clang_getTokenSpelling(TU, tokens[i]); CXSourceRange extent = clang_getTokenExtent(TU, tokens[i]); unsigned start_line, start_column, end_line, end_column; switch (clang_getTokenKind(tokens[i])) { case CXToken_Punctuation: kind = "Punctuation"; break; case CXToken_Keyword: kind = "Keyword"; break; case CXToken_Identifier: kind = "Identifier"; break; case CXToken_Literal: kind = "Literal"; break; case CXToken_Comment: kind = "Comment"; break; } clang_getSpellingLocation(clang_getRangeStart(extent), 0, &start_line, &start_column, 0); clang_getSpellingLocation(clang_getRangeEnd(extent), 0, &end_line, &end_column, 0); printf("%s: \"%s\" ", kind, clang_getCString(spelling)); clang_disposeString(spelling); PrintExtent(stdout, start_line, start_column, end_line, end_column); if (!clang_isInvalid(cursors[i].kind)) { printf(" "); PrintCursor(cursors[i], NULL); } printf("\n"); } free(cursors); clang_disposeTokens(TU, tokens, num_tokens); teardown: PrintDiagnostics(TU); clang_disposeTranslationUnit(TU); clang_disposeIndex(CIdx); free(filename); free_remapped_files(unsaved_files, num_unsaved_files); return errorCode; } static int perform_test_compilation_db(const char *database, int argc, const char **argv) { CXCompilationDatabase db; CXCompileCommands CCmds; CXCompileCommand CCmd; CXCompilationDatabase_Error ec; CXString wd; CXString arg; int errorCode = 0; char *tmp; unsigned len; char *buildDir; int i, j, a, numCmds, numArgs; len = strlen(database); tmp = (char *) malloc(len+1); memcpy(tmp, database, len+1); buildDir = dirname(tmp); db = clang_CompilationDatabase_fromDirectory(buildDir, &ec); if (db) { if (ec!=CXCompilationDatabase_NoError) { printf("unexpected error %d code while loading compilation database\n", ec); errorCode = -1; goto cdb_end; } for (i=0; i<argc && errorCode==0; ) { if (strcmp(argv[i],"lookup")==0){ CCmds = clang_CompilationDatabase_getCompileCommands(db, argv[i+1]); if (!CCmds) { printf("file %s not found in compilation db\n", argv[i+1]); errorCode = -1; break; } numCmds = clang_CompileCommands_getSize(CCmds); if (numCmds==0) { fprintf(stderr, "should not get an empty compileCommand set for file" " '%s'\n", argv[i+1]); errorCode = -1; break; } for (j=0; j<numCmds; ++j) { CCmd = clang_CompileCommands_getCommand(CCmds, j); wd = clang_CompileCommand_getDirectory(CCmd); printf("workdir:'%s'", clang_getCString(wd)); clang_disposeString(wd); printf(" cmdline:'"); numArgs = clang_CompileCommand_getNumArgs(CCmd); for (a=0; a<numArgs; ++a) { if (a) printf(" "); arg = clang_CompileCommand_getArg(CCmd, a); printf("%s", clang_getCString(arg)); clang_disposeString(arg); } printf("'\n"); } clang_CompileCommands_dispose(CCmds); i += 2; } } clang_CompilationDatabase_dispose(db); } else { printf("database loading failed with error code %d.\n", ec); errorCode = -1; } cdb_end: free(tmp); return errorCode; } /******************************************************************************/ /* USR printing. */ /******************************************************************************/ static int insufficient_usr(const char *kind, const char *usage) { fprintf(stderr, "USR for '%s' requires: %s\n", kind, usage); return 1; } static unsigned isUSR(const char *s) { return s[0] == 'c' && s[1] == ':'; } static int not_usr(const char *s, const char *arg) { fprintf(stderr, "'%s' argument ('%s') is not a USR\n", s, arg); return 1; } static void print_usr(CXString usr) { const char *s = clang_getCString(usr); printf("%s\n", s); clang_disposeString(usr); } static void display_usrs() { fprintf(stderr, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n" " ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n" " ObjCMethod <selector> [0=class method|1=instance method] " "<class USR>\n" " ObjCProperty <property name> <class USR>\n" " ObjCProtocol <protocol name>\n"); } int print_usrs(const char **I, const char **E) { while (I != E) { const char *kind = *I; unsigned len = strlen(kind); switch (len) { case 8: if (memcmp(kind, "ObjCIvar", 8) == 0) { if (I + 2 >= E) return insufficient_usr(kind, "<ivar name> <class USR>"); if (!isUSR(I[2])) return not_usr("<class USR>", I[2]); else { CXString x; x.data = (void*) I[2]; x.private_flags = 0; print_usr(clang_constructUSR_ObjCIvar(I[1], x)); } I += 3; continue; } break; case 9: if (memcmp(kind, "ObjCClass", 9) == 0) { if (I + 1 >= E) return insufficient_usr(kind, "<class name>"); print_usr(clang_constructUSR_ObjCClass(I[1])); I += 2; continue; } break; case 10: if (memcmp(kind, "ObjCMethod", 10) == 0) { if (I + 3 >= E) return insufficient_usr(kind, "<method selector> " "[0=class method|1=instance method] <class USR>"); if (!isUSR(I[3])) return not_usr("<class USR>", I[3]); else { CXString x; x.data = (void*) I[3]; x.private_flags = 0; print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x)); } I += 4; continue; } break; case 12: if (memcmp(kind, "ObjCCategory", 12) == 0) { if (I + 2 >= E) return insufficient_usr(kind, "<class name> <category name>"); print_usr(clang_constructUSR_ObjCCategory(I[1], I[2])); I += 3; continue; } if (memcmp(kind, "ObjCProtocol", 12) == 0) { if (I + 1 >= E) return insufficient_usr(kind, "<protocol name>"); print_usr(clang_constructUSR_ObjCProtocol(I[1])); I += 2; continue; } if (memcmp(kind, "ObjCProperty", 12) == 0) { if (I + 2 >= E) return insufficient_usr(kind, "<property name> <class USR>"); if (!isUSR(I[2])) return not_usr("<class USR>", I[2]); else { CXString x; x.data = (void*) I[2]; x.private_flags = 0; print_usr(clang_constructUSR_ObjCProperty(I[1], x)); } I += 3; continue; } break; default: break; } break; } if (I != E) { fprintf(stderr, "Invalid USR kind: %s\n", *I); display_usrs(); return 1; } return 0; } int print_usrs_file(const char *file_name) { char line[2048]; const char *args[128]; unsigned numChars = 0; FILE *fp = fopen(file_name, "r"); if (!fp) { fprintf(stderr, "error: cannot open '%s'\n", file_name); return 1; } /* This code is not really all that safe, but it works fine for testing. */ while (!feof(fp)) { char c = fgetc(fp); if (c == '\n') { unsigned i = 0; const char *s = 0; if (numChars == 0) continue; line[numChars] = '\0'; numChars = 0; if (line[0] == '/' && line[1] == '/') continue; s = strtok(line, " "); while (s) { args[i] = s; ++i; s = strtok(0, " "); } if (print_usrs(&args[0], &args[i])) return 1; } else line[numChars++] = c; } fclose(fp); return 0; } /******************************************************************************/ /* Command line processing. */ /******************************************************************************/ int write_pch_file(const char *filename, int argc, const char *argv[]) { CXIndex Idx; CXTranslationUnit TU; struct CXUnsavedFile *unsaved_files = 0; int num_unsaved_files = 0; enum CXErrorCode Err; int result = 0; Idx = clang_createIndex(/* excludeDeclsFromPCH */1, /* displayDiagnostics=*/1); if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) { clang_disposeIndex(Idx); return -1; } Err = clang_parseTranslationUnit2( Idx, 0, argv + num_unsaved_files, argc - num_unsaved_files, unsaved_files, num_unsaved_files, CXTranslationUnit_Incomplete | CXTranslationUnit_DetailedPreprocessingRecord | CXTranslationUnit_ForSerialization, &TU); if (Err != CXError_Success) { fprintf(stderr, "Unable to load translation unit!\n"); describeLibclangFailure(Err); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeTranslationUnit(TU); clang_disposeIndex(Idx); return 1; } switch (clang_saveTranslationUnit(TU, filename, clang_defaultSaveOptions(TU))) { case CXSaveError_None: break; case CXSaveError_TranslationErrors: fprintf(stderr, "Unable to write PCH file %s: translation errors\n", filename); result = 2; break; case CXSaveError_InvalidTU: fprintf(stderr, "Unable to write PCH file %s: invalid translation unit\n", filename); result = 3; break; case CXSaveError_Unknown: default: fprintf(stderr, "Unable to write PCH file %s: unknown error \n", filename); result = 1; break; } clang_disposeTranslationUnit(TU); free_remapped_files(unsaved_files, num_unsaved_files); clang_disposeIndex(Idx); return result; } /******************************************************************************/ /* Serialized diagnostics. */ /******************************************************************************/ static const char *getDiagnosticCodeStr(enum CXLoadDiag_Error error) { switch (error) { case CXLoadDiag_CannotLoad: return "Cannot Load File"; case CXLoadDiag_None: break; case CXLoadDiag_Unknown: return "Unknown"; case CXLoadDiag_InvalidFile: return "Invalid File"; } return "None"; } static const char *getSeverityString(enum CXDiagnosticSeverity severity) { switch (severity) { case CXDiagnostic_Note: return "note"; case CXDiagnostic_Error: return "error"; case CXDiagnostic_Fatal: return "fatal"; case CXDiagnostic_Ignored: return "ignored"; case CXDiagnostic_Warning: return "warning"; } return "unknown"; } static void printIndent(unsigned indent) { if (indent == 0) return; fprintf(stderr, "+"); --indent; while (indent > 0) { fprintf(stderr, "-"); --indent; } } static void printLocation(CXSourceLocation L) { CXFile File; CXString FileName; unsigned line, column, offset; clang_getExpansionLocation(L, &File, &line, &column, &offset); FileName = clang_getFileName(File); fprintf(stderr, "%s:%d:%d", clang_getCString(FileName), line, column); clang_disposeString(FileName); } static void printRanges(CXDiagnostic D, unsigned indent) { unsigned i, n = clang_getDiagnosticNumRanges(D); for (i = 0; i < n; ++i) { CXSourceLocation Start, End; CXSourceRange SR = clang_getDiagnosticRange(D, i); Start = clang_getRangeStart(SR); End = clang_getRangeEnd(SR); printIndent(indent); fprintf(stderr, "Range: "); printLocation(Start); fprintf(stderr, " "); printLocation(End); fprintf(stderr, "\n"); } } static void printFixIts(CXDiagnostic D, unsigned indent) { unsigned i, n = clang_getDiagnosticNumFixIts(D); fprintf(stderr, "Number FIXITs = %d\n", n); for (i = 0 ; i < n; ++i) { CXSourceRange ReplacementRange; CXString text; text = clang_getDiagnosticFixIt(D, i, &ReplacementRange); printIndent(indent); fprintf(stderr, "FIXIT: ("); printLocation(clang_getRangeStart(ReplacementRange)); fprintf(stderr, " - "); printLocation(clang_getRangeEnd(ReplacementRange)); fprintf(stderr, "): \"%s\"\n", clang_getCString(text)); clang_disposeString(text); } } static void printDiagnosticSet(CXDiagnosticSet Diags, unsigned indent) { unsigned i, n; if (!Diags) return; n = clang_getNumDiagnosticsInSet(Diags); for (i = 0; i < n; ++i) { CXSourceLocation DiagLoc; CXDiagnostic D; CXFile File; CXString FileName, DiagSpelling, DiagOption, DiagCat; unsigned line, column, offset; const char *DiagOptionStr = 0, *DiagCatStr = 0; D = clang_getDiagnosticInSet(Diags, i); DiagLoc = clang_getDiagnosticLocation(D); clang_getExpansionLocation(DiagLoc, &File, &line, &column, &offset); FileName = clang_getFileName(File); DiagSpelling = clang_getDiagnosticSpelling(D); printIndent(indent); fprintf(stderr, "%s:%d:%d: %s: %s", clang_getCString(FileName), line, column, getSeverityString(clang_getDiagnosticSeverity(D)), clang_getCString(DiagSpelling)); DiagOption = clang_getDiagnosticOption(D, 0); DiagOptionStr = clang_getCString(DiagOption); if (DiagOptionStr) { fprintf(stderr, " [%s]", DiagOptionStr); } DiagCat = clang_getDiagnosticCategoryText(D); DiagCatStr = clang_getCString(DiagCat); if (DiagCatStr) { fprintf(stderr, " [%s]", DiagCatStr); } fprintf(stderr, "\n"); printRanges(D, indent); printFixIts(D, indent); /* Print subdiagnostics. */ printDiagnosticSet(clang_getChildDiagnostics(D), indent+2); clang_disposeString(FileName); clang_disposeString(DiagSpelling); clang_disposeString(DiagOption); clang_disposeString(DiagCat); } } static int read_diagnostics(const char *filename) { enum CXLoadDiag_Error error; CXString errorString; CXDiagnosticSet Diags = 0; Diags = clang_loadDiagnostics(filename, &error, &errorString); if (!Diags) { fprintf(stderr, "Trouble deserializing file (%s): %s\n", getDiagnosticCodeStr(error), clang_getCString(errorString)); clang_disposeString(errorString); return 1; } printDiagnosticSet(Diags, 0); fprintf(stderr, "Number of diagnostics: %d\n", clang_getNumDiagnosticsInSet(Diags)); clang_disposeDiagnosticSet(Diags); return 0; } static int perform_print_build_session_timestamp(void) { printf("%lld\n", clang_getBuildSessionTimestamp()); return 0; } /******************************************************************************/ /* Command line processing. */ /******************************************************************************/ static CXCursorVisitor GetVisitor(const char *s) { if (s[0] == '\0') return FilteredPrintingVisitor; if (strcmp(s, "-usrs") == 0) return USRVisitor; if (strncmp(s, "-memory-usage", 13) == 0) return GetVisitor(s + 13); return NULL; } static void print_usage(void) { fprintf(stderr, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n" " c-index-test -code-completion-timing=<site> <compiler arguments>\n" " c-index-test -cursor-at=<site> <compiler arguments>\n" " c-index-test -file-refs-at=<site> <compiler arguments>\n" " c-index-test -file-includes-in=<filename> <compiler arguments>\n"); fprintf(stderr, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n" " c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n" " c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n" " c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n" " c-index-test -test-file-scan <AST file> <source file> " "[FileCheck prefix]\n"); fprintf(stderr, " c-index-test -test-load-tu <AST file> <symbol filter> " "[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> " "[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"); fprintf(stderr, " c-index-test -test-load-source-memory-usage " "<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> " " {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n" " c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n" " c-index-test -test-annotate-tokens=<range> {<args>}*\n" " c-index-test -test-inclusion-stack-source {<args>}*\n" " c-index-test -test-inclusion-stack-tu <AST file>\n"); fprintf(stderr, " c-index-test -test-print-linkage-source {<args>}*\n" " c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n" " c-index-test -test-print-bitwidth {<args>}*\n" " c-index-test -print-usr [<CursorKind> {<args>}]*\n" " c-index-test -print-usr-file <file>\n" " c-index-test -write-pch <file> <compiler arguments>\n"); fprintf(stderr, " c-index-test -compilation-db [lookup <filename>] database\n"); fprintf(stderr, " c-index-test -print-build-session-timestamp\n"); fprintf(stderr, " c-index-test -read-diagnostics <file>\n\n"); fprintf(stderr, " <symbol filter> values:\n%s", " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n" " category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n" " protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n" " typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"); } /***/ int cindextest_main(int argc, const char **argv) { clang_enableStackTraces(); if (argc > 2 && strcmp(argv[1], "-read-diagnostics") == 0) return read_diagnostics(argv[2]); if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1]) return perform_code_completion(argc, argv, 0); if (argc > 2 && strstr(argv[1], "-code-completion-timing=") == argv[1]) return perform_code_completion(argc, argv, 1); if (argc > 2 && strstr(argv[1], "-cursor-at=") == argv[1]) return inspect_cursor_at(argc, argv); if (argc > 2 && strstr(argv[1], "-file-refs-at=") == argv[1]) return find_file_refs_at(argc, argv); if (argc > 2 && strstr(argv[1], "-file-includes-in=") == argv[1]) return find_file_includes_in(argc, argv); if (argc > 2 && strcmp(argv[1], "-index-file") == 0) return index_file(argc - 2, argv + 2, /*full=*/0); if (argc > 2 && strcmp(argv[1], "-index-file-full") == 0) return index_file(argc - 2, argv + 2, /*full=*/1); if (argc > 2 && strcmp(argv[1], "-index-tu") == 0) return index_tu(argc - 2, argv + 2); if (argc > 2 && strcmp(argv[1], "-index-compile-db") == 0) return index_compile_db(argc - 2, argv + 2); else if (argc >= 4 && strncmp(argv[1], "-test-load-tu", 13) == 0) { CXCursorVisitor I = GetVisitor(argv[1] + 13); if (I) return perform_test_load_tu(argv[2], argv[3], argc >= 5 ? argv[4] : 0, I, NULL); } else if (argc >= 5 && strncmp(argv[1], "-test-load-source-reparse", 25) == 0){ CXCursorVisitor I = GetVisitor(argv[1] + 25); if (I) { int trials = atoi(argv[2]); return perform_test_reparse_source(argc - 4, argv + 4, trials, argv[3], I, NULL); } } else if (argc >= 4 && strncmp(argv[1], "-test-load-source", 17) == 0) { CXCursorVisitor I = GetVisitor(argv[1] + 17); PostVisitTU postVisit = 0; if (strstr(argv[1], "-memory-usage")) postVisit = PrintMemoryUsage; if (I) return perform_test_load_source(argc - 3, argv + 3, argv[2], I, postVisit); } else if (argc >= 4 && strcmp(argv[1], "-test-file-scan") == 0) return perform_file_scan(argv[2], argv[3], argc >= 5 ? argv[4] : 0); else if (argc > 2 && strstr(argv[1], "-test-annotate-tokens=") == argv[1]) return perform_token_annotation(argc, argv); else if (argc > 2 && strcmp(argv[1], "-test-inclusion-stack-source") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", NULL, PrintInclusionStack); else if (argc > 2 && strcmp(argv[1], "-test-inclusion-stack-tu") == 0) return perform_test_load_tu(argv[2], "all", NULL, NULL, PrintInclusionStack); else if (argc > 2 && strcmp(argv[1], "-test-print-linkage-source") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage, NULL); else if (argc > 2 && strcmp(argv[1], "-test-print-type") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintType, 0); else if (argc > 2 && strcmp(argv[1], "-test-print-type-size") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintTypeSize, 0); else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintBitWidth, 0); else if (argc > 2 && strcmp(argv[1], "-test-print-mangle") == 0) return perform_test_load_tu(argv[2], "all", NULL, PrintMangledName, NULL); else if (argc > 1 && strcmp(argv[1], "-print-usr") == 0) { if (argc > 2) return print_usrs(argv + 2, argv + argc); else { display_usrs(); return 1; } } else if (argc > 2 && strcmp(argv[1], "-print-usr-file") == 0) return print_usrs_file(argv[2]); else if (argc > 2 && strcmp(argv[1], "-write-pch") == 0) return write_pch_file(argv[2], argc - 3, argv + 3); else if (argc > 2 && strcmp(argv[1], "-compilation-db") == 0) return perform_test_compilation_db(argv[argc-1], argc - 3, argv + 2); else if (argc == 2 && strcmp(argv[1], "-print-build-session-timestamp") == 0) return perform_print_build_session_timestamp(); print_usage(); return 1; } /***/ /* We intentionally run in a separate thread to ensure we at least minimal * testing of a multithreaded environment (for example, having a reduced stack * size). */ typedef struct thread_info { int argc; const char **argv; int result; } thread_info; void thread_runner(void *client_data_v) { thread_info *client_data = client_data_v; client_data->result = cindextest_main(client_data->argc, client_data->argv); } static void flush_atexit(void) { /* stdout, and surprisingly even stderr, are not always flushed on process * and thread exit, particularly when the system is under heavy load. */ fflush(stdout); fflush(stderr); } int main(int argc, const char **argv) { thread_info client_data; atexit(flush_atexit); #ifdef CLANG_HAVE_LIBXML LIBXML_TEST_VERSION #endif if (getenv("CINDEXTEST_NOTHREADS")) return cindextest_main(argc, argv); client_data.argc = argc; client_data.argv = argv; clang_executeOnThread(thread_runner, &client_data, 0); return client_data.result; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxa/dxa.rc
// Copyright (c) Microsoft Corporation. All rights reserved. // #include <windows.h> #include <ntverp.h> #define VER_FILETYPE VFT_DLL #define VER_FILESUBTYPE VFT_UNKNOWN #define VER_FILEDESCRIPTION_STR "DX Assembler" #define VER_INTERNALNAME_STR "DX Assembler" #define VER_ORIGINALFILENAME_STR "dxa.exe" #include <common.ver>
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxa/CMakeLists.txt
# Copyright (C) Microsoft Corporation. All rights reserved. # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. # Builds dxa.exe if (MSVC) find_package(DiaSDK REQUIRED) # Used for constants and declarations. endif (MSVC) set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} DXIL DxilContainer DxilRootSignature HLSL dxcsupport Option # option library MSSupport # for CreateMSFileSystemForDisk ) add_clang_executable(dxa dxa.cpp ) target_link_libraries(dxa dxcompiler ) set_target_properties(dxa PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION}) if (MSVC) include_directories(AFTER ${DIASDK_INCLUDE_DIRS}) endif (MSVC) add_dependencies(dxa dxcompiler) if(UNIX) set(CLANGXX_LINK_OR_COPY create_symlink) # Create a relative symlink set(dxa_binary "dxa${CMAKE_EXECUTABLE_SUFFIX}") else() set(CLANGXX_LINK_OR_COPY copy) set(dxa_binary "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/dxa${CMAKE_EXECUTABLE_SUFFIX}") endif() install(TARGETS dxa RUNTIME DESTINATION bin)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxa/dxa.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxa.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides the entry point for the dxa console program. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/Global.h" #include "dxc/Support/Unicode.h" #include "dxc/Support/WinIncludes.h" #include "dxc/DxilContainer/DxilContainer.h" #include "dxc/DxilContainer/DxilPipelineStateValidation.h" #include "dxc/DxilRootSignature/DxilRootSignature.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/dxcapi.use.h" #include "dxc/Test/D3DReflectionDumper.h" #include "dxc/Test/RDATDumper.h" #include "dxc/dxcapi.h" #include "llvm/Support//MSFileSystem.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace llvm::opt; using namespace dxc; using namespace hlsl::options; static cl::opt<bool> Help("help", cl::desc("Print help")); static cl::alias Help_h("h", cl::aliasopt(Help)); static cl::alias Help_q("?", cl::aliasopt(Help)); static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input .llvm file>")); static cl::opt<std::string> OutputFilename("o", cl::desc("Override output filename"), cl::value_desc("filename")); static cl::opt<bool> ListParts("listparts", cl::desc("List parts in input container"), cl::init(false)); static cl::opt<std::string> ExtractPart("extractpart", cl::desc("Extract one part from input container (use 'module' " "or 'dbgmodule' for a .ll file)")); static cl::opt<bool> ListFiles("listfiles", cl::desc("List files in input container"), cl::init(false)); static cl::opt<std::string> ExtractFile( "extractfile", cl::desc("Extract file from debug information (use '*' for all files)")); static cl::opt<bool> DumpRootSig("dumprs", cl::desc("Dump root signature"), cl::init(false)); static cl::opt<bool> DumpRDAT("dumprdat", cl::desc("Dump RDAT"), cl::init(false)); static cl::opt<bool> DumpReflection("dumpreflection", cl::desc("Dump reflection"), cl::init(false)); static cl::opt<bool> DumpHash("dumphash", cl::desc("Dump validation hash"), cl::init(false)); static cl::opt<bool> DumpPSV("dumppsv", cl::desc("Dump pipeline state validation"), cl::init(false)); class DxaContext { private: DxcDllSupport &m_dxcSupport; HRESULT FindModule(hlsl::DxilFourCC fourCC, IDxcBlob *pSource, IDxcLibrary *pLibrary, IDxcBlob **ppTarget); bool ExtractPart(uint32_t Part, IDxcBlob **ppTargetBlob); bool ExtractPart(IDxcBlob *pSource, uint32_t Part, IDxcBlob **ppTargetBlob); public: DxaContext(DxcDllSupport &dxcSupport) : m_dxcSupport(dxcSupport) {} void Assemble(); bool ExtractFile(const char *pName); bool ExtractPart(const char *pName); void ListFiles(); void ListParts(); void DumpRS(); void DumpRDAT(); void DumpReflection(); void DumpValidationHash(); void DumpPSV(); }; void DxaContext::Assemble() { CComPtr<IDxcOperationResult> pAssembleResult; { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); CComPtr<IDxcAssembler> pAssembler; IFT(m_dxcSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler)); IFT(pAssembler->AssembleToContainer(pSource, &pAssembleResult)); } CComPtr<IDxcBlobEncoding> pErrors; CComPtr<IDxcBlobUtf8> pErrorsUtf8; pAssembleResult->GetErrorBuffer(&pErrors); if (pErrors && pErrors->GetBufferSize() > 1) { IFT(pErrors->QueryInterface(IID_PPV_ARGS(&pErrorsUtf8))); printf("Errors or warnings:\n%s", pErrorsUtf8->GetStringPointer()); } HRESULT status; IFT(pAssembleResult->GetStatus(&status)); if (SUCCEEDED(status)) { printf("Assembly succeeded.\n"); CComPtr<IDxcBlob> pContainer; IFT(pAssembleResult->GetResult(&pContainer)); if (pContainer.p != nullptr) { // Infer the output filename if needed. if (OutputFilename.empty()) { if (InputFilename == "-") { OutputFilename = "-"; } else { StringRef IFN = InputFilename; OutputFilename = (IFN.endswith(".ll") ? IFN.drop_back(3) : IFN).str(); OutputFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str(); OutputFilename += ".dxbc"; } } WriteBlobToFile(pContainer, StringRefWide(OutputFilename), DXC_CP_ACP); printf("Output written to \"%s\"\n", OutputFilename.c_str()); } } else { printf("Assembly failed.\n"); } } // Finds DXIL module from the blob assuming blob is either DxilContainer, // DxilPartHeader, or DXIL module HRESULT DxaContext::FindModule(hlsl::DxilFourCC fourCC, IDxcBlob *pSource, IDxcLibrary *pLibrary, IDxcBlob **ppTargetBlob) { if (!pSource || !pLibrary || !ppTargetBlob) return E_INVALIDARG; const UINT32 BC_C0DE = ((INT32)(INT8)'B' | (INT32)(INT8)'C' << 8 | (INT32)0xDEC0 << 16); // BC0xc0de in big endian const char *pBitcode = nullptr; const hlsl::DxilPartHeader *pDxilPartHeader = (hlsl::DxilPartHeader *) pSource->GetBufferPointer(); // Initialize assuming that source is // starting with DXIL part if (BC_C0DE == *(UINT32 *)pSource->GetBufferPointer()) { *ppTargetBlob = pSource; pSource->AddRef(); return S_OK; } if (hlsl::IsValidDxilContainer( (hlsl::DxilContainerHeader *)pSource->GetBufferPointer(), pSource->GetBufferSize())) { hlsl::DxilContainerHeader *pDxilContainerHeader = (hlsl::DxilContainerHeader *)pSource->GetBufferPointer(); pDxilPartHeader = *std::find_if(begin(pDxilContainerHeader), end(pDxilContainerHeader), hlsl::DxilPartIsType(fourCC)); } if (fourCC == pDxilPartHeader->PartFourCC) { UINT32 pBlobSize; const hlsl::DxilProgramHeader *pDxilProgramHeader = (const hlsl::DxilProgramHeader *)(pDxilPartHeader + 1); hlsl::GetDxilProgramBitcode(pDxilProgramHeader, &pBitcode, &pBlobSize); UINT32 offset = (UINT32)(pBitcode - (const char *)pSource->GetBufferPointer()); pLibrary->CreateBlobFromBlob(pSource, offset, pBlobSize, ppTargetBlob); return S_OK; } return E_INVALIDARG; } void DxaContext::ListFiles() { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); CComPtr<IDxcPdbUtils> pPdbUtils; IFT(m_dxcSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils)); IFT(pPdbUtils->Load(pSource)); UINT32 uNumSources = 0; IFT(pPdbUtils->GetSourceCount(&uNumSources)); for (UINT32 i = 0; i < uNumSources; i++) { CComBSTR name; IFT(pPdbUtils->GetSourceName(i, &name)); printf("%S\r\n", (LPWSTR)name); } } bool DxaContext::ExtractFile(const char *pName) { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); CComPtr<IDxcPdbUtils> pPdbUtils; IFT(m_dxcSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils)); IFT(pPdbUtils->Load(pSource)); UINT32 uNumSources = 0; IFT(pPdbUtils->GetSourceCount(&uNumSources)); bool printedAny = false; CA2W WideName(pName); for (UINT32 i = 0; i < uNumSources; i++) { CComBSTR name; IFT(pPdbUtils->GetSourceName(i, &name)); if (strcmp("*", pName) == 0 || wcscmp((LPWSTR)name, WideName) == 0) { printedAny = true; CComPtr<IDxcBlobEncoding> pFileContent; IFT(pPdbUtils->GetSource(i, &pFileContent)); printf("%.*s", (int)pFileContent->GetBufferSize(), (char *)pFileContent->GetBufferPointer()); } } return printedAny; } bool DxaContext::ExtractPart(uint32_t PartKind, IDxcBlob **ppTargetBlob) { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); return ExtractPart(pSource, PartKind, ppTargetBlob); } bool DxaContext::ExtractPart(IDxcBlob *pSource, uint32_t PartKind, IDxcBlob **ppTargetBlob) { CComPtr<IDxcContainerReflection> pReflection; UINT32 partCount; IFT(m_dxcSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection)); IFT(pReflection->Load(pSource)); IFT(pReflection->GetPartCount(&partCount)); for (UINT32 i = 0; i < partCount; ++i) { UINT32 curPartKind; IFT(pReflection->GetPartKind(i, &curPartKind)); if (curPartKind == PartKind) { CComPtr<IDxcBlob> pContent; IFT(pReflection->GetPartContent(i, ppTargetBlob)); return true; } } return false; } bool DxaContext::ExtractPart(const char *pName) { // If the part name is 'module', don't just extract the part, // but also skip the appropriate header. bool extractModule = strcmp("module", pName) == 0; if (extractModule) { pName = "DXIL"; } if (strcmp("dbgmodule", pName) == 0) { pName = "ILDB"; extractModule = true; } IFTARG(strlen(pName) == 4); const UINT32 matchName = ((UINT32)pName[0] | ((UINT32)pName[1] << 8) | ((UINT32)pName[2] << 16) | ((UINT32)pName[3] << 24)); CComPtr<IDxcBlob> pContent; if (!ExtractPart(matchName, &pContent)) return false; if (OutputFilename.empty()) { if (InputFilename == "-") { OutputFilename = "-"; } else { OutputFilename = InputFilename.getValue(); OutputFilename += "."; if (extractModule) { OutputFilename += "ll"; } else { OutputFilename += pName; } } } if (extractModule) { char *pDxilPart = (char *)pContent->GetBufferPointer(); hlsl::DxilProgramHeader *pProgramHdr = (hlsl::DxilProgramHeader *)pDxilPart; const char *pBitcode; uint32_t bitcodeLength; GetDxilProgramBitcode(pProgramHdr, &pBitcode, &bitcodeLength); uint32_t offset = pBitcode - pDxilPart; CComPtr<IDxcLibrary> pLib; CComPtr<IDxcBlob> pModuleBlob; IFT(m_dxcSupport.CreateInstance(CLSID_DxcLibrary, &pLib)); IFT(pLib->CreateBlobFromBlob(pContent, offset, bitcodeLength, &pModuleBlob)); std::swap(pModuleBlob, pContent); } WriteBlobToFile(pContent, StringRefWide(OutputFilename), DXC_CP_UTF8); // TODO: Support DefaultTextCodePage printf("%zu bytes written to %s\n", (size_t)pContent->GetBufferSize(), OutputFilename.c_str()); return true; } void DxaContext::ListParts() { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); CComPtr<IDxcContainerReflection> pReflection; IFT(m_dxcSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection)); IFT(pReflection->Load(pSource)); UINT32 partCount; IFT(pReflection->GetPartCount(&partCount)); printf("Part count: %u\n", partCount); for (UINT32 i = 0; i < partCount; ++i) { UINT32 partKind; IFT(pReflection->GetPartKind(i, &partKind)); // Part kind is typically four characters. char kindText[5]; hlsl::PartKindToCharArray(partKind, kindText); CComPtr<IDxcBlob> partContent; IFT(pReflection->GetPartContent(i, &partContent)); printf("#%u - %s (%u bytes)\n", i, kindText, (unsigned)partContent->GetBufferSize()); } } void DxaContext::DumpRS() { const char *pName = "RTS0"; const UINT32 matchName = ((UINT32)pName[0] | ((UINT32)pName[1] << 8) | ((UINT32)pName[2] << 16) | ((UINT32)pName[3] << 24)); CComPtr<IDxcBlob> pContent; if (!ExtractPart(matchName, &pContent)) { printf("cannot find root signature part"); return; } const void *serializedData = pContent->GetBufferPointer(); uint32_t serializedSize = pContent->GetBufferSize(); hlsl::RootSignatureHandle rootsig; rootsig.LoadSerialized(static_cast<const uint8_t *>(serializedData), serializedSize); try { rootsig.Deserialize(); } catch (const hlsl::Exception &e) { printf("fail to deserialize root sig %s", e.msg.c_str()); return; } if (const hlsl::DxilVersionedRootSignatureDesc *pRS = rootsig.GetDesc()) { std::string str; llvm::raw_string_ostream os(str); hlsl::printRootSignature(*pRS, os); printf("%s", str.c_str()); } } void DxaContext::DumpRDAT() { CComPtr<IDxcBlob> pPart; CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); if (pSource->GetBufferSize() < sizeof(hlsl::RDAT::RuntimeDataHeader)) { printf("Invalid input file, use binary DxilContainer or raw RDAT part."); return; } // If DXBC, extract part, otherwise, try to read raw RDAT binary. if (hlsl::DFCC_Container == *(UINT *)pSource->GetBufferPointer()) { if (!ExtractPart(pSource, hlsl::DFCC_RuntimeData, &pPart)) { printf("cannot find RDAT part"); return; } } else if (hlsl::RDAT::RDAT_Version_10 != *(UINT *)pSource->GetBufferPointer()) { printf("Invalid input file, use binary DxilContainer or raw RDAT part."); return; } else { pPart = pSource; // Try assuming the source is pure RDAT part } hlsl::RDAT::DxilRuntimeData rdat; if (!rdat.InitFromRDAT(pPart->GetBufferPointer(), pPart->GetBufferSize())) { // If any error occurred trying to read as RDAT, assume it's not the right // kind of input. printf("Invalid input file, use binary DxilContainer or raw RDAT part."); return; } std::ostringstream ss; hlsl::dump::DumpContext d(ss); hlsl::dump::DumpRuntimeData(rdat, d); printf("%s", ss.str().c_str()); } void DxaContext::DumpReflection() { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); CComPtr<IDxcContainerReflection> pReflection; IFT(m_dxcSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection)); IFT(pReflection->Load(pSource)); UINT32 partCount; IFT(pReflection->GetPartCount(&partCount)); bool blobFound = false; std::ostringstream ss; hlsl::dump::D3DReflectionDumper dumper(ss); CComPtr<ID3D12ShaderReflection> pShaderReflection; CComPtr<ID3D12LibraryReflection> pLibraryReflection; for (uint32_t i = 0; i < partCount; ++i) { uint32_t kind; IFT(pReflection->GetPartKind(i, &kind)); if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_DXIL) { blobFound = true; CComPtr<IDxcBlob> pPart; IFT(pReflection->GetPartContent(i, &pPart)); const hlsl::DxilProgramHeader *pProgramHeader = reinterpret_cast<const hlsl::DxilProgramHeader *>( pPart->GetBufferPointer()); IFT(IsValidDxilProgramHeader(pProgramHeader, (uint32_t)pPart->GetBufferSize())); hlsl::DXIL::ShaderKind SK = hlsl::GetVersionShaderType(pProgramHeader->ProgramVersion); if (SK == hlsl::DXIL::ShaderKind::Library) { IFT(pReflection->GetPartReflection(i, IID_PPV_ARGS(&pLibraryReflection))); } else { IFT(pReflection->GetPartReflection(i, IID_PPV_ARGS(&pShaderReflection))); } break; } else if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_RuntimeData) { CComPtr<IDxcBlob> pPart; IFT(pReflection->GetPartContent(i, &pPart)); hlsl::RDAT::DxilRuntimeData rdat(pPart->GetBufferPointer(), pPart->GetBufferSize()); hlsl::dump::DumpContext d(ss); DumpRuntimeData(rdat, d); } } if (!blobFound) { printf("Unable to find DXIL part"); return; } else if (pShaderReflection) { dumper.Dump(pShaderReflection); } else if (pLibraryReflection) { dumper.Dump(pLibraryReflection); } ss.flush(); printf("%s", ss.str().c_str()); } void DxaContext::DumpValidationHash() { CComPtr<IDxcBlobEncoding> pSource; ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource); if (!hlsl::IsValidDxilContainer( (hlsl::DxilContainerHeader *)pSource->GetBufferPointer(), pSource->GetBufferSize())) { printf("Invalid input file, use binary DxilContainer."); return; } hlsl::DxilContainerHeader *pDxilContainerHeader = (hlsl::DxilContainerHeader *)pSource->GetBufferPointer(); printf("Validation hash: 0x"); for (size_t i = 0; i < hlsl::DxilContainerHashSize; i++) { printf("%02x", pDxilContainerHeader->Hash.Digest[i]); } } void DxaContext::DumpPSV() { CComPtr<IDxcBlob> pContent; if (!ExtractPart(hlsl::DFCC_PipelineStateValidation, &pContent)) { printf("cannot find PSV part"); return; } DxilPipelineStateValidation PSV; if (!PSV.InitFromPSV0(pContent->GetBufferPointer(), pContent->GetBufferSize())) { printf("fail to read PSV part"); return; } std::string Str; llvm::raw_string_ostream OS(Str); PSV.Print(OS, static_cast<uint8_t>(PSVShaderKind::Library)); for (char &c : Str) { printf("%c", c); } } using namespace hlsl::options; #ifdef _WIN32 int __cdecl main(int argc, char **argv) { #else int main(int argc, const char **argv) { #endif if (llvm::sys::fs::SetupPerThreadFileSystem()) return 1; llvm::sys::fs::AutoCleanupPerThreadFileSystem auto_cleanup_fs; if (FAILED(DxcInitThreadMalloc())) return 1; DxcSetThreadMallocToDefault(); const char *pStage = "Operation"; try { llvm::sys::fs::MSFileSystem *msfPtr; IFT(CreateMSFileSystemForDisk(&msfPtr)); std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr); ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get()); IFTLLVM(pts.error_code()); pStage = "Argument processing"; // Parse command line options. cl::ParseCommandLineOptions(argc, argv, "dxil assembly\n"); if (InputFilename == "" || Help) { cl::PrintHelpMessage(); return 2; } DxcDllSupport dxcSupport; dxc::EnsureEnabled(dxcSupport); DxaContext context(dxcSupport); if (ListParts) { pStage = "Listing parts"; context.ListParts(); } else if (ListFiles) { pStage = "Listing files"; context.ListFiles(); } else if (!ExtractPart.empty()) { pStage = "Extracting part"; if (!context.ExtractPart(ExtractPart.c_str())) { return 1; } } else if (!ExtractFile.empty()) { pStage = "Extracting files"; if (!context.ExtractFile(ExtractFile.c_str())) { return 1; } } else if (DumpRootSig) { pStage = "Dump root sig"; context.DumpRS(); } else if (DumpRDAT) { pStage = "Dump RDAT"; context.DumpRDAT(); } else if (DumpReflection) { pStage = "Dump Reflection"; context.DumpReflection(); } else if (DumpHash) { pStage = "Dump Validation Hash"; context.DumpValidationHash(); } else if (DumpPSV) { pStage = "Dump Pipeline State Validation"; context.DumpPSV(); } else { pStage = "Assembling"; context.Assemble(); } } catch (const ::hlsl::Exception &hlslException) { try { const char *msg = hlslException.what(); Unicode::acp_char printBuffer[128]; // printBuffer is safe to treat as // UTF-8 because we use ASCII only // errors only if (msg == nullptr || *msg == '\0') { sprintf_s(printBuffer, _countof(printBuffer), "Assembly failed - error code 0x%08x.", hlslException.hr); msg = printBuffer; } printf("%s\n", msg); } catch (...) { printf("%s failed - unable to retrieve error message.\n", pStage); } return 1; } catch (std::bad_alloc &) { printf("%s failed - out of memory.\n", pStage); return 1; } catch (...) { printf("%s failed - unknown error.\n", pStage); return 1; } return 0; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxcapi.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements the DxcCreateInstance function for the DirectX Compiler. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/WinIncludes.h" #define DXC_API_IMPORT __declspec(dllexport) #include "dxc/Support/Global.h" #include "dxc/dxcdxrfallbackcompiler.h" #include "dxc/dxctools.h" #include "dxcetw.h" #include <memory> HRESULT CreateDxcDxrFallbackCompiler(REFIID riid, LPVOID *ppv); static HRESULT ThreadMallocDxcCreateInstance(REFCLSID rclsid, REFIID riid, LPVOID *ppv) { HRESULT hr = S_OK; *ppv = nullptr; if (IsEqualCLSID(rclsid, CLSID_DxcDxrFallbackCompiler)) { hr = CreateDxcDxrFallbackCompiler(riid, ppv); } else { hr = REGDB_E_CLASSNOTREG; } return hr; } DXC_API_IMPORT HRESULT __stdcall DxcCreateDxrFallbackCompiler(REFCLSID rclsid, REFIID riid, LPVOID *ppv) { if (ppv == nullptr) { return E_POINTER; } HRESULT hr = S_OK; DxcEtw_DXCompilerCreateInstance_Start(); DxcThreadMalloc TM(nullptr); hr = ThreadMallocDxcCreateInstance(rclsid, riid, ppv); DxcEtw_DXCompilerCreateInstance_Stop(hr); return hr; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxcdxrfallbackcompiler.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxcdxrfallbackcompiler.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements the DirectX Raytracing Fallback Compiler object. // // // /////////////////////////////////////////////////////////////////////////////// // clang-format off // Includes on Windows are highly order dependent. #include "dxc/Support/WinIncludes.h" #include "dxc/Support/Global.h" #include "dxc/Support/Unicode.h" #include "dxc/Support/microcom.h" #include "dxc/dxcdxrfallbackcompiler.h" #include "dxc/DxrFallback/DxrFallbackCompiler.h" #include "dxc/DxilContainer/DxilContainer.h" #include "dxc/HLSL/DxilLinker.h" #include "dxc/DXIL/DxilModule.h" #include "dxc/DXIL/DxilUtil.h" #include "dxc/DxilValidation/DxilValidation.h" #include "dxc/Support/FileIOHelper.h" #include "dxc/Support/dxcapi.impl.h" #include "dxcutil.h" #include "clang/Basic/Diagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IRReader/IRReader.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MSFileSystem.h" #include "llvm/Support/SourceMgr.h" #include "llvm/IR/LegacyPassManager.h" #include "dxc/HLSL/DxilFallbackLayerPass.h" // clang-format on using namespace llvm; using namespace hlsl; static std::string ws2s(const std::wstring &wide) { return std::string(wide.begin(), wide.end()); } static HRESULT FindDxilProgram(IDxcBlob *pBlob, DxilFourCC FourCC, const DxilProgramHeader **ppProgram) { void *pContainerBytes = pBlob->GetBufferPointer(); SIZE_T ContainerSize = pBlob->GetBufferSize(); const DxilContainerHeader *pContainer = IsDxilContainerLike(pContainerBytes, ContainerSize); if (!pContainer) { IFR(DXC_E_CONTAINER_INVALID); } if (!IsValidDxilContainer(pContainer, ContainerSize)) { IFR(DXC_E_CONTAINER_INVALID); } DxilPartIterator it = std::find_if(begin(pContainer), end(pContainer), DxilPartIsType(FourCC)); if (it == end(pContainer)) { IFR(DXC_E_CONTAINER_MISSING_DXIL); } const DxilProgramHeader *pProgramHeader = reinterpret_cast<const DxilProgramHeader *>(GetDxilPartData(*it)); if (!IsValidDxilProgramHeader(pProgramHeader, (*it)->PartSize)) { IFR(DXC_E_CONTAINER_INVALID); } *ppProgram = pProgramHeader; return S_OK; } static DxilModule *ExtractDxil(LLVMContext &context, IDxcBlob *pContainer) { const DxilProgramHeader *pProgram = nullptr; IFT(FindDxilProgram(pContainer, DFCC_DXIL, &pProgram)); const char *pIL = nullptr; uint32_t ILLength = 0; GetDxilProgramBitcode(pProgram, &pIL, &ILLength); std::unique_ptr<Module> M; std::string diagStr; M = dxilutil::LoadModuleFromBitcode(llvm::StringRef(pIL, ILLength), context, diagStr); DxilModule *dxil = nullptr; if (M) dxil = &M->GetOrCreateDxilModule(); M.release(); return dxil; } static void saveModuleToAsmFile(const llvm::Module *mod, const std::string &filename) { std::error_code EC; raw_fd_ostream out(filename, EC, sys::fs::F_Text); if (!out.has_error()) { mod->print(out, nullptr); out.close(); } if (out.has_error()) { errs() << "Error saving to " << filename << ":" << filename << "\n"; exit(1); } } class DxcDxrFallbackCompiler : public IDxcDxrFallbackCompiler { private: DXC_MICROCOM_TM_REF_FIELDS() bool m_findCalledShaders = false; int m_debugOutput = 0; // Only used for test purposes when exports aren't explicitly listed std::unique_ptr<DxrFallbackCompiler::IntToFuncNameMap> m_pCachedMap; public: DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL() DXC_MICROCOM_TM_CTOR(DxcDxrFallbackCompiler) HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { return DoBasicQueryInterface<IDxcDxrFallbackCompiler>(this, iid, ppvObject); } HRESULT STDMETHODCALLTYPE SetFindCalledShaders(bool val) override { m_findCalledShaders = val; return S_OK; } HRESULT STDMETHODCALLTYPE SetDebugOutput(int val) override { m_debugOutput = val; return S_OK; } HRESULT STDMETHODCALLTYPE PatchShaderBindingTables( const LPCWSTR pEntryName, DxcShaderBytecode *pShaderBytecode, void *pShaderInfo, IDxcOperationResult **ppResult) override; HRESULT STDMETHODCALLTYPE RenameAndLink( DxcShaderBytecode *pLibs, UINT32 libCount, DxcExportDesc *pExports, UINT32 ExportCount, IDxcOperationResult **ppResult) override; HRESULT STDMETHODCALLTYPE Compile(DxcShaderBytecode *pLibs, UINT32 libCount, const LPCWSTR *pShaderNames, DxcShaderInfo *pShaderInfo, UINT32 shaderCount, UINT32 maxAttributeSize, IDxcOperationResult **ppResult) override; HRESULT STDMETHODCALLTYPE Link(const LPCWSTR pEntryName, IDxcBlob **pLibs, UINT32 libCount, const LPCWSTR *pShaderNames, DxcShaderInfo *pShaderInfo, UINT32 shaderCount, UINT32 maxAttributeSize, UINT32 stackSizeInBytes, IDxcOperationResult **ppResult) override; }; // TODO: Stolen from Brandon's code, merge // Remove ELF mangling static inline std::string GetUnmangledName(StringRef name) { if (!name.startswith("\x1?")) return name; size_t pos = name.find("@@"); if (pos == name.npos) return name; return name.substr(2, pos - 2); } static Function *getFunctionFromName(Module &M, const std::wstring &exportName) { for (auto F = M.begin(), E = M.end(); F != E; ++F) { std::wstring functionName = Unicode::UTF8ToWideStringOrThrow( GetUnmangledName(F->getName()).c_str()); if (exportName == functionName) { return F; } } return nullptr; } DXIL::ShaderKind getRayShaderKind(Function *F); Function *CloneFunction(Function *Orig, const llvm::Twine &Name, llvm::Module *llvmModule); HRESULT STDMETHODCALLTYPE DxcDxrFallbackCompiler::RenameAndLink( DxcShaderBytecode *pLibs, UINT32 libCount, DxcExportDesc *pExports, UINT32 ExportCount, IDxcOperationResult **ppResult) { if (pLibs == nullptr || pExports == nullptr) return E_POINTER; if (libCount == 0 || ExportCount == 0) return E_INVALIDARG; *ppResult = nullptr; HRESULT hr = S_OK; DxcThreadMalloc TM(m_pMalloc); LLVMContext context; try { // Init file system because we are currently loading the runtime from disk ::llvm::sys::fs::MSFileSystem *msfPtr; IFT(CreateMSFileSystemForDisk(&msfPtr)); std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr); ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get()); IFTLLVM(pts.error_code()); // Create a diagnostic printer CComPtr<AbstractMemoryStream> pDiagStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pDiagStream)); raw_stream_ostream DiagStream(pDiagStream); DiagnosticPrinterRawOStream DiagPrinter(DiagStream); PrintDiagnosticContext DiagContext(DiagPrinter); context.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler, &DiagContext, true); std::vector<CComPtr<IDxcBlobEncoding>> pShaderLibs(libCount); for (UINT i = 0; i < libCount; i++) { hlsl::DxcCreateBlobWithEncodingFromPinned(pLibs[i].pData, pLibs[i].Size, CP_ACP, &pShaderLibs[i]); } // Link all the modules together into a single into library unsigned int valMajor = 0, valMinor = 0; dxcutil::GetValidatorVersion(&valMajor, &valMinor); std::unique_ptr<Module> M; { DxilLinker *pLinker = DxilLinker::CreateLinker(context, valMajor, valMinor); for (UINT32 i = 0; i < libCount; ++i) { DxilModule *dxil = ExtractDxil(context, pShaderLibs[i]); if (dxil == nullptr) { return DXC_E_CONTAINER_MISSING_DXIL; } pLinker->RegisterLib(std::to_string(i), std::unique_ptr<Module>(dxil->GetModule()), nullptr); pLinker->AttachLib(std::to_string(i)); } dxilutil::ExportMap exportMap; M = pLinker->Link("", "lib_6_3", exportMap); if (m_debugOutput) { saveModuleToAsmFile(M.get(), "combined.ll"); } } dxilutil::ExportMap exportMap; for (UINT i = 0; i < ExportCount; i++) { auto &exportDesc = pExports[i]; auto exportName = ws2s(exportDesc.ExportName); if (exportDesc.ExportToRename) { auto exportToRename = ws2s(exportDesc.ExportToRename); CloneFunction(M->getFunction(exportToRename), exportName, M.get()); } exportMap.Add(GetUnmangledName(exportName)); } // Create the compute shader DxilLinker *pLinker = DxilLinker::CreateLinker(context, valMajor, valMinor); pLinker->RegisterLib("M", std::move(M), nullptr); pLinker->AttachLib("M"); auto profile = "lib_6_3"; M = pLinker->Link(StringRef(), profile, exportMap); bool hasErrors = DiagContext.HasErrors(); CComPtr<IDxcBlob> pResultBlob; if (M) { CComPtr<AbstractMemoryStream> pOutputStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pOutputStream)); raw_stream_ostream outStream(pOutputStream.p); WriteBitcodeToFile(M.get(), outStream); outStream.flush(); // Validation. dxcutil::AssembleInputs inputs(std::move(M), pResultBlob, TM.GetInstalledAllocator(), SerializeDxilFlags::None, pOutputStream); dxcutil::AssembleToContainer(inputs); } DiagStream.flush(); CComPtr<IStream> pStream = static_cast<CComPtr<IStream>>(pDiagStream); std::string warnings; dxcutil::CreateOperationResultFromOutputs(pResultBlob, pStream, warnings, hasErrors, ppResult); } CATCH_CPP_ASSIGN_HRESULT(); return hr; } HRESULT STDMETHODCALLTYPE DxcDxrFallbackCompiler::PatchShaderBindingTables( const LPCWSTR pEntryName, DxcShaderBytecode *pShaderBytecode, void *pShaderInfo, IDxcOperationResult **ppResult) { if (pShaderBytecode == nullptr || pShaderInfo == nullptr) return E_POINTER; *ppResult = nullptr; HRESULT hr = S_OK; DxcThreadMalloc TM(m_pMalloc); LLVMContext context; try { CComPtr<IDxcBlobEncoding> pShaderBlob; hlsl::DxcCreateBlobWithEncodingFromPinned( pShaderBytecode->pData, pShaderBytecode->Size, CP_ACP, &pShaderBlob); // Init file system because we are currently loading the runtime from disk ::llvm::sys::fs::MSFileSystem *msfPtr; IFT(CreateMSFileSystemForDisk(&msfPtr)); std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr); ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get()); IFTLLVM(pts.error_code()); // Create a diagnostic printer CComPtr<AbstractMemoryStream> pDiagStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pDiagStream)); raw_stream_ostream DiagStream(pDiagStream); DiagnosticPrinterRawOStream DiagPrinter(DiagStream); PrintDiagnosticContext DiagContext(DiagPrinter); context.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler, &DiagContext, true); DxilModule *dxil = ExtractDxil(context, pShaderBlob); // TODO: Lifetime managment? std::unique_ptr<Module> M(dxil->GetModule()); if (dxil == nullptr) { return DXC_E_CONTAINER_MISSING_DXIL; } ModulePass *patchShaderRecordBindingsPass = createDxilPatchShaderRecordBindingsPass(); char dxilPatchShaderRecordString[32]; StringCchPrintf(dxilPatchShaderRecordString, _countof(dxilPatchShaderRecordString), "%p", pShaderInfo); auto passOption = PassOption("root-signature", dxilPatchShaderRecordString); PassOptions options(passOption); patchShaderRecordBindingsPass->applyOptions(options); legacy::PassManager FPM; FPM.add(patchShaderRecordBindingsPass); FPM.run(*M); CComPtr<IDxcBlob> pResultBlob; if (M) { CComPtr<AbstractMemoryStream> pOutputStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pOutputStream)); raw_stream_ostream outStream(pOutputStream.p); WriteBitcodeToFile(M.get(), outStream); outStream.flush(); dxcutil::AssembleInputs inputs(std::move(M), pResultBlob, TM.GetInstalledAllocator(), SerializeDxilFlags::None, pOutputStream); dxcutil::AssembleToContainer(inputs); } DiagStream.flush(); CComPtr<IStream> pStream = static_cast<CComPtr<IStream>>(pDiagStream); std::string warnings; dxcutil::CreateOperationResultFromOutputs(pResultBlob, pStream, warnings, false, ppResult); } CATCH_CPP_ASSIGN_HRESULT(); return hr; } HRESULT STDMETHODCALLTYPE DxcDxrFallbackCompiler::Link( const LPCWSTR pEntryName, IDxcBlob **pLibs, UINT32 libCount, const LPCWSTR *pShaderNames, DxcShaderInfo *pShaderInfo, UINT32 shaderCount, UINT32 maxAttributeSize, UINT32 stackSizeInBytes, IDxcOperationResult **ppResult) { if (pLibs == nullptr || pShaderNames == nullptr || ppResult == nullptr) return E_POINTER; if (libCount == 0 || shaderCount == 0) return E_INVALIDARG; *ppResult = nullptr; HRESULT hr = S_OK; DxcThreadMalloc TM(m_pMalloc); LLVMContext context; try { // Init file system because we are currently loading the runtime from disk ::llvm::sys::fs::MSFileSystem *msfPtr; IFT(CreateMSFileSystemForDisk(&msfPtr)); std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr); ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get()); IFTLLVM(pts.error_code()); // Create a diagnostic printer CComPtr<AbstractMemoryStream> pDiagStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pDiagStream)); raw_stream_ostream DiagStream(pDiagStream); DiagnosticPrinterRawOStream DiagPrinter(DiagStream); PrintDiagnosticContext DiagContext(DiagPrinter); context.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler, &DiagContext, true); std::vector<std::string> shaderNames(shaderCount); for (UINT32 i = 0; i < shaderCount; ++i) shaderNames[i] = ws2s(pShaderNames[i]); // Link all the modules together into a single into library unsigned int valMajor = 0, valMinor = 0; dxcutil::GetValidatorVersion(&valMajor, &valMinor); std::unique_ptr<Module> M; { DxilLinker *pLinker = DxilLinker::CreateLinker(context, valMajor, valMinor); for (UINT32 i = 0; i < libCount; ++i) { DxilModule *dxil = ExtractDxil(context, pLibs[i]); if (dxil == nullptr) { return DXC_E_CONTAINER_MISSING_DXIL; } pLinker->RegisterLib(std::to_string(i), std::unique_ptr<Module>(dxil->GetModule()), nullptr); pLinker->AttachLib(std::to_string(i)); } dxilutil::ExportMap exportMap; M = pLinker->Link("", "lib_6_3", exportMap); if (m_debugOutput) { saveModuleToAsmFile(M.get(), "combined.ll"); } } std::vector<int> shaderEntryStateIds; std::vector<unsigned int> shaderStackSizes; DxrFallbackCompiler compiler(M.get(), shaderNames, maxAttributeSize, stackSizeInBytes, m_findCalledShaders); compiler.setDebugOutputLevel(m_debugOutput); shaderEntryStateIds.resize(shaderCount); shaderStackSizes.resize(shaderCount); for (UINT i = 0; i < shaderCount; i++) { shaderEntryStateIds[i] = pShaderInfo[i].Identifier; shaderStackSizes[i] = pShaderInfo[i].StackSize; } compiler.link(shaderEntryStateIds, shaderStackSizes, m_pCachedMap.get()); if (m_debugOutput) { saveModuleToAsmFile(M.get(), "compiled.ll"); } // Create the compute shader dxilutil::ExportMap exportMap; DxilLinker *pLinker = DxilLinker::CreateLinker(context, valMajor, valMinor); pLinker->RegisterLib("M", std::move(M), nullptr); pLinker->AttachLib("M"); auto profile = "cs_6_0"; M = pLinker->Link(pEntryName ? ws2s(pEntryName).c_str() : StringRef(), profile, exportMap); bool hasErrors = DiagContext.HasErrors(); CComPtr<IDxcBlob> pResultBlob; if (M) { if (!hasErrors && stackSizeInBytes) DxrFallbackCompiler::resizeStack( M->getFunction(ws2s(pEntryName).c_str()), stackSizeInBytes); llvm::NamedMDNode *IdentMetadata = M->getOrInsertNamedMetadata("llvm.ident"); llvm::LLVMContext &Ctx = M->getContext(); llvm::Metadata *IdentNode[] = {llvm::MDString::get(Ctx, "FallbackLayer")}; IdentMetadata->addOperand(llvm::MDNode::get(Ctx, IdentNode)); DxilModule &DM = M->GetDxilModule(); DM.SetValidatorVersion(valMajor, valMinor); DxilModule::ClearDxilMetadata(*M); DM.EmitDxilMetadata(); if (m_debugOutput) saveModuleToAsmFile(M.get(), "linked.ll"); #if !DISABLE_GET_CUSTOM_DIAG_ID const IntrusiveRefCntPtr<clang::DiagnosticIDs> Diags( new clang::DiagnosticIDs); IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts = new clang::DiagnosticOptions(); // Construct our diagnostic client. clang::TextDiagnosticPrinter *DiagClient = new clang::TextDiagnosticPrinter(DiagStream, &*DiagOpts); clang::DiagnosticsEngine Diag(Diags, &*DiagOpts, DiagClient); #endif } if (M) { CComPtr<AbstractMemoryStream> pOutputStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pOutputStream)); raw_stream_ostream outStream(pOutputStream.p); WriteBitcodeToFile(M.get(), outStream); outStream.flush(); // Validation. dxcutil::AssembleInputs inputs(std::move(M), pResultBlob, TM.GetInstalledAllocator(), SerializeDxilFlags::None, pOutputStream, /*bDebugInfo*/ false); HRESULT valHR = dxcutil::ValidateAndAssembleToContainer(inputs); if (FAILED(valHR)) hasErrors = true; } DiagStream.flush(); CComPtr<IStream> pStream = static_cast<CComPtr<IStream>>(pDiagStream); std::string warnings; dxcutil::CreateOperationResultFromOutputs(pResultBlob, pStream, warnings, hasErrors, ppResult); } CATCH_CPP_ASSIGN_HRESULT(); return hr; } HRESULT STDMETHODCALLTYPE DxcDxrFallbackCompiler::Compile( DxcShaderBytecode *pShaderLibs, UINT32 libCount, const LPCWSTR *pShaderNames, DxcShaderInfo *pShaderInfo, UINT32 shaderCount, UINT32 maxAttributeSize, IDxcOperationResult **ppResult) { if (pShaderLibs == nullptr || pShaderNames == nullptr || ppResult == nullptr) return E_POINTER; if (libCount == 0 || shaderCount == 0) return E_INVALIDARG; *ppResult = nullptr; HRESULT hr = S_OK; DxcThreadMalloc TM(m_pMalloc); LLVMContext context; try { std::vector<CComPtr<IDxcBlobEncoding>> pLibs(libCount); for (UINT i = 0; i < libCount; i++) { auto &shaderBytecode = pShaderLibs[i]; hlsl::DxcCreateBlobWithEncodingFromPinned( shaderBytecode.pData, shaderBytecode.Size, CP_ACP, &pLibs[i]); } // Init file system because we are currently loading the runtime from disk ::llvm::sys::fs::MSFileSystem *msfPtr; IFT(CreateMSFileSystemForDisk(&msfPtr)); std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr); ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get()); IFTLLVM(pts.error_code()); // Create a diagnostic printer CComPtr<AbstractMemoryStream> pDiagStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pDiagStream)); raw_stream_ostream DiagStream(pDiagStream); DiagnosticPrinterRawOStream DiagPrinter(DiagStream); PrintDiagnosticContext DiagContext(DiagPrinter); context.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler, &DiagContext, true); std::vector<std::string> shaderNames(shaderCount); for (UINT32 i = 0; i < shaderCount; ++i) shaderNames[i] = ws2s(pShaderNames[i]); // Link all the modules together into a single into library unsigned int valMajor = 0, valMinor = 0; dxcutil::GetValidatorVersion(&valMajor, &valMinor); std::unique_ptr<Module> M; { DxilLinker *pLinker = DxilLinker::CreateLinker(context, valMajor, valMinor); for (UINT32 i = 0; i < libCount; ++i) { DxilModule *dxil = ExtractDxil(context, pLibs[i]); if (dxil == nullptr) { return DXC_E_CONTAINER_MISSING_DXIL; } pLinker->RegisterLib(std::to_string(i), std::unique_ptr<Module>(dxil->GetModule()), nullptr); pLinker->AttachLib(std::to_string(i)); } dxilutil::ExportMap exportMap; M = pLinker->Link("", "lib_6_3", exportMap); if (m_debugOutput) { saveModuleToAsmFile(M.get(), "combined.ll"); } } std::vector<ShaderType> shaderTypes; for (UINT32 i = 0; i < shaderCount; ++i) { switch (getRayShaderKind(getFunctionFromName(*M, pShaderNames[i]))) { case DXIL::ShaderKind::RayGeneration: shaderTypes.push_back(ShaderType::Raygen); break; case DXIL::ShaderKind::AnyHit: shaderTypes.push_back(ShaderType::AnyHit); break; case DXIL::ShaderKind::ClosestHit: shaderTypes.push_back(ShaderType::ClosestHit); break; case DXIL::ShaderKind::Intersection: shaderTypes.push_back(ShaderType::Intersection); break; case DXIL::ShaderKind::Miss: shaderTypes.push_back(ShaderType::Miss); break; case DXIL::ShaderKind::Callable: shaderTypes.push_back(ShaderType::Callable); break; default: shaderTypes.push_back(ShaderType::Lib); break; } } if (m_findCalledShaders) { m_pCachedMap.reset(new DxrFallbackCompiler::IntToFuncNameMap); } std::vector<int> shaderEntryStateIds; std::vector<unsigned int> shaderStackSizes; DxrFallbackCompiler compiler(M.get(), shaderNames, maxAttributeSize, 0, m_findCalledShaders); compiler.setDebugOutputLevel(m_debugOutput); compiler.compile(shaderEntryStateIds, shaderStackSizes, m_pCachedMap.get()); if (m_debugOutput) { saveModuleToAsmFile(M.get(), "compiled.ll"); } // Create the compute shader dxilutil::ExportMap exportMap; DxilLinker *pLinker = DxilLinker::CreateLinker(context, valMajor, valMinor); pLinker->RegisterLib("M", std::move(M), nullptr); pLinker->AttachLib("M"); auto profile = "lib_6_3"; M = pLinker->Link(StringRef(), profile, exportMap); bool hasErrors = DiagContext.HasErrors(); CComPtr<IDxcBlob> pResultBlob; if (M) { CComPtr<AbstractMemoryStream> pOutputStream; IFT(CreateMemoryStream(TM.GetInstalledAllocator(), &pOutputStream)); raw_stream_ostream outStream(pOutputStream.p); WriteBitcodeToFile(M.get(), outStream); outStream.flush(); dxcutil::AssembleInputs inputs(std::move(M), pResultBlob, TM.GetInstalledAllocator(), SerializeDxilFlags::None, pOutputStream); dxcutil::AssembleToContainer(inputs); } DiagStream.flush(); CComPtr<IStream> pStream = static_cast<CComPtr<IStream>>(pDiagStream); std::string warnings; dxcutil::CreateOperationResultFromOutputs(pResultBlob, pStream, warnings, hasErrors, ppResult); // Write out shader identifiers size_t copyCount = (m_findCalledShaders) ? 1 : shaderCount; for (unsigned int i = 0; i < copyCount; i++) { pShaderInfo[i].Identifier = shaderEntryStateIds[i]; pShaderInfo[i].StackSize = shaderStackSizes[i]; pShaderInfo[i].Type = shaderTypes[i]; } } CATCH_CPP_ASSIGN_HRESULT(); return hr; } HRESULT CreateDxcDxrFallbackCompiler(REFIID riid, LPVOID *ppv) { CComPtr<DxcDxrFallbackCompiler> result = DxcDxrFallbackCompiler::Alloc(DxcGetThreadMallocNoRef()); if (result == nullptr) { *ppv = nullptr; return E_OUTOFMEMORY; } return result.p->QueryInterface(riid, ppv); }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp
/////////////////////////////////////////////////////////////////////////////// // // // DXCompiler.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements the entry point for the dxcompiler DLL. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxc/Support/WinIncludes.h" #include "dxc/Support/Global.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/config.h" #include "dxcetw.h" #include "dxillib.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" namespace hlsl { HRESULT SetupRegistryPassForHLSL(); } // C++ exception specification ignored except to indicate a function is not // __declspec(nothrow) #pragma warning(disable : 4290) #if !defined(DXC_DISABLE_ALLOCATOR_OVERRIDES) // operator new and friends. void *__CRTDECL operator new(std::size_t size) noexcept(false) { void *ptr = DxcNew(size); if (ptr == nullptr) throw std::bad_alloc(); return ptr; } void *__CRTDECL operator new(std::size_t size, const std::nothrow_t &nothrow_value) throw() { return DxcNew(size); } void __CRTDECL operator delete(void *ptr) throw() { DxcDelete(ptr); } void __CRTDECL operator delete(void *ptr, const std::nothrow_t &nothrow_constant) throw() { DxcDelete(ptr); } #endif static HRESULT InitMaybeFail() throw() { HRESULT hr; bool fsSetup = false, memSetup = false; IFC(DxcInitThreadMalloc()); DxcSetThreadMallocToDefault(); memSetup = true; if (::llvm::sys::fs::SetupPerThreadFileSystem()) { hr = E_FAIL; goto Cleanup; } fsSetup = true; IFC(hlsl::SetupRegistryPassForHLSL()); IFC(DxilLibInitialize()); if (hlsl::options::initHlslOptTable()) { hr = E_FAIL; goto Cleanup; } Cleanup: if (FAILED(hr)) { if (fsSetup) { ::llvm::sys::fs::CleanupPerThreadFileSystem(); } if (memSetup) { DxcClearThreadMalloc(); DxcCleanupThreadMalloc(); } } else { DxcClearThreadMalloc(); } return hr; } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID reserved) { BOOL result = TRUE; if (Reason == DLL_PROCESS_ATTACH) { EventRegisterMicrosoft_Windows_DXCompiler_API(); DxcEtw_DXCompilerInitialization_Start(); HRESULT hr = InitMaybeFail(); DxcEtw_DXCompilerInitialization_Stop(hr); result = SUCCEEDED(hr) ? TRUE : FALSE; } else if (Reason == DLL_PROCESS_DETACH) { DxcEtw_DXCompilerShutdown_Start(); DxcSetThreadMallocToDefault(); ::hlsl::options::cleanupHlslOptTable(); ::llvm::sys::fs::CleanupPerThreadFileSystem(); ::llvm::llvm_shutdown(); if (reserved == NULL) { // FreeLibrary has been called or the DLL load failed DxilLibCleanup(DxilLibCleanUpType::UnloadLibrary); } else { // Process termination. We should not call FreeLibrary() DxilLibCleanup(DxilLibCleanUpType::ProcessTermination); } DxcClearThreadMalloc(); DxcCleanupThreadMalloc(); DxcEtw_DXCompilerShutdown_Stop(S_OK); EventUnregisterMicrosoft_Windows_DXCompiler_API(); } return result; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxcutil.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxcutil.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides helper code for dxcompiler. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxcutil.h" #include "dxc/DXIL/DxilModule.h" #include "dxc/DxilContainer/DxilContainerAssembler.h" #include "dxc/Support/FileIOHelper.h" #include "dxc/Support/Global.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/WinIncludes.h" #include "dxc/Support/dxcapi.impl.h" #include "dxc/dxcapi.h" #include "dxillib.h" #include "clang/Basic/Diagnostic.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Support/Path.h" using namespace llvm; using namespace hlsl; // This declaration is used for the locally-linked validator. HRESULT CreateDxcValidator(REFIID riid, LPVOID *ppv); // This internal call allows the validator to avoid having to re-deserialize // the module. It trusts that the caller didn't make any changes and is // kept internal because the layout of the module class may change based // on changes across modules, or picking a different compiler version or CRT. HRESULT RunInternalValidator(IDxcValidator *pValidator, llvm::Module *pDebugModule, IDxcBlob *pShader, UINT32 Flags, IDxcOperationResult **ppResult); namespace { // AssembleToContainer helper functions. bool CreateValidator(CComPtr<IDxcValidator> &pValidator) { if (DxilLibIsEnabled()) { DxilLibCreateInstance(CLSID_DxcValidator, &pValidator); } bool bInternalValidator = false; if (pValidator == nullptr) { IFT(CreateDxcValidator(IID_PPV_ARGS(&pValidator))); bInternalValidator = true; } return bInternalValidator; } } // namespace namespace dxcutil { AssembleInputs::AssembleInputs( std::unique_ptr<llvm::Module> &&pM, CComPtr<IDxcBlob> &pOutputContainerBlob, IMalloc *pMalloc, hlsl::SerializeDxilFlags SerializeFlags, CComPtr<hlsl::AbstractMemoryStream> &pModuleBitcode, bool bDebugInfo, llvm::StringRef DebugName, clang::DiagnosticsEngine *pDiag, hlsl::DxilShaderHash *pShaderHashOut, AbstractMemoryStream *pReflectionOut, AbstractMemoryStream *pRootSigOut) : pM(std::move(pM)), pOutputContainerBlob(pOutputContainerBlob), pMalloc(pMalloc), SerializeFlags(SerializeFlags), pModuleBitcode(pModuleBitcode), bDebugInfo(bDebugInfo), DebugName(DebugName), pDiag(pDiag), pShaderHashOut(pShaderHashOut), pReflectionOut(pReflectionOut), pRootSigOut(pRootSigOut) {} void GetValidatorVersion(unsigned *pMajor, unsigned *pMinor) { if (pMajor == nullptr || pMinor == nullptr) return; CComPtr<IDxcValidator> pValidator; CreateValidator(pValidator); CComPtr<IDxcVersionInfo> pVersionInfo; if (SUCCEEDED(pValidator.QueryInterface(&pVersionInfo))) { IFT(pVersionInfo->GetVersion(pMajor, pMinor)); } else { // Default to 1.0 *pMajor = 1; *pMinor = 0; } } void AssembleToContainer(AssembleInputs &inputs) { CComPtr<AbstractMemoryStream> pContainerStream; IFT(CreateMemoryStream(inputs.pMalloc, &pContainerStream)); SerializeDxilContainerForModule( &inputs.pM->GetOrCreateDxilModule(), inputs.pModuleBitcode, nullptr, pContainerStream, inputs.DebugName, inputs.SerializeFlags, inputs.pShaderHashOut, inputs.pReflectionOut, inputs.pRootSigOut); inputs.pOutputContainerBlob.Release(); IFT(pContainerStream.QueryInterface(&inputs.pOutputContainerBlob)); } void ReadOptsAndValidate(hlsl::options::MainArgs &mainArgs, hlsl::options::DxcOpts &opts, AbstractMemoryStream *pOutputStream, IDxcOperationResult **ppResult, bool &finished) { const llvm::opt::OptTable *table = ::options::getHlslOptTable(); raw_stream_ostream outStream(pOutputStream); if (0 != hlsl::options::ReadDxcOpts(table, hlsl::options::CompilerFlags, mainArgs, opts, outStream)) { CComPtr<IDxcBlob> pErrorBlob; IFT(pOutputStream->QueryInterface(&pErrorBlob)); outStream.flush(); IFT(DxcResult::Create( E_INVALIDARG, DXC_OUT_NONE, {DxcOutputObject::ErrorOutput(opts.DefaultTextCodePage, (LPCSTR)pErrorBlob->GetBufferPointer(), pErrorBlob->GetBufferSize())}, ppResult)); finished = true; return; } DXASSERT(opts.HLSLVersion > hlsl::LangStd::v2015, "else ReadDxcOpts didn't fail for non-isense"); finished = false; } HRESULT ValidateAndAssembleToContainer(AssembleInputs &inputs) { HRESULT valHR = S_OK; // If we have debug info, this will be a clone of the module before debug info // is stripped. This is used with internal validator to provide more useful // error messages. std::unique_ptr<llvm::Module> llvmModuleWithDebugInfo; CComPtr<IDxcValidator> pValidator; bool bInternalValidator = CreateValidator(pValidator); // Warning on internal Validator if (bInternalValidator) { // If using the internal validator, we'll use the modules directly. // In this case, we'll want to make a clone to avoid // SerializeDxilContainerForModule stripping all the debug info. The debug // info will be stripped from the orginal module, but preserved in the // cloned module. if (inputs.bDebugInfo) { llvmModuleWithDebugInfo.reset(llvm::CloneModule(inputs.pM.get())); } } // Verify validator version can validate this module CComPtr<IDxcVersionInfo> pValidatorVersion; IFT(pValidator->QueryInterface(&pValidatorVersion)); UINT32 ValMajor, ValMinor; IFT(pValidatorVersion->GetVersion(&ValMajor, &ValMinor)); DxilModule &DM = inputs.pM.get()->GetOrCreateDxilModule(); unsigned ReqValMajor, ReqValMinor; DM.GetValidatorVersion(ReqValMajor, ReqValMinor); if (DXIL::CompareVersions(ValMajor, ValMinor, ReqValMajor, ReqValMinor) < 0) { // Module is expecting to be validated by a newer validator. #if !DISABLE_GET_CUSTOM_DIAG_ID if (inputs.pDiag) { unsigned diagID = inputs.pDiag->getCustomDiagID( clang::DiagnosticsEngine::Level::Error, "The module cannot be validated by the version of the validator " "currently attached."); inputs.pDiag->Report(diagID); } #endif return E_FAIL; } AssembleToContainer(inputs); CComPtr<IDxcOperationResult> pValResult; // Important: in-place edit is required so the blob is reused and thus // dxil.dll can be released. if (bInternalValidator) { IFT(RunInternalValidator(pValidator, llvmModuleWithDebugInfo.get(), inputs.pOutputContainerBlob, DxcValidatorFlags_InPlaceEdit, &pValResult)); } else { IFT(pValidator->Validate(inputs.pOutputContainerBlob, DxcValidatorFlags_InPlaceEdit, &pValResult)); } IFT(pValResult->GetStatus(&valHR)); #if !DISABLE_GET_CUSTOM_DIAG_ID if (inputs.pDiag) { if (FAILED(valHR)) { CComPtr<IDxcBlobEncoding> pErrors; CComPtr<IDxcBlobUtf8> pErrorsUtf8; IFT(pValResult->GetErrorBuffer(&pErrors)); IFT(hlsl::DxcGetBlobAsUtf8(pErrors, inputs.pMalloc, &pErrorsUtf8)); StringRef errRef(pErrorsUtf8->GetStringPointer(), pErrorsUtf8->GetStringLength()); unsigned DiagID = inputs.pDiag->getCustomDiagID( clang::DiagnosticsEngine::Error, "validation errors\r\n%0"); inputs.pDiag->Report(DiagID) << errRef; } } #endif CComPtr<IDxcBlob> pValidatedBlob; IFT(pValResult->GetResult(&pValidatedBlob)); if (pValidatedBlob != nullptr) { std::swap(inputs.pOutputContainerBlob, pValidatedBlob); } pValidator.Release(); return valHR; } HRESULT ValidateRootSignatureInContainer(IDxcBlob *pRootSigContainer, clang::DiagnosticsEngine *pDiag) { HRESULT valHR = S_OK; CComPtr<IDxcValidator> pValidator; CComPtr<IDxcOperationResult> pValResult; CreateValidator(pValidator); IFT(pValidator->Validate(pRootSigContainer, DxcValidatorFlags_RootSignatureOnly | DxcValidatorFlags_InPlaceEdit, &pValResult)); IFT(pValResult->GetStatus(&valHR)); #if !DISABLE_GET_CUSTOM_DIAG_ID if (pDiag) { if (FAILED(valHR)) { CComPtr<IDxcBlobEncoding> pErrors; CComPtr<IDxcBlobUtf8> pErrorsUtf8; IFT(pValResult->GetErrorBuffer(&pErrors)); IFT(hlsl::DxcGetBlobAsUtf8(pErrors, nullptr, &pErrorsUtf8)); StringRef errRef(pErrorsUtf8->GetStringPointer(), pErrorsUtf8->GetStringLength()); unsigned DiagID = pDiag->getCustomDiagID(clang::DiagnosticsEngine::Error, "root signature validation errors\r\n%0"); pDiag->Report(DiagID) << errRef; } } #endif return valHR; } void CreateOperationResultFromOutputs( DXC_OUT_KIND resultKind, UINT32 textEncoding, IDxcBlob *pResultBlob, CComPtr<IStream> &pErrorStream, const std::string &warnings, bool hasErrorOccurred, IDxcOperationResult **ppResult) { CComPtr<DxcResult> pResult = DxcResult::Alloc(DxcGetThreadMallocNoRef()); IFT(pResult->SetEncoding(textEncoding)); IFT(pResult->SetStatusAndPrimaryResult(hasErrorOccurred ? E_FAIL : S_OK, resultKind)); IFT(pResult->SetOutputObject(resultKind, pResultBlob)); CComPtr<IDxcBlob> pErrorBlob; IFT(pErrorStream.QueryInterface(&pErrorBlob)); if (IsBlobNullOrEmpty(pErrorBlob)) { IFT(pResult->SetOutputString(DXC_OUT_ERRORS, warnings.c_str(), warnings.size())); } else { IFT(pResult->SetOutputObject(DXC_OUT_ERRORS, pErrorBlob)); } IFT(pResult.QueryInterface(ppResult)); } void CreateOperationResultFromOutputs(IDxcBlob *pResultBlob, CComPtr<IStream> &pErrorStream, const std::string &warnings, bool hasErrorOccurred, IDxcOperationResult **ppResult) { CreateOperationResultFromOutputs(DXC_OUT_OBJECT, DXC_CP_UTF8, pResultBlob, pErrorStream, warnings, hasErrorOccurred, ppResult); } bool IsAbsoluteOrCurDirRelative(const llvm::Twine &T) { if (llvm::sys::path::is_absolute(T)) { return true; } if (T.isSingleStringRef()) { StringRef r = T.getSingleStringRef(); if (r.size() < 2) return false; const char *pData = r.data(); return pData[0] == '.' && (pData[1] == '\\' || pData[1] == '/'); } DXASSERT(false, "twine kind not supported"); return false; } } // namespace dxcutil
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxcutil.h
/////////////////////////////////////////////////////////////////////////////// // // // dxcutil.h // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides helper code for dxcompiler. // // // /////////////////////////////////////////////////////////////////////////////// #pragma once #include "dxc/Support/microcom.h" #include "dxc/dxcapi.h" #include "llvm/ADT/StringRef.h" #include <memory> #define DISABLE_GET_CUSTOM_DIAG_ID 1 namespace clang { class DiagnosticsEngine; } namespace llvm { class LLVMContext; class MemoryBuffer; class Module; class raw_string_ostream; class Twine; } // namespace llvm namespace hlsl { enum class SerializeDxilFlags : uint32_t; struct DxilShaderHash; class AbstractMemoryStream; namespace options { class MainArgs; class DxcOpts; } // namespace options } // namespace hlsl namespace dxcutil { struct AssembleInputs { AssembleInputs(std::unique_ptr<llvm::Module> &&pM, CComPtr<IDxcBlob> &pOutputContainerBlob, IMalloc *pMalloc, hlsl::SerializeDxilFlags SerializeFlags, CComPtr<hlsl::AbstractMemoryStream> &pModuleBitcode, bool bDebugInfo = false, llvm::StringRef DebugName = llvm::StringRef(), clang::DiagnosticsEngine *pDiag = nullptr, hlsl::DxilShaderHash *pShaderHashOut = nullptr, hlsl::AbstractMemoryStream *pReflectionOut = nullptr, hlsl::AbstractMemoryStream *pRootSigOut = nullptr); std::unique_ptr<llvm::Module> pM; CComPtr<IDxcBlob> &pOutputContainerBlob; IMalloc *pMalloc; hlsl::SerializeDxilFlags SerializeFlags; CComPtr<hlsl::AbstractMemoryStream> &pModuleBitcode; bool bDebugInfo; llvm::StringRef DebugName = llvm::StringRef(); clang::DiagnosticsEngine *pDiag; hlsl::DxilShaderHash *pShaderHashOut = nullptr; hlsl::AbstractMemoryStream *pReflectionOut = nullptr; hlsl::AbstractMemoryStream *pRootSigOut = nullptr; }; HRESULT ValidateAndAssembleToContainer(AssembleInputs &inputs); HRESULT ValidateRootSignatureInContainer(IDxcBlob *pRootSigContainer, clang::DiagnosticsEngine *pDiag = nullptr); void GetValidatorVersion(unsigned *pMajor, unsigned *pMinor); void AssembleToContainer(AssembleInputs &inputs); HRESULT Disassemble(IDxcBlob *pProgram, llvm::raw_string_ostream &Stream); void ReadOptsAndValidate(hlsl::options::MainArgs &mainArgs, hlsl::options::DxcOpts &opts, hlsl::AbstractMemoryStream *pOutputStream, IDxcOperationResult **ppResult, bool &finished); void CreateOperationResultFromOutputs( DXC_OUT_KIND resultKind, UINT32 textEncoding, IDxcBlob *pResultBlob, CComPtr<IStream> &pErrorStream, const std::string &warnings, bool hasErrorOccurred, IDxcOperationResult **ppResult); void CreateOperationResultFromOutputs(IDxcBlob *pResultBlob, CComPtr<IStream> &pErrorStream, const std::string &warnings, bool hasErrorOccurred, IDxcOperationResult **ppResult); bool IsAbsoluteOrCurDirRelative(const llvm::Twine &T); } // namespace dxcutil
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/CMakeLists.txt
# Copyright (C) Microsoft Corporation. All rights reserved. # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. find_package(DiaSDK REQUIRED) # Used for constants and declarations. set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} analysis asmparser # asmprinter # no support for LLVM codegen bitreader bitwriter # codegen # no support for LLVM codegen core # debuginfodwarf # no support for DWARF files (IR debug info is OK) # debuginfopdb # no support for PDB files dxcsupport dxcbindingtable dxrfallback dxil dxilcontainer dxilrootsignature hlsl instcombine ipa ipo irreader # libdriver # lineeditor linker # lto # mirparser # no support for LLVM codegen mssupport # object # no support for object files (coff, elf) option # passes profiledata scalaropts # selectiondag # no support for LLVM codegen support target transformutils vectorize ) set(SOURCES dxcapi.cpp DXCompiler.cpp DXCompiler.rc DXCompiler.def dxillib.cpp dxcutil.cpp dxcdxrfallbackcompiler.cpp dxcvalidator.cpp ) add_clang_library(dxrfallbackcompiler SHARED ${SOURCES}) target_link_libraries(dxrfallbackcompiler PRIVATE ${LIBRARIES} ${DIASDK_LIBRARIES} dxcvalidator) # SPIRV change starts if (ENABLE_SPIRV_CODEGEN) target_link_libraries(dxrfallbackcompiler PRIVATE clangSPIRV) endif (ENABLE_SPIRV_CODEGEN) # SPIRV change ends add_dependencies(dxrfallbackcompiler DxcEtw) include_directories(AFTER ${LLVM_INCLUDE_DIR}/dxc/Tracing ${DIASDK_INCLUDE_DIRS}) include_directories(${LLVM_SOURCE_DIR}/tools/clang/tools/dxcvalidator) set_target_properties(dxrfallbackcompiler PROPERTIES OUTPUT_NAME "dxrfallbackcompiler" VERSION ${LIBCLANG_LIBRARY_VERSION} DEFINE_SYMBOL _CINDEX_LIB_)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxcvalidator.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxcvalidator.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Implements the DirectX Validator object. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxcvalidator.h" #include "dxc/Support/WinIncludes.h" #include "dxc/Support/Global.h" #include "dxc/Support/microcom.h" #include "dxc/dxcapi.h" using namespace llvm; using namespace hlsl; class DxcValidator : public IDxcValidator, public IDxcVersionInfo { private: DXC_MICROCOM_TM_REF_FIELDS() public: DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL() DXC_MICROCOM_TM_CTOR(DxcValidator) HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { return DoBasicQueryInterface<IDxcValidator, IDxcVersionInfo>(this, iid, ppvObject); } // For internal use only. HRESULT ValidateWithOptDebugModule( IDxcBlob *pShader, // Shader to validate. UINT32 Flags, // Validation flags. llvm::Module *pDebugModule, // Debug module to validate, if available IDxcOperationResult * *ppResult // Validation output status, buffer, and errors ); // IDxcValidator HRESULT STDMETHODCALLTYPE Validate( IDxcBlob *pShader, // Shader to validate. UINT32 Flags, // Validation flags. IDxcOperationResult * *ppResult // Validation output status, buffer, and errors ) override; // IDxcVersionInfo HRESULT STDMETHODCALLTYPE GetVersion(UINT32 *pMajor, UINT32 *pMinor) override; HRESULT STDMETHODCALLTYPE GetFlags(UINT32 *pFlags) override; }; // Compile a single entry point to the target shader model HRESULT STDMETHODCALLTYPE DxcValidator::Validate( IDxcBlob *pShader, // Shader to validate. UINT32 Flags, // Validation flags. IDxcOperationResult * *ppResult // Validation output status, buffer, and errors ) { return hlsl::validateWithDebug(pShader, Flags, nullptr, ppResult); } HRESULT DxcValidator::ValidateWithOptDebugModule( IDxcBlob *pShader, // Shader to validate. UINT32 Flags, // Validation flags. llvm::Module *pDebugModule, // Debug module to validate, if available IDxcOperationResult * *ppResult // Validation output status, buffer, and errors ) { return hlsl::validateWithOptDebugModule(pShader, Flags, pDebugModule, ppResult); } HRESULT STDMETHODCALLTYPE DxcValidator::GetVersion(UINT32 *pMajor, UINT32 *pMinor) { return hlsl::getValidationVersion(pMajor, pMinor); } HRESULT STDMETHODCALLTYPE DxcValidator::GetFlags(UINT32 *pFlags) { if (pFlags == nullptr) return E_INVALIDARG; *pFlags = DxcVersionInfoFlags_None; #ifndef NDEBUG *pFlags |= DxcVersionInfoFlags_Debug; #endif *pFlags |= DxcVersionInfoFlags_Internal; return S_OK; } /////////////////////////////////////////////////////////////////////////////// HRESULT RunInternalValidator(IDxcValidator *pValidator, llvm::Module *pDebugModule, IDxcBlob *pShader, UINT32 Flags, IDxcOperationResult **ppResult) { DXASSERT_NOMSG(pValidator != nullptr); DXASSERT_NOMSG(pShader != nullptr); DXASSERT_NOMSG(ppResult != nullptr); DxcValidator *pInternalValidator = (DxcValidator *)pValidator; return pInternalValidator->ValidateWithOptDebugModule(pShader, Flags, pDebugModule, ppResult); } HRESULT CreateDxcValidator(REFIID riid, LPVOID *ppv) { try { CComPtr<DxcValidator> result( DxcValidator::Alloc(DxcGetThreadMallocNoRef())); IFROOM(result.p); return result.p->QueryInterface(riid, ppv); } CATCH_CPP_RETURN_HRESULT(); }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc
// Copyright (c) Microsoft Corporation. All rights reserved. // #include <windows.h> #include <ntverp.h> #define VER_FILETYPE VFT_DLL #define VER_FILESUBTYPE VFT_UNKNOWN #define VER_FILEDESCRIPTION_STR "DXR Fallback Compiler DLL" #define VER_INTERNALNAME_STR "DX Fallback Compiler DLL" #define VER_ORIGINALFILENAME_STR "DxrFallbackCompiler.dll" // #include <common.ver> #include "dxcetw.rc"
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxillib.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides access to dxil.dll // // // /////////////////////////////////////////////////////////////////////////////// #include "dxillib.h" #include "dxc/Support/Global.h" // For DXASSERT #include "dxc/Support/dxcapi.use.h" using namespace dxc; static DxcDllSupport g_DllSupport; static HRESULT g_DllLibResult = S_OK; static CRITICAL_SECTION cs; // Check if we can successfully get IDxcValidator from dxil.dll // This function is to prevent multiple attempts to load dxil.dll HRESULT DxilLibInitialize() { InitializeCriticalSection(&cs); return S_OK; } HRESULT DxilLibCleanup(DxilLibCleanUpType type) { HRESULT hr = S_OK; if (type == DxilLibCleanUpType::ProcessTermination) { g_DllSupport.Detach(); } else if (type == DxilLibCleanUpType::UnloadLibrary) { g_DllSupport.Cleanup(); } else { hr = E_INVALIDARG; } DeleteCriticalSection(&cs); return hr; } // g_DllLibResult is S_OK by default, check again to see if dxil.dll is loaded // If we fail to load dxil.dll, set g_DllLibResult to E_FAIL so that we don't // have multiple attempts to load dxil.dll bool DxilLibIsEnabled() { EnterCriticalSection(&cs); if (SUCCEEDED(g_DllLibResult)) { if (!g_DllSupport.IsEnabled()) { g_DllLibResult = g_DllSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); } } LeaveCriticalSection(&cs); return SUCCEEDED(g_DllLibResult); } HRESULT DxilLibCreateInstance(REFCLSID rclsid, REFIID riid, IUnknown **ppInterface) { DXASSERT_NOMSG(ppInterface != nullptr); HRESULT hr = E_FAIL; if (DxilLibIsEnabled()) { EnterCriticalSection(&cs); hr = g_DllSupport.CreateInstance(rclsid, riid, ppInterface); LeaveCriticalSection(&cs); } return hr; }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/DXCompiler.def
LIBRARY dxrfallbackcompiler EXPORTS DxcCreateDxrFallbackCompiler
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxrfallbackcompiler/dxillib.h
/////////////////////////////////////////////////////////////////////////////// // // // dxillib.h // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides wrappers to handle calls to dxil.dll // // // /////////////////////////////////////////////////////////////////////////////// #pragma once #ifndef __DXC_DXILLIB__ #define __DXC_DXILLIB__ #include "dxc/Support/WinIncludes.h" // Initialize Dxil library. HRESULT DxilLibInitialize(); // When dxcompiler is detached from process, // we should not call FreeLibrary on process termination. // So the caller has to specify if cleaning is from FreeLibrary or process // termination enum class DxilLibCleanUpType { UnloadLibrary, ProcessTermination }; HRESULT DxilLibCleanup(DxilLibCleanUpType type); // Check if can access dxil.dll bool DxilLibIsEnabled(); HRESULT DxilLibCreateInstance(REFCLSID rclsid, REFIID riid, IUnknown **ppInterface); template <class TInterface> HRESULT DxilLibCreateInstance(REFCLSID rclsid, TInterface **ppInterface) { return DxilLibCreateInstance(rclsid, __uuidof(TInterface), (IUnknown **)ppInterface); } #endif // __DXC_DXILLIB__
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxl/dxl.rc
// Copyright (c) Microsoft Corporation. All rights reserved. // #include <windows.h> #include <ntverp.h> #define VER_FILETYPE VFT_DLL #define VER_FILESUBTYPE VFT_UNKNOWN #define VER_FILEDESCRIPTION_STR "DX Linker" #define VER_INTERNALNAME_STR "DX Linker" #define VER_ORIGINALFILENAME_STR "dxl.exe" #include <common.ver>
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxl/CMakeLists.txt
# Copyright (C) Microsoft Corporation. All rights reserved. # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. # Builds dxl.exe if (MSVC) find_package(DiaSDK REQUIRED) # Used for constants and declarations. endif (MSVC) set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} DXIL HLSL dxcsupport Option # option library MSSupport # for CreateMSFileSystemForDisk ) add_clang_executable(dxl dxl.cpp ) target_link_libraries(dxl dxclib dxcompiler ) set_target_properties(dxl PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION}) if (MSVC) include_directories(AFTER ${DIASDK_INCLUDE_DIRS}) endif (MSVC) include_directories(${LLVM_SOURCE_DIR}/tools/clang/tools) add_dependencies(dxl dxclib dxcompiler) if(UNIX) set(CLANGXX_LINK_OR_COPY create_symlink) # Create a relative symlink set(dxl_binary "dxl${CMAKE_EXECUTABLE_SUFFIX}") else() set(CLANGXX_LINK_OR_COPY copy) set(dxl_binary "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/dxl${CMAKE_EXECUTABLE_SUFFIX}") endif() install(TARGETS dxl RUNTIME DESTINATION bin)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/dxl/dxl.cpp
/////////////////////////////////////////////////////////////////////////////// // // // dxl.cpp // // Copyright (C) Microsoft Corporation. All rights reserved. // // This file is distributed under the University of Illinois Open Source // // License. See LICENSE.TXT for details. // // // // Provides the entry point for the dxl console program. // // // /////////////////////////////////////////////////////////////////////////////// #include "dxclib/dxc.h" #include <vector> #ifdef _WIN32 int __cdecl wmain(int argc, const wchar_t **argv_) { std::vector<const wchar_t *> args; for (int i = 0; i < argc; i++) args.emplace_back(argv_[i]); args.emplace_back(L"-link"); return dxc::main(args.size(), args.data()); #else int main(int argc, const char **argv_) { std::vector<const char *> args; for (int i = 0; i < argc; i++) args.emplace_back(argv_[i]); args.emplace_back("-link"); return dxc::main(args.size(), args.data()); #endif // _WIN32 }
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-format/clang-format-diff.py
#!/usr/bin/env python # #===- clang-format-diff.py - ClangFormat Diff Reformatter ----*- python -*--===# # # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. # #===------------------------------------------------------------------------===# r""" ClangFormat Diff Reformatter ============================ This script reads input from a unified diff and reformats all the changed lines. This is useful to reformat all the lines touched by a specific patch. Example usage for git/svn users: git diff -U0 HEAD^ | clang-format-diff.py -p1 -i svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i """ import argparse import difflib import re import string import subprocess import StringIO import sys # Change this to the full path if clang-format is not on the path. binary = 'clang-format' def main(): parser = argparse.ArgumentParser(description= 'Reformat changed lines in diff. Without -i ' 'option just output the diff that would be ' 'introduced.') parser.add_argument('-i', action='store_true', default=False, help='apply edits to files instead of displaying a diff') parser.add_argument('-p', metavar='NUM', default=0, help='strip the smallest prefix containing P slashes') parser.add_argument('-regex', metavar='PATTERN', default=None, help='custom pattern selecting file paths to reformat ' '(case sensitive, overrides -iregex)') parser.add_argument('-iregex', metavar='PATTERN', default= r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc|js|ts|proto' r'|protodevel|java)', help='custom pattern selecting file paths to reformat ' '(case insensitive, overridden by -regex)') parser.add_argument('-v', '--verbose', action='store_true', help='be more verbose, ineffective without -i') parser.add_argument( '-style', help= 'formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)') args = parser.parse_args() # Extract changed lines for each file. filename = None lines_by_file = {} for line in sys.stdin: match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line) if match: filename = match.group(2) if filename == None: continue if args.regex is not None: if not re.match('^%s$' % args.regex, filename): continue else: if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): continue match = re.search('^@@.*\+(\d+)(,(\d+))?', line) if match: start_line = int(match.group(1)) line_count = 1 if match.group(3): line_count = int(match.group(3)) if line_count == 0: continue end_line = start_line + line_count - 1; lines_by_file.setdefault(filename, []).extend( ['-lines', str(start_line) + ':' + str(end_line)]) # Reformat files containing changes in place. for filename, lines in lines_by_file.iteritems(): if args.i and args.verbose: print 'Formatting', filename command = [binary, filename] if args.i: command.append('-i') command.extend(lines) if args.style: command.extend(['-style', args.style]) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, stdin=subprocess.PIPE) stdout, stderr = p.communicate() if p.returncode != 0: sys.exit(p.returncode); if not args.i: with open(filename) as f: code = f.readlines() formatted_code = StringIO.StringIO(stdout).readlines() diff = difflib.unified_diff(code, formatted_code, filename, filename, '(before formatting)', '(after formatting)') diff_string = string.join(diff, '') if len(diff_string) > 0: sys.stdout.write(diff_string) if __name__ == '__main__': main()
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-format/clang-format.py
# This file is a minimal clang-format vim-integration. To install: # - Change 'binary' if clang-format is not on the path (see below). # - Add to your .vimrc: # # map <C-I> :pyf <path-to-this-file>/clang-format.py<cr> # imap <C-I> <c-o>:pyf <path-to-this-file>/clang-format.py<cr> # # The first line enables clang-format for NORMAL and VISUAL mode, the second # line adds support for INSERT mode. Change "C-I" to another binding if you # need clang-format on a different key (C-I stands for Ctrl+i). # # With this integration you can press the bound key and clang-format will # format the current line in NORMAL and INSERT mode or the selected region in # VISUAL mode. The line or region is extended to the next bigger syntactic # entity. # # You can also pass in the variable "l:lines" to choose the range for # formatting. This variable can either contain "<start line>:<end line>" or # "all" to format the full file. So, to format the full file, write a function # like: # :function FormatFile() # : let l:lines="all" # : pyf <path-to-this-file>/clang-format.py # :endfunction # # It operates on the current, potentially unsaved buffer and does not create # or save any files. To revert a formatting, just undo. import difflib import json import subprocess import sys import vim # set g:clang_format_path to the path to clang-format if it is not on the path # Change this to the full path if clang-format is not on the path. binary = 'clang-format' if vim.eval('exists("g:clang_format_path")') == "1": binary = vim.eval('g:clang_format_path') # Change this to format according to other formatting styles. See the output of # 'clang-format --help' for a list of supported styles. The default looks for # a '.clang-format' or '_clang-format' file to indicate the style that should be # used. style = 'file' fallback_style = None if vim.eval('exists("g:clang_format_fallback_style")') == "1": fallback_style = vim.eval('g:clang_format_fallback_style') def main(): # Get the current text. buf = vim.current.buffer text = '\n'.join(buf) # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = vim.eval('l:lines') else: lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1) # Determine the cursor position. cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2 if cursor < 0: print 'Couldn\'t determine cursor position. Is your file empty?' return # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format. startupinfo = None if sys.platform.startswith('win32'): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE # Call formatter. command = [binary, '-style', style, '-cursor', str(cursor)] if lines != 'all': command.extend(['-lines', lines]) if fallback_style: command.extend(['-fallback-style', fallback_style]) if vim.current.buffer.name: command.extend(['-assume-filename', vim.current.buffer.name]) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, startupinfo=startupinfo) stdout, stderr = p.communicate(input=text) # If successful, replace buffer contents. if stderr: print stderr if not stdout: print ('No output from clang-format (crashed?).\n' + 'Please report to bugs.llvm.org.') else: lines = stdout.split('\n') output = json.loads(lines[0]) lines = lines[1:] sequence = difflib.SequenceMatcher(None, vim.current.buffer, lines) for op in reversed(sequence.get_opcodes()): if op[0] is not 'equal': vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]] if output.get('IncompleteFormat'): print 'clang-format: incomplete (syntax errors)' vim.command('goto %d' % (output['Cursor'] + 1)) main()
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-format/CMakeLists.txt
set(LLVM_LINK_COMPONENTS support mcparser # HLSL Change - needed for 'no target' build hlsl # HLSL Change ) add_clang_executable(clang-format ClangFormat.cpp ) set(CLANG_FORMAT_LIB_DEPS clangBasic clangFormat clangRewrite clangToolingCore ) target_link_libraries(clang-format ${CLANG_FORMAT_LIB_DEPS} ) if( LLVM_USE_SANITIZE_COVERAGE ) add_subdirectory(fuzzer) endif() install(TARGETS clang-format RUNTIME DESTINATION bin) install(PROGRAMS clang-format-bbedit.applescript DESTINATION share/clang) install(PROGRAMS clang-format-diff.py DESTINATION share/clang) install(PROGRAMS clang-format-sublime.py DESTINATION share/clang) install(PROGRAMS clang-format.el DESTINATION share/clang) install(PROGRAMS clang-format.py DESTINATION share/clang) install(PROGRAMS git-clang-format DESTINATION bin)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-format/clang-format-sublime.py
# This file is a minimal clang-format sublime-integration. To install: # - Change 'binary' if clang-format is not on the path (see below). # - Put this file into your sublime Packages directory, e.g. on Linux: # ~/.config/sublime-text-2/Packages/User/clang-format-sublime.py # - Add a key binding: # { "keys": ["ctrl+shift+c"], "command": "clang_format" }, # # With this integration you can press the bound key and clang-format will # format the current lines and selections for all cursor positions. The lines # or regions are extended to the next bigger syntactic entities. # # It operates on the current, potentially unsaved buffer and does not create # or save any files. To revert a formatting, just undo. from __future__ import print_function import sublime import sublime_plugin import subprocess # Change this to the full path if clang-format is not on the path. binary = 'clang-format' # Change this to format according to other formatting styles. See the output of # 'clang-format --help' for a list of supported styles. The default looks for # a '.clang-format' or '_clang-format' file to indicate the style that should be # used. style = 'file' class ClangFormatCommand(sublime_plugin.TextCommand): def run(self, edit): encoding = self.view.encoding() if encoding == 'Undefined': encoding = 'utf-8' regions = [] command = [binary, '-style', style] for region in self.view.sel(): regions.append(region) region_offset = min(region.a, region.b) region_length = abs(region.b - region.a) command.extend(['-offset', str(region_offset), '-length', str(region_length), '-assume-filename', str(self.view.file_name())]) old_viewport_position = self.view.viewport_position() buf = self.view.substr(sublime.Region(0, self.view.size())) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) output, error = p.communicate(buf.encode(encoding)) if error: print(error) self.view.replace( edit, sublime.Region(0, self.view.size()), output.decode(encoding)) self.view.sel().clear() for region in regions: self.view.sel().add(region) # FIXME: Without the 10ms delay, the viewport sometimes jumps. sublime.set_timeout(lambda: self.view.set_viewport_position( old_viewport_position, False), 10)
0
repos/DirectXShaderCompiler/tools/clang/tools
repos/DirectXShaderCompiler/tools/clang/tools/clang-format/ClangFormat.cpp
//===-- clang-format/ClangFormat.cpp - Clang format tool ------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// /// /// \file /// \brief This file implements a clang-format tool that automatically formats /// (fragments of) C++ code. /// //===----------------------------------------------------------------------===// #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Format/Format.h" #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Signals.h" using namespace llvm; static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden); // Mark all our options with this category, everything else (except for -version // and -help) will be hidden. static cl::OptionCategory ClangFormatCategory("Clang-format options"); static cl::list<unsigned> Offsets("offset", cl::desc("Format a range starting at this byte offset.\n" "Multiple ranges can be formatted by specifying\n" "several -offset and -length pairs.\n" "Can only be used with one input file."), cl::cat(ClangFormatCategory)); static cl::list<unsigned> Lengths("length", cl::desc("Format a range of this length (in bytes).\n" "Multiple ranges can be formatted by specifying\n" "several -offset and -length pairs.\n" "When only a single -offset is specified without\n" "-length, clang-format will format up to the end\n" "of the file.\n" "Can only be used with one input file."), cl::cat(ClangFormatCategory)); static cl::list<std::string> LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n" "lines (both 1-based).\n" "Multiple ranges can be formatted by specifying\n" "several -lines arguments.\n" "Can't be used with -offset and -length.\n" "Can only be used with one input file."), cl::cat(ClangFormatCategory)); static cl::opt<std::string> Style("style", cl::desc(clang::format::StyleOptionHelpDescription), cl::init("file"), cl::cat(ClangFormatCategory)); static cl::opt<std::string> FallbackStyle("fallback-style", cl::desc("The name of the predefined style used as a\n" "fallback in case clang-format is invoked with\n" "-style=file, but can not find the .clang-format\n" "file to use.\n" "Use -fallback-style=none to skip formatting."), cl::init("LLVM"), cl::cat(ClangFormatCategory)); static cl::opt<std::string> AssumeFilename("assume-filename", cl::desc("When reading from stdin, clang-format assumes this\n" "filename to look for a style config file (with\n" "-style=file) and to determine the language."), cl::cat(ClangFormatCategory)); static cl::opt<bool> Inplace("i", cl::desc("Inplace edit <file>s, if specified."), cl::cat(ClangFormatCategory)); static cl::opt<bool> OutputXML("output-replacements-xml", cl::desc("Output replacements as XML."), cl::cat(ClangFormatCategory)); static cl::opt<bool> DumpConfig("dump-config", cl::desc("Dump configuration options to stdout and exit.\n" "Can be used with -style option."), cl::cat(ClangFormatCategory)); static cl::opt<unsigned> Cursor("cursor", cl::desc("The position of the cursor when invoking\n" "clang-format from an editor integration"), cl::init(0), cl::cat(ClangFormatCategory)); static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"), cl::cat(ClangFormatCategory)); namespace clang { namespace format { static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source, SourceManager &Sources, FileManager &Files) { const FileEntry *Entry = Files.getVirtualFile(FileName == "-" ? "<stdin>" : FileName, Source->getBufferSize(), 0); Sources.overrideFileContents(Entry, Source, true); return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User); } // Parses <start line>:<end line> input to a pair of line numbers. // Returns true on error. static bool parseLineRange(StringRef Input, unsigned &FromLine, unsigned &ToLine) { std::pair<StringRef, StringRef> LineRange = Input.split(':'); return LineRange.first.getAsInteger(0, FromLine) || LineRange.second.getAsInteger(0, ToLine); } static bool fillRanges(SourceManager &Sources, FileID ID, const MemoryBuffer *Code, std::vector<CharSourceRange> &Ranges) { if (!LineRanges.empty()) { if (!Offsets.empty() || !Lengths.empty()) { llvm::errs() << "error: cannot use -lines with -offset/-length\n"; return true; } for (unsigned i = 0, e = LineRanges.size(); i < e; ++i) { unsigned FromLine, ToLine; if (parseLineRange(LineRanges[i], FromLine, ToLine)) { llvm::errs() << "error: invalid <start line>:<end line> pair\n"; return true; } if (FromLine > ToLine) { llvm::errs() << "error: start line should be less than end line\n"; return true; } SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1); SourceLocation End = Sources.translateLineCol(ID, ToLine, UINT_MAX); if (Start.isInvalid() || End.isInvalid()) return true; Ranges.push_back(CharSourceRange::getCharRange(Start, End)); } return false; } if (Offsets.empty()) Offsets.push_back(0); if (Offsets.size() != Lengths.size() && !(Offsets.size() == 1 && Lengths.empty())) { llvm::errs() << "error: number of -offset and -length arguments must match.\n"; return true; } for (unsigned i = 0, e = Offsets.size(); i != e; ++i) { if (Offsets[i] >= Code->getBufferSize()) { llvm::errs() << "error: offset " << Offsets[i] << " is outside the file\n"; return true; } SourceLocation Start = Sources.getLocForStartOfFile(ID).getLocWithOffset(Offsets[i]); SourceLocation End; if (i < Lengths.size()) { if (Offsets[i] + Lengths[i] > Code->getBufferSize()) { llvm::errs() << "error: invalid length " << Lengths[i] << ", offset + length (" << Offsets[i] + Lengths[i] << ") is outside the file.\n"; return true; } End = Start.getLocWithOffset(Lengths[i]); } else { End = Sources.getLocForEndOfFile(ID); } Ranges.push_back(CharSourceRange::getCharRange(Start, End)); } return false; } static void outputReplacementXML(StringRef Text) { size_t From = 0; size_t Index; while ((Index = Text.find_first_of("\n\r", From)) != StringRef::npos) { llvm::outs() << Text.substr(From, Index - From); switch (Text[Index]) { case '\n': llvm::outs() << "&#10;"; break; case '\r': llvm::outs() << "&#13;"; break; default: llvm_unreachable("Unexpected character encountered!"); } From = Index + 1; } llvm::outs() << Text.substr(From); } // Returns true on error. static bool format(StringRef FileName) { FileManager Files((FileSystemOptions())); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr = MemoryBuffer::getFileOrSTDIN(FileName); if (std::error_code EC = CodeOrErr.getError()) { llvm::errs() << EC.message() << "\n"; return true; } std::unique_ptr<llvm::MemoryBuffer> Code = std::move(CodeOrErr.get()); if (Code->getBufferSize() == 0) return false; // Empty files are formatted correctly. FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files); std::vector<CharSourceRange> Ranges; if (fillRanges(Sources, ID, Code.get(), Ranges)) return true; FormatStyle FormatStyle = getStyle( Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle); bool IncompleteFormat = false; tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat); if (OutputXML) { llvm::outs() << "<?xml version='1.0'?>\n<replacements " "xml:space='preserve' incomplete_format='" << (IncompleteFormat ? "true" : "false") << "'>\n"; if (Cursor.getNumOccurrences() != 0) llvm::outs() << "<cursor>" << tooling::shiftedCodePosition(Replaces, Cursor) << "</cursor>\n"; for (tooling::Replacements::const_iterator I = Replaces.begin(), E = Replaces.end(); I != E; ++I) { llvm::outs() << "<replacement " << "offset='" << I->getOffset() << "' " << "length='" << I->getLength() << "'>"; outputReplacementXML(I->getReplacementText()); llvm::outs() << "</replacement>\n"; } llvm::outs() << "</replacements>\n"; } else { Rewriter Rewrite(Sources, LangOptions()); tooling::applyAllReplacements(Replaces, Rewrite); if (Inplace) { if (FileName == "-") llvm::errs() << "error: cannot use -i when reading from stdin.\n"; else if (Rewrite.overwriteChangedFiles()) return true; } else { if (Cursor.getNumOccurrences() != 0) outs() << "{ \"Cursor\": " << tooling::shiftedCodePosition(Replaces, Cursor) << ", \"IncompleteFormat\": " << (IncompleteFormat ? "true" : "false") << " }\n"; Rewrite.getEditBuffer(ID).write(outs()); } } return false; } } // namespace format } // namespace clang static void PrintVersion() { raw_ostream &OS = outs(); OS << clang::getClangToolFullVersion("clang-format") << '\n'; } int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); cl::HideUnrelatedOptions(ClangFormatCategory); cl::SetVersionPrinter(PrintVersion); cl::ParseCommandLineOptions( argc, argv, "A tool to format C/C++/Obj-C code.\n\n" "If no arguments are specified, it formats the code from standard input\n" "and writes the result to the standard output.\n" "If <file>s are given, it reformats the files. If -i is specified\n" "together with <file>s, the files are edited in-place. Otherwise, the\n" "result is written to the standard output.\n"); if (Help) cl::PrintHelpMessage(); if (DumpConfig) { std::string Config = clang::format::configurationAsText(clang::format::getStyle( Style, FileNames.empty() ? AssumeFilename : FileNames[0], FallbackStyle)); llvm::outs() << Config << "\n"; return 0; } bool Error = false; switch (FileNames.size()) { case 0: Error = clang::format::format("-"); break; case 1: Error = clang::format::format(FileNames[0]); break; default: if (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty()) { llvm::errs() << "error: -offset, -length and -lines can only be used for " "single file.\n"; return 1; } for (unsigned i = 0; i < FileNames.size(); ++i) Error |= clang::format::format(FileNames[i]); break; } return Error ? 1 : 0; }
0
repos/DirectXShaderCompiler/tools/clang/tools/clang-format
repos/DirectXShaderCompiler/tools/clang/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp
//===-- ClangFormatFuzzer.cpp - Fuzz the Clang format tool ----------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// /// /// \file /// \brief This file implements a function that runs Clang format on a single /// input. This function is then linked into the Fuzzer library. /// //===----------------------------------------------------------------------===// #include "clang/Format/Format.h" extern "C" void LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { // FIXME: fuzz more things: different styles, different style features. std::string s((const char *)data, size); auto Style = getGoogleStyle(clang::format::FormatStyle::LK_Cpp); Style.ColumnLimit = 60; applyAllReplacements(s, clang::format::reformat( Style, s, {clang::tooling::Range(0, s.size())})); }