summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/RecordLayoutBuilder.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Move vtordisp mode from Attr class to LangOptions.h, NFCReid Kleckner2019-11-221-3/+3
| | | | | This removes one of the two uses of Attr.h in DeclCXX.h, reducing the need to include Attr.h as widely. LangOptions is already very popular.
* P0840R2: support for [[no_unique_address]] attributeRichard Smith2019-06-201-40/+86
| | | | | | | | | | | | | | | | | Summary: Add support for the C++2a [[no_unique_address]] attribute for targets using the Itanium C++ ABI. This depends on D63371. Reviewers: rjmccall, aaron.ballman Subscribers: dschuff, aheejin, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63451 llvm-svn: 363976
* Use llvm::stable_sortFangrui Song2019-04-241-4/+4
| | | | llvm-svn: 359098
* Range-style std::find{,_if} -> llvm::find{,_if}. NFCFangrui Song2019-03-311-1/+1
| | | | llvm-svn: 357359
* [AST] Improve support of external layouts in `MicrosoftRecordLayoutBuilder`Aleksandr Urakov2019-03-131-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch fixes several small problems with external layouts support in `MicrosoftRecordLayoutBuilder`: - aligns properly the size of a struct that ends with a bit field. It was aligned on byte before, not on the size of the field, so the struct size was smaller than it should be; - adjusts the struct size when injecting a vbptr in the case when there were no bases or fields allocated after the vbptr. Similarly, without the adjustment the struct was smaller than it should be; - the same fix as above for the vfptr. All these fixes affect the non-virtual size of a struct, so they are tested through non-virtual inheritance. Reviewers: rnk, zturner, rsmith Reviewed By: rnk Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58544 llvm-svn: 356047
* Use llvm::is_contained. NFCFangrui Song2019-02-101-1/+1
| | | | llvm-svn: 353635
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Fix up diagnostics.Richard Trieu2018-12-141-1/+1
| | | | | | | | | | | Move some diagnostics around between Diagnostic*Kinds.td files. Diagnostics used in multiple places were moved to DiagnosticCommonKinds.td. Diagnostics listed in the wrong place (ie, Sema diagnostics listed in DiagnosticsParseKinds.td) were moved to the correct places. One diagnostic split into two so that the diagnostic string is in the .td file instead of in code. Cleaned up the diagnostic includes after all the changes. llvm-svn: 349125
* [AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` whenAleksandr Urakov2018-10-231-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | an external layout is used Summary: The patch removes alignment of virtual bases when an external layout is used. We have two cases: - the external layout source has an information about virtual bases offsets, so we just use them; - the external source has no information about virtual bases offsets. In this case we can't predict where the base will be located. If we will align it but there will be something like `#pragma pack(push, 1)` really, then likely our layout will not fit into the real structure size, and then some asserts will hit. The asserts look reasonable, so I don't think that we need to remove them. May be it would be better instead don't align fields / bases etc. (so treat it always as `#pragma pack(push, 1)`) when an external layout source is used but no info about a field location is presented. This one is related to D49871 Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer Reviewed By: rnk Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D53497 llvm-svn: 345012
* Improve support of PDB as an external layout sourceAleksandr Urakov2018-07-311-23/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch improves support of PDB as an external layout source in the next cases: - Multiple non-virtual inheritance from packed base classes. When using external layout, there's no need to align `NonVirtualSize` of a base class. It may cause an overlapping when the next base classes will be layouted (but there is a slightly different case in the test because I can't find a way to specify a base offset); - Support of nameless structs and unions. There is no info about nameless child structs and unions in Microsoft cl-emitted PDBs. Instead all its fields are just treated as outer structure's (union's) fields. This also causes a fields overlapping, and makes it possible for unions to have fields located at a non-zero offset. Reviewers: rsmith, zturner, rnk, mstorsjo, majnemer Reviewed By: rnk Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D49871 llvm-svn: 338353
* Remove trailing spaceFangrui Song2018-07-301-90/+90
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* [ARM, AArch64]: Use unadjusted alignment when passing composites as argumentsMomchil Velikov2018-07-301-5/+15
| | | | | | | | | | | | | | | | | | The "Procedure Call Procedure Call Standard for the ARM® Architecture" (https://static.docs.arm.com/ihi0042/f/IHI0042F_aapcs.pdf), specifies that composite types are passed according to their "natural alignment", i.e. the alignment before alignment adjustment on the entire composite is applied. The same applies for AArch64 ABI. Clang, however, used the adjusted alignment. GCC already implements the ABI correctly. With this patch Clang becomes compatible with GCC and passes such arguments in accordance with AAPCS. Differential Revision: https://reviews.llvm.org/D46013 llvm-svn: 338279
* Use external layout information to layout bit-fields for MS ABI.Richard Smith2018-07-131-1/+9
| | | | | | | | Patch by Aleksandr Urakov! Differential Revision: https://reviews.llvm.org/D49227 llvm-svn: 337047
* Maintain PS4 ABI compatibility by making the fix made in r331136 not apply ↵Douglas Yung2018-05-181-4/+6
| | | | | | | | | | | | when the target is the PS4. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47084 llvm-svn: 332773
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-44/+44
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* Remove now-unnecessary check for non-zero nvsize in addition toRichard Smith2018-05-071-2/+2
| | | | | | emptyness in MS record layout. llvm-svn: 331621
* PR37275 packed attribute should not apply to base classesRichard Smith2018-04-291-3/+8
| | | | | | | | | | | | | Clang incorrectly applied the packed attribute to base classes. Per GCC's documentation and as can be observed from its behavior, packed only applies to members, not base classes. This change is conditioned behind -fclang-abi-compat so that an ABI break can be avoided by users if desired. Differential Revision: https://reviews.llvm.org/D46218 llvm-svn: 331136
* DR1672, DR1813, DR1881, DR2120: Implement recent fixes to "standardRichard Smith2018-04-051-1/+1
| | | | | | | | | | | | | | | | | layout" rules. The new rules say that a standard-layout struct has its first non-static data member and all base classes at offset 0, and consider a class to not be standard-layout if that would result in multiple subobjects of a single type having the same address. We track "is C++11 standard-layout class" separately from "is standard-layout class" so that the ABIs that need this information can still use it. Differential Revision: https://reviews.llvm.org/D45176 llvm-svn: 329332
* [RecordLayout] Only assert that fundamental type sizes are power of two on MSVCMartin Storsjo2018-03-011-4/+26
| | | | | | | | | | Make types with sizes that aren't a power of two an error (that can be disabled) in structs with ms_struct layout, except on mingw where the situation is quite likely to occur and GCC handles it silently. Differential Revision: https://reviews.llvm.org/D43908 llvm-svn: 326476
* Remove redundant casts. NFCGeorge Burgess IV2018-03-011-1/+1
| | | | | | | | | | | | | | | | | | | So I wrote a clang-tidy check to lint out redundant `isa`, `cast`, and `dyn_cast`s for fun. This is a portion of what it found for clang; I plan to do similar cleanups in LLVM and other subprojects when I find time. Because of the volume of changes, I explicitly avoided making any change that wasn't highly local and obviously correct to me (e.g. we still have a number of foo(cast<Bar>(baz)) that I didn't touch, since overloading is a thing and the cast<Bar> did actually change the type -- just up the class hierarchy). I also tried to leave the types we were cast<>ing to somewhere nearby, in cases where it wasn't locally obvious what we were dealing with before. llvm-svn: 326416
* [RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfieldsMartin Storsjo2018-02-271-1/+6
| | | | | | | | | | | | | | | | | | | | When targeting GNU/MinGW for i386, the size of the "long double" data type is 12 bytes (while it is 8 bytes in MSVC). When building with -mms-bitfields to have struct layouts match MSVC, data types are laid out in a struct with alignment according to their size. However, this doesn't make sense for the long double type, since it doesn't match MSVC at all, and aligning to a non-power-of-2 size triggers other asserts later. This matches what GCC does, aligning a long double to 4 bytes in structs on i386 even when -mms-bitfields is specified. This fixes asserts when using the max_align_t data type when building for MinGW/i386 with the -mms-bitfields flag. Differential Revision: https://reviews.llvm.org/D43734 llvm-svn: 326173
* [PR32482] Fix bitfield layout for -mms-bitfield and pragma packAlex Lorenz2018-01-311-3/+4
| | | | | | | | | | | The patch ensures that a new storage unit is created when the new bitfield's size is wider than the available bits. rdar://36343145 Differential Revision: https://reviews.llvm.org/D42660 llvm-svn: 323921
* Refactor overridden methods iteration to avoid double lookups.Benjamin Kramer2017-12-171-4/+3
| | | | | | Convert most uses to range-for loops. No functionality change intended. llvm-svn: 320954
* Convert clang::LangAS to a strongly typed enumAlexander Richardson2017-10-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Convert clang::LangAS to a strongly typed enum Currently both clang AST address spaces and target specific address spaces are represented as unsigned which can lead to subtle errors if the wrong type is passed. It is especially confusing in the CodeGen files as it is not possible to see what kind of address space should be passed to a function without looking at the implementation. I originally made this change for our LLVM fork for the CHERI architecture where we make extensive use of address spaces to differentiate between capabilities and pointers. When merging the upstream changes I usually run into some test failures or runtime crashes because the wrong kind of address space is passed to a function. By converting the LangAS enum to a C++11 we can catch these errors at compile time. Additionally, it is now obvious from the function signature which kind of address space it expects. I found the following errors while writing this patch: - ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address space to TargetInfo::getPointer{Width,Align}() - TypePrinter::printAttributedAfter() prints the numeric value of the clang AST address space instead of the target address space. However, this code is not used so I kept the current behaviour - initializeForBlockHeader() in CGBlocks.cpp was passing LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}() - CodeGenFunction::EmitBlockLiteral() was passing a AST address space to TargetInfo::getPointerWidth() - CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space to Qualifiers::addAddressSpace() - CGOpenMPRuntimeNVPTX::getParameterAddress() was using llvm::Type::getPointerTo() with a AST address space - clang_getAddressSpace() returns either a LangAS or a target address space. As this is exposed to C I have kept the current behaviour and added a comment stating that it is probably not correct. Other than this the patch should not cause any functional changes. Reviewers: yaxunl, pcc, bader Reviewed By: yaxunl, bader Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits Differential Revision: https://reviews.llvm.org/D38816 llvm-svn: 315871
* Remove unused variables. No functionality change.Benjamin Kramer2017-10-081-1/+0
| | | | llvm-svn: 315185
* Fix broken links to the Itanium CXX ABIVlad Tsyrklevich2017-09-121-1/+1
| | | | llvm-svn: 312986
* [clang] Change the condition of unnecessary packed warningYan Wang2017-08-011-13/+13
| | | | | | | | | | | | | | | | | | | | Summary: Change the condition of this unnecessary packed warning. The packed is unnecessary when 1. the alignment of the struct/class won't alter. 2. the size is unchanged. 3. the offset of each field is the same. Remove all field-level warning. Reviewers: chh, akyrtzi, rtrieu Reviewed By: chh Subscribers: rsmith, srhines, cfe-commits, xazax.hun Differential Revision: https://reviews.llvm.org/D34114 llvm-svn: 309750
* [CodeGen][ObjC] Fix GNU's encoding of bit-field ivars.Akira Hatanaka2017-06-271-0/+35
| | | | | | | | | | | | | | | | | According to the documentation, when encoding a bit-field, GNU runtime needs its starting position in addition to its type and size. https://gcc.gnu.org/onlinedocs/gcc/Type-encoding.html Prior to r297702, the starting position information was not being encoded, which is incorrect, and after r297702, an assertion started to fail because an ObjCIvarDecl was being passed to a function expecting a FieldDecl. This commit moves LookupFieldBitOffset to ASTContext and uses the function to encode the starting position of bit-fields. llvm-svn: 306364
* [RecordLayout] Use an ASTVector instead of using a separate pointer and counterDavid Majnemer2016-05-241-12/+7
| | | | | | No functional change is intended. llvm-svn: 270591
* [MS ABI] Implement __declspec(empty_bases) and __declspec(layout_version)David Majnemer2016-05-231-16/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The layout_version attribute is pretty straightforward: use the layout rules from version XYZ of MSVC when used like struct __declspec(layout_version(XYZ)) S {}; The empty_bases attribute is more interesting. It tries to get the C++ empty base optimization to fire more often by tweaking the MSVC ABI rules in subtle ways: 1. Disable the leading and trailing zero-sized object flags if a class is marked __declspec(empty_bases) and is empty. This means that given: struct __declspec(empty_bases) A {}; struct __declspec(empty_bases) B {}; struct C : A, B {}; 'C' will have size 1 and nvsize 0 despite not being annotated __declspec(empty_bases). 2. When laying out virtual or non-virtual bases, disable the injection of padding between classes if the most derived class is marked __declspec(empty_bases). This means that given: struct A {}; struct B {}; struct __declspec(empty_bases) C : A, B {}; 'C' will have size 1 and nvsize 0. 3. When calculating the offset of a non-virtual base, choose offset zero if the most derived class is marked __declspec(empty_bases) and the base is empty _and_ has an nvsize of 0. Because of the ABI rules, this does not mean that empty bases reliably get placed at offset 0! For example: struct A {}; struct B {}; struct __declspec(empty_bases) C : A, B { virtual ~C(); }; 'C' will be pointer sized to account for the vfptr at offset 0. 'A' and 'B' will _not_ be at offset 0 despite being empty! Instead, they will be located right after the vfptr. This occurs due to the interaction betweeen non-virtual base layout and virtual function pointer injection: injection occurs after the nv-bases and shifts them down by the size of a pointer. llvm-svn: 270457
* pr26544: Bitfield layout with pragma pack and attributes "packed" andAlexey Bataev2016-02-191-2/+9
| | | | | | | | | | "aligned", by Vladimir Yakovlev Fix clang/gcc incompatibility of bitfields layout in the presence of pragma packed and attributes aligned and packed. Differential Revision: http://reviews.llvm.org/D17023 llvm-svn: 261321
* [AST] Fix typos in RecordLayoutBuilderDavid Majnemer2016-02-121-5/+5
| | | | | | No functional change is intended. llvm-svn: 260709
* Do not honor explicit alignment attribute on fields for PS4.Sunil Srivastava2016-02-051-2/+4
| | | | | | | | This change reverts r257462 for PS4 triple. Differential Revision: http://reviews.llvm.org/D16788 llvm-svn: 259916
* Update for LLVM function name change.Rui Ueyama2016-01-141-41/+37
| | | | llvm-svn: 257802
* PR18513: make gcc compatible layout for bit-fields with explicit aligned ↵Alexey Bataev2016-01-121-1/+9
| | | | | | | | | attribute, by Dmitry Polukhin Fix binary compatibility issue with GCC. Differential Revision: http://reviews.llvm.org/D14980 llvm-svn: 257462
* [CUDA] Make vtable construction aware of host/device side of CUDA compilation.Artem Belevich2015-12-171-0/+15
| | | | | | | | | | | | | | | | | | | C++ emits vtables for classes that have key function present in the current TU. While we compile CUDA the fact that key function was found in this TU does not mean that we are going to generate code for it. E.g. vtable for a class with host-only methods should not (and can not) be generated on device side, because we'll never generate code for them during device-side compilation. This patch adds an extra CUDA-specific check during key method computation and filters out potential key methods that are not suitable for this side of CUDA compilation. When we codegen vtable, entries for unsuitable methods are set to null. Differential Revision: http://reviews.llvm.org/D15309 llvm-svn: 255911
* Don't adjust field offsets when using external record layout.Zachary Turner2015-10-011-4/+11
| | | | | | | | | | | This was already being done when injecting the VBPtr, but not when injecting the VFPtr. This fixes a number of tests in LLDB's test suite. Reviewed by: David Majnemer Differential Revision: http://reviews.llvm.org/D13276 llvm-svn: 249085
* [RecordLayoutBuilder] Remove duplicated diagnostic argument. NFC.Benjamin Kramer2015-08-211-3/+3
| | | | llvm-svn: 245700
* Fix the layout of bitfields in ms_struct unions: theirJohn McCall2015-08-191-90/+152
| | | | | | | | | | | | | | | alignment is ignored, and they always allocate a complete storage unit. Also, change the dumping of AST record layouts: use the more readable C++-style dumping even in C, include bitfield offset information in the dump, and don't print sizeof/alignof information for fields of record type, since we don't do so for bases or other kinds of field. rdar://22275433 llvm-svn: 245514
* [dllimport] A non-imported class with an imported key can't have a keyReid Kleckner2015-08-101-0/+6
| | | | | | | | | | | | | | | | | Summary: The vtable takes its DLL storage class from the class, not the key function. When they disagree, the vtable won't be exported by the DLL that defines the key function. The easiest way to ensure that importers of the class emit their own vtable is to say that the class has no key function. Reviewers: hans, majnemer Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11913 llvm-svn: 244488
* [AST] Rename RecordLayoutBuilder to ItaniumRecordLayoutBuilderDavid Majnemer2015-07-251-141/+119
| | | | | | | RecordLayoutBuilder is an inaccruate name because it does not build all records. It only builds layouts for targets using the Itanium C++ ABI. llvm-svn: 243225
* Remove two unused includes, part 2...Nico Weber2015-07-191-1/+0
| | | | llvm-svn: 242649
* Fix "the the" in comments/documentation/etc.Eric Christopher2015-06-191-1/+1
| | | | llvm-svn: 240110
* Work around overloading bug in MSVC 2015Reid Kleckner2015-05-211-3/+3
| | | | | | | | MSVC 2015 appears to be unable to find the correct operator== here. I haven't yet filed a bug with Microsoft as I've been unable to create a reduced test case. llvm-svn: 237862
* Cleanup some MS-ABI specific codeDavid Majnemer2015-04-241-3/+5
| | | | | | No functional change intended. llvm-svn: 235680
* Fix obviously broken assertion, NFCReid Kleckner2015-03-241-4/+4
| | | | llvm-svn: 233138
* Reland r230446, "MS ABI: Try to respect external AST source record layouts"Reid Kleckner2015-02-251-59/+129
| | | | | | | | | It broke test/PCH/headersearch.cpp because it was using -Wpadding, which only works for Itanium layout. Before this commit, we would use Itanium record layout when using PCH, which is crazy. Now that the test uses an explicit Itanium triple, we can reland. llvm-svn: 230525
* Whitespace.NAKAMURA Takumi2015-02-251-8/+8
| | | | llvm-svn: 230475
* Revert r230446, "MS ABI: Try to respect external AST source record layouts"NAKAMURA Takumi2015-02-251-130/+60
| | | | | | It fails on Clang::PCH/headersearch.cpp for targeting msvc. llvm-svn: 230474
* MS ABI: Try to respect external AST source record layoutsReid Kleckner2015-02-251-60/+130
| | | | | | | | Covered by existing tests in test/CodeGen/override-layout.c and test/CodeGenCXX/override-layout.cpp. Seriously, they found real bugs in my code. :) llvm-svn: 230446
OpenPOWER on IntegriCloud