summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/designated-initializers.c
Commit message (Collapse)AuthorAgeFilesLines
* Implementing C99 partial re-initialization behavior (DR-253)Yunzhong Gao2015-06-101-7/+17
| | | | | | | | | | | | | | | | | | | | | | | | | Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446
* Gracefully (and correctly) handle init of multiple union membersMatthew Curtis2013-10-031-1/+49
| | | | | | | | | | | | | | | We now emit warnings when doing so and code generation is consistent with GCC. Note that the C99 spec is unclear as to the precise behavior. See also ... Bug: http://llvm.org/bugs/show_bug.cgi?id=16644 and cfe-dev discussion: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-September/031918.html llvm-svn: 191890
* Tweak r183791 so we don't print a note without a source location.Eli Friedman2013-06-111-0/+16
| | | | llvm-svn: 183803
* This patch fixes multiple issues in clang's designated init builder andDouglas Gregor2010-10-081-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | completes support for C1X anonymous struct/union init features: * Indexed anonymous member initializers should not be expanded. Doing so makes little sense and would cause unresolvable semantic ambiguity in valid code (regression introduced by r69153). * Subobject initialization of (possibly nested) anonymous members are now referred to with paths relative to the naming record context, eliminating the synthesis of incorrect implicit InitListExprs that caused CodeGen to assert. * Field lookup was missing a null check in IdentifierInfo comparison which caused lookup for a known (already resolved) field to match the first unnamed data member it encountered leading to silent miscompilation. * Subobject paths are no longer built using the general purpose Sema::BuildAnonymousStructUnionMemberPath(). If any corner cases crop up, we will now assert earlier in Sema instead of passing invalid InitListExprs through to CodeGen. Fixes PR6955, from Alp Toker! llvm-svn: 116098
* When filling in value initializations within an initializer list, beDouglas Gregor2009-12-221-0/+17
| | | | | | | sure to fill in the initialized member of a union when a member was explicitly designated. Fixes PR5843. llvm-svn: 91858
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* Remove the -arch option from clang-cc: for all practical purposes, it's Eli Friedman2009-05-191-1/+1
| | | | | | redundant with -triple. llvm-svn: 72108
* fix PR4073 by making designated initializer checking code useChris Lattner2009-04-251-0/+11
| | | | | | | | | | | | | | VerifyIntegerConstantExpression instead of isIntegerConstantExpr. This makes it ext-warn but tolerate things that fold to a constant but that are not valid i-c-e's. There must be a bug in the i-c-e computation though, because it doesn't catch this case even with pedantic. This also switches the later code to use EvaluateAsInt which is simpler and handles everything that evaluate does. llvm-svn: 70081
* Implement support for designated initializers that refer to members ofDouglas Gregor2009-04-151-0/+34
| | | | | | anonymous structs or unions. Fixes PR3778. llvm-svn: 69153
* Make our diagnostics about the obsolete GNU designated-initializerDouglas Gregor2009-03-281-1/+2
| | | | | | | syntax into extension warnings, and provide code-modification hints showing how to fix the problem. llvm-svn: 67885
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Downgrade the "excess elements in initializer" errors to warnings *inDouglas Gregor2009-02-181-1/+1
| | | | | | C*. They're required errors in C++. llvm-svn: 64964
* Fix a bug with designated initializers where we were stepping out of aDouglas Gregor2009-02-121-0/+14
| | | | | | | | | union subobject initialization before checking whether the next initiailizer was actually a designated initializer. This led to spurious "excess elements in union initializer" errors. Thanks to rdivacky for reporting the bug! llvm-svn: 64392
* When handling "the rest" of a designated array subobject, maybe sureDouglas Gregor2009-02-091-0/+21
| | | | | | | | to tell it that it wasn't (directly) designated. This way, we unwind back to the explicit initializer list properly rather than getting stuck in the wrong subobject. Fixes llvm.org/PR3519 llvm-svn: 64155
* Make CodeGen produce an error if we come across a non-constant initializer ↵Douglas Gregor2009-01-291-5/+4
| | | | | | list that involves the GNU array-range designator extension llvm-svn: 63327
* Add another devilish testcase for designated initializersDouglas Gregor2009-01-291-1/+6
| | | | llvm-svn: 63262
* Eliminate infinite looping in a wacky case with designated initializers. ↵Douglas Gregor2009-01-291-1/+9
| | | | | | Simplifies (somewhat) the actually checking of the initializer expression following the designators llvm-svn: 63257
* Improvements to code-generation and semantic analysis of designatedDouglas Gregor2009-01-281-5/+5
| | | | | | | | | | | | initializers. - We now initialize unions properly when a member other than the first is named by a designated initializer. - We now provide proper semantic analysis and code generation for GNU array-range designators *except* that side effects will occur more than once. We warn about this. llvm-svn: 63253
* Code generation support for C99 designated initializers.Douglas Gregor2009-01-281-4/+26
| | | | | | | | | | | | | | | | | | | | The approach I've taken in this patch is relatively straightforward, although the code itself is non-trivial. Essentially, as we process an initializer list we build up a fully-explicit representation of the initializer list, where each of the subobject initializations occurs in order. Designators serve to "fill in" subobject initializations in a non-linear way. The fully-explicit representation makes initializer lists (both with and without designators) easy to grok for codegen and later semantic analyses. We keep the syntactic form of the initializer list linked into the AST for those clients interested in exactly what the user wrote. Known limitations: - Designating a member of a union that isn't the first member may result in bogus initialization (we warn about this) - GNU array-range designators are not supported (we warn about this) llvm-svn: 63242
* More APSInt appeasementDouglas Gregor2009-01-231-1/+1
| | | | llvm-svn: 62884
* Hopefully the last of the APSInt signedness issues with initializers. Fixes ↵Douglas Gregor2009-01-231-1/+2
| | | | | | PR clang/3378 llvm-svn: 62876
* Make sure all of the isUnsigned flags line up when comparing initializer ↵Douglas Gregor2009-01-231-0/+1
| | | | | | values, to really really fix PR clang/3377 llvm-svn: 62858
* Properly manage the bit-widths of APInts/APSInts in array initialization.Douglas Gregor2009-01-231-0/+3
| | | | | | Fixes PR clang/3377 llvm-svn: 62851
* Reimplement the handling of the "current object" in designatorDouglas Gregor2009-01-221-1/+37
| | | | | | | | | | | initializers, so that we are within the appropriate subobject after we've processed a multi-designator designation. We're matching GCC and EDG's behavior on all examples I've found thus far. *Huge* thanks to Eli Friedman for pointing out my fundamental misunderstanding of "current object" in the C99 spec. llvm-svn: 62812
* Initial implementation of semantic analysis and ASTs for C99Douglas Gregor2009-01-221-0/+78
designated initializers. This implementation should cover all of the constraints in C99 6.7.8, including long, complex designations and computing the size of incomplete array types initialized with a designated initializer. Please see the new test-case and holler if you find cases where this doesn't work. There are still some wrinkles with GNU's anonymous structs and anonymous unions (it isn't clear how these should work; we'll just follow GCC's lead) and with designated initializers for the members of a union. I'll tackle those very soon. CodeGen is still nonexistent, and there's some leftover code in the parser's representation of designators that I'll also need to clean up. llvm-svn: 62737
OpenPOWER on IntegriCloud