summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprConstant.cpp
AgeCommit message (Collapse)Author
2014-10-08Fix IRGen for referencing a static local before emitting its declReid Kleckner
Summary: Previously CodeGen assumed that static locals were emitted before they could be accessed, which is true for automatic storage duration locals. However, it is possible to have CodeGen emit a nested function that uses a static local before emitting the function that defines the static local, breaking that assumption. Fix it by creating the static local upon access and ensuring that the deferred function body gets emitted. We may not be able to emit the initializer properly from outside the function body, so don't try. Fixes PR18020. See also previous attempts to fix static locals in PR6769 and PR7101. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4787 llvm-svn: 219265
2014-08-27Allow __fp16 as a function arg or return type for AArch64Oliver Stannard
ACLE 2.0 allows __fp16 to be used as a function argument or return type. This enables this for AArch64. This also fixes an existing bug that causes clang to not allow homogeneous floating-point aggregates with a base type of __fp16. This is valid for AAPCS64, but not for AAPCS-VFP. llvm-svn: 216558
2014-07-31PR18097: Support initializing an _Atomic(T) from an object of C++ class type TRichard Smith
or a class derived from T. We already supported this when initializing _Atomic(T) from T for most (and maybe all) other reasonable values of T. llvm-svn: 214390
2014-05-21[C++11] Use 'nullptr'. CodeGen edition.Craig Topper
llvm-svn: 209272
2014-04-23Objective-C [IRGen]. Fixes a crash in IRGen involving use ofFariborz Jahanian
'typeof' to extract type of an @encode expression used in an initializer. // rdar://16655340 llvm-svn: 207004
2014-04-17Bug 18567: Fix constantexpr pointer casts with address spaces.Matt Arsenault
Getting a pointer into a struct at a non-zero offset would try to use the default address space. llvm-svn: 206478
2014-03-13[C++11] Replacing CXXRecordDecl iterators vbases_begin() and vbases_end() ↵Aaron Ballman
with iterator_range vbases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203808
2014-03-13[C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with ↵Aaron Ballman
iterator_range bases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203803
2014-03-08[C++11] Replacing RecordDecl iterators field_begin() and field_end() with ↵Aaron Ballman
iterator_range fields(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203355
2013-12-28Rename isBuiltinCall() to getBuiltinCallee()Alp Toker
This better describes what the function does. Cleanup only. llvm-svn: 198127
2013-12-11Add front-end infrastructure now address space casts are in LLVM IR.David Tweed
With the introduction of explicit address space casts into LLVM, there's a need to provide a new cast kind the front-end can create for C/OpenCL/CUDA and code to produce address space casts from those kinds when appropriate. Patch by Michele Scandale! llvm-svn: 197036
2013-09-27Abstract out the emission of vtables, add basic support for vtable emission ↵Timur Iskhodzhanov
when using -cxx-abi microsoft Reviewed at http://llvm-reviews.chandlerc.com/D1532 llvm-svn: 191523
2013-09-27AST: Handle qualified array types in typeid() expressionsDavid Majnemer
The intent of getTypeOperand() was to yield an unqualified type. However QualType::getUnqualifiedType() does not strip away qualifiers on arrays. N.B. This worked fine when typeid() was applied to an expression because we would inject as implicit cast to the unqualified array type in the AST. llvm-svn: 191487
2013-07-20Make IgnoreParens() look through ChooseExprs.Eli Friedman
This is the same way GenericSelectionExpr works, and it's generally a more consistent approach. A large part of this patch is devoted to caching the value of the condition of a ChooseExpr; it's needed to avoid threading an ASTContext into IgnoreParens(). Fixes <rdar://problem/14438917>. llvm-svn: 186738
2013-07-16Make Expr::isConstantInitializer match IRGen.Eli Friedman
Sema needs to be able to accurately determine what will be emitted as a constant initializer and what will not, so we get accurate errors in C and accurate -Wglobal-constructors warnings in C++. This makes Expr::isConstantInitializer match CGExprConstant as closely as possible. llvm-svn: 186464
2013-06-26Rewrite record layout for ms_struct structs.Eli Friedman
The old implementation of ms_struct in RecordLayoutBuilder was a complete mess: it depended on complicated conditionals which didn't really reflect the underlying logic, and placed a burden on users of the resulting RecordLayout. This commit rips out almost all of the old code, and replaces it with simple checks in RecordLayoutBuilder::LayoutBitField. This commit also fixes <rdar://problem/14252115>, a bug where class inheritance would cause us to lay out bitfields incorrectly. llvm-svn: 185018
2013-06-12PR12086, PR15117Richard Smith
Introduce CXXStdInitializerListExpr node, representing the implicit construction of a std::initializer_list<T> object from its underlying array. The AST representation of such an expression goes from an InitListExpr with a flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr). This more detailed representation has several advantages, the most important of which is that the new MaterializeTemporaryExpr allows us to directly model lifetime extension of the underlying temporary array. Using that, this patch *drastically* simplifies the IR generation of this construct, provides IR generation support for nested global initializer_list objects, fixes several bugs where the destructors for the underlying array would accidentally not get invoked, and provides constant expression evaluation support for std::initializer_list objects. llvm-svn: 183872
2013-06-05Model temporary lifetime-extension explicitly in the AST. Use this model toRichard Smith
handle temporaries which have been lifetime-extended to static storage duration within constant expressions. This correctly handles nested lifetime extension (through reference members of aggregates in aggregate initializers) but non-constant-expression emission hasn't yet been updated to do the same. llvm-svn: 183283
2013-04-20C++1y: Allow aggregates to have default initializers.Richard Smith
Add a CXXDefaultInitExpr, analogous to CXXDefaultArgExpr, and use it both in CXXCtorInitializers and in InitListExprs to represent a default initializer. There's an additional complication here: because the default initializer can refer to the initialized object via its 'this' pointer, we need to make sure that 'this' points to the right thing within the evaluation. llvm-svn: 179958
2013-04-05Allow EmitConstantInit() to emit constant initializers for objects with ↵Alexey Samsonov
trivial constructors and non-trivial destructors. Test that such objects are ignored by init-order checker. llvm-svn: 178856
2013-03-05Silence a number of static analyzer warnings with assertions and such.Jordan Rose
No functionality change. llvm-svn: 176469
2013-01-23Add a new LangOpt NativeHalfType. This option allows for native half/fp16Joey Gouly
operations (as opposed to storage only half/fp16). Also add some semantic checks for OpenCL half types. llvm-svn: 173254
2013-01-20Implement OpenCL event_t as Clang builtin type, including event_t related ↵Guy Benyei
OpenCL restrictions (OpenCL 1.2 spec 6.9) llvm-svn: 172973
2013-01-12Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko
brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
2013-01-10c++ IRGen. In trivial cases that object is going into staticFariborz Jahanian
storage and thus is implicitly zero-initialized, no need to do C++11 memory model. This patch unconditionally detects such condition and zeroinitializer's the variable. Patch has been commented on and OKed by Doug off-line. // rdar://12897704 llvm-svn: 172144
2013-01-03Don't assert/crash on reference variables in lambdas bound to aEli Friedman
static local variable from the parent scope. PR14773. llvm-svn: 171433
2013-01-02Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate toChandler Carruth
reflect the migration in r171366. Re-sort the #include lines to reflect the new paths. llvm-svn: 171369
2012-12-04Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth
uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
2012-10-12Make -mms-bitfields behave consistently.Eli Friedman
Patch by Jeremiah Zanin. llvm-svn: 165849
2012-10-11Add codegen support for __uuidof().Nico Weber
llvm-svn: 165710
2012-10-08Move TargetData to DataLayout.Micah Villmow
llvm-svn: 165395
2012-09-11Remove some redundancy from constant aggregate emission. No functionality ↵Richard Smith
change. llvm-svn: 163595
2012-09-05Changing of type checking order on InitListExprJin-Gu Kang
- UnionType is checked eariler than RecordType. llvm-svn: 163202
2012-08-31Change the representation of builtin functions in the ASTEli Friedman
(__builtin_* etc.) so that it isn't possible to take their address. Specifically, introduce a new type to represent a reference to a builtin function, and a new cast kind to convert it to a function pointer in the operand of a call. Fixes PR13195. llvm-svn: 162962
2012-07-04Remove get(V)BaseClassOffsetInBits, the CharUnit functions should be used ↵Benjamin Kramer
instead. No functionality change. llvm-svn: 159719
2012-06-23Support the tls_model attribute (PR9788)Hans Wennborg
This adds support for the tls_model attribute. This allows the user to choose a TLS model that is better than what LLVM would select by default. For example, a variable might be declared as: __thread int x __attribute__((tls_model("initial-exec"))); if it will not be used in a shared library that is dlopen'ed. This depends on LLVM r159077. llvm-svn: 159078
2012-06-06Revert Decl's iterators back to pointer value_type rather than reference ↵David Blaikie
value_type In addition, I've made the pointer and reference typedef 'void' rather than T* just so they can't get misused. I would've omitted them entirely but std::distance likes them to be there even if it doesn't use them. This rolls back r155808 and r155869. Review by Doug Gregor incorporating feedback from Chandler Carruth. llvm-svn: 158104
2012-04-30Remove the ref/value inconsistency in filter_decl_iterator.David Blaikie
filter_decl_iterator had a weird mismatch where both op* and op-> returned T* making it difficult to generalize this filtering behavior into a reusable library of any kind. This change errs on the side of value, making op-> return T* and op* return T&. (reviewed by Richard Smith) llvm-svn: 155808
2012-04-15PR12226: don't generate wrong code if a braced string literal is used toRichard Smith
initialize an array of unsigned char. Outside C++11 mode, this bug was benign, and just resulted in us emitting a constant which was double the required length, padded with 0s. In C++11, it resulted in us generating an array whose first element was something like i8 ptrtoint ([n x i8]* @str to i8). llvm-svn: 154756
2012-03-30Missing piece of r153720: make sure the vtable pointer is handled correctly.Eli Friedman
llvm-svn: 153721
2012-03-30ConstStructBuilder: fix offset math for base classes so it works correctly ↵Eli Friedman
in general. Found by inspection. llvm-svn: 153720
2012-03-09Make sure constant emission handles initializer lists with strings ↵Eli Friedman
correctly. Part of <rdar://problem/10957867>. llvm-svn: 152370
2012-03-02Reinstate r151879, r151880, reverted in r151922, along with a bugfix forRichard Smith
scalar emission of DeclRefExprs to const bools: emit scalar bools as i1, not as i8. In addition to the extra unit testing, this has successfully bootstrapped. llvm-svn: 151955
2012-02-25CodeGen support for global variables of type std::initializer_list<X>.Sebastian Redl
This emits a backing array with internal linkage and fills it with data, then has the initializer_list point at the array. Dynamic initialization and global destructors are correctly supported. What doesn't work is nested initializer_lists. I have no idea how to get them to work, either. However, these should be very rare, and so I'll just call it a known bug and declare generalized initializers DONE! llvm-svn: 151457
2012-02-23PR12067: When emitting an evaluated constant structure in C++11 mode, don'tRichard Smith
forget the vptrs. llvm-svn: 151245
2012-02-22Generate an AST for the conversion from a lambda closure type to aDouglas Gregor
block pointer that returns a block literal which captures (by copy) the lambda closure itself. Some aspects of the block literal are left unspecified, namely the capture variable (which doesn't actually exist) and the body (which will be filled in by IRgen because it can't be written as an AST). Because we're switching to this model, this patch also eliminates tracking the copy-initialization expression for the block capture of the conversion function, since that information is now embedded in the synthesized block literal. -1 side tables FTW. llvm-svn: 151131
2012-02-19Refuse to compile global std::initializer_lists instead of doing completely ↵Sebastian Redl
the wrong thing. llvm-svn: 150928
2012-02-15Split reinterpret_casts of member pointers out from CK_BitCast; thisJohn McCall
is general goodness because representations of member pointers are not always equivalent across member pointer types on all ABIs (even though this isn't really standard-endorsed). Take advantage of the new information to teach IR-generation how to do these reinterprets in constant initializers. Make sure this works when intermingled with hierarchy conversions (although this is not part of our motivating use case). Doing this in the constant-evaluator would probably have been better, but that would require a *lot* of extra structure in the representation of constant member pointers: you'd really have to track an arbitrary chain of hierarchy conversions and reinterpretations in order to get this right. Ultimately, this seems less complex. I also wasn't quite sure how to extend the constant evaluator to handle foldings that we don't actually want to treat as extended constant expressions. llvm-svn: 150551
2012-02-14Use a simpler (and more efficient) pattern to pad vectors.Benjamin Kramer
llvm-svn: 150475
2012-02-13Deal with a horrible C++11 special case. If a non-literal type has a constexprRichard Smith
constructor, and that constructor is used to initialize an object of static storage duration such that all members and bases are initialized by constant expressions, constant initialization is performed. In this case, the object can still have a non-trivial destructor, and if it does, we must emit a dynamic initializer which performs no initialization and instead simply registers that destructor. llvm-svn: 150419