Commit Graph

775 Commits

Author SHA1 Message Date
Douglas Gregor d5576dee1c Closed out a few radars that were addressed by designated initializers
llvm-svn: 63398
2009-01-30 17:42:28 +00:00
Douglas Gregor bf7207a11f Make CodeGen produce an error if we come across a non-constant initializer list that involves the GNU array-range designator extension
llvm-svn: 63327
2009-01-29 19:42:23 +00:00
Douglas Gregor 35a52fabf4 Add another devilish testcase for designated initializers
llvm-svn: 63262
2009-01-29 01:10:11 +00:00
Douglas Gregor f6d2752f12 Eliminate infinite looping in a wacky case with designated initializers. Simplifies (somewhat) the actually checking of the initializer expression following the designators
llvm-svn: 63257
2009-01-29 00:39:20 +00:00
Douglas Gregor 17bd094a6b Improvements to code-generation and semantic analysis of designated
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
2009-01-28 23:36:17 +00:00
Douglas Gregor 347f7eabb9 Code generation support for C99 designated initializers.
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
2009-01-28 21:54:33 +00:00
Daniel Dunbar 804c0441c2 Handle complex types in ASTContext::mergeTypes
llvm-svn: 63238
2009-01-28 21:22:12 +00:00
Nuno Lopes b81d94ff58 add test for PR2502, which was already fixed some time ago
llvm-svn: 63160
2009-01-28 00:44:33 +00:00
Anders Carlsson 570c357ded If an input constraint refers to an output constraint, it should have the same constraint info as the output constraint. Fixes PR3417
llvm-svn: 63127
2009-01-27 20:38:24 +00:00
Eli Friedman 8b7c52658b Fix for PR2100: merge types for variables.
llvm-svn: 62947
2009-01-24 23:49:55 +00:00
Eli Friedman 588395702f Correct test; sorry for any inconvenience.
llvm-svn: 62946
2009-01-24 23:44:26 +00:00
Eli Friedman 52cc016f21 PR3062: statement expressions should be illegal at file scope. I don't
think this has any significant effects at the moment, but it could 
matter if we start constant-folding statement expressions like gcc does.

llvm-svn: 62943
2009-01-24 23:09:00 +00:00
Chris Lattner 5eca6ada3a Implement C99 6.5.3.4p1, rejecting sizeof(bitfield)
llvm-svn: 62936
2009-01-24 21:29:22 +00:00
Chris Lattner 8dff017695 Fix PR3386 by handling GCC's rules for alignof, which are substantially
different than those for sizeof.  Reject alignof(bitfield) like gcc does.

llvm-svn: 62928
2009-01-24 20:17:12 +00:00
Daniel Dunbar 134a02586e Fix invalid evaluation of _Complex float (real & imaginary parts had
mismatched semantics).
 - Enforce this in APValue.

llvm-svn: 62924
2009-01-24 19:08:01 +00:00
Anders Carlsson a0b892113a Handle the 'e' constraint. Fixes PR3385
llvm-svn: 62923
2009-01-24 18:03:09 +00:00
Anders Carlsson b66a312f93 Ignore parens when determining if an expr is a string literal. Fixes PR3382.
llvm-svn: 62922
2009-01-24 17:47:50 +00:00
Douglas Gregor 7a95b08fce More APSInt appeasement
llvm-svn: 62884
2009-01-23 22:22:29 +00:00
Douglas Gregor 51650d380b Hopefully the last of the APSInt signedness issues with initializers. Fixes PR clang/3378
llvm-svn: 62876
2009-01-23 21:04:18 +00:00
Douglas Gregor 5da47ad57b Allow subtraction of function pointer types in C, as a GNU extension. Fixes rdar://problem/6520707
llvm-svn: 62859
2009-01-23 19:03:35 +00:00
Douglas Gregor 583cf0ac57 Make sure all of the isUnsigned flags line up when comparing initializer values, to really really fix PR clang/3377
llvm-svn: 62858
2009-01-23 18:58:42 +00:00
Douglas Gregor 033d1257ca Properly manage the bit-widths of APInts/APSInts in array initialization.
Fixes PR clang/3377

llvm-svn: 62851
2009-01-23 16:54:12 +00:00
Douglas Gregor 9aa8904a46 Handle any undeclared parameters in a K&R-style function with a
special action, inside function prototype scope. This avoids confusion
when we try to inject these parameters into the scope of the function
body before the function itself has been added to the surrounding
scope. Fixes <rdar://problem/6097326>.

llvm-svn: 62849
2009-01-23 16:23:13 +00:00
Douglas Gregor f6cd928bf4 Support arithmetic on pointer-to-function types as a GNU
extension. Addresses clang PR/3371.

llvm-svn: 62823
2009-01-23 00:36:41 +00:00
Douglas Gregor d7fb85e8ad Reimplement the handling of the "current object" in designator
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
2009-01-22 23:26:18 +00:00
Douglas Gregor e4a0bb7a20 Initial implementation of semantic analysis and ASTs for C99
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
2009-01-22 00:58:24 +00:00
Anders Carlsson dc6ceca4ba Fix an inline asm sema bug that I introduced.
llvm-svn: 62666
2009-01-21 06:27:20 +00:00
Anders Carlsson 224fca8982 Improvements to Sema of asm statements. Fixes <rdar://problem/6156893>
llvm-svn: 62609
2009-01-20 20:49:22 +00:00
Eli Friedman 08c5dabf1b Fix for PR3350: add special-casing for "references" to va_lists in
builtins.

Also, a minor tweak to va_copy for consistency.

llvm-svn: 62574
2009-01-20 07:46:22 +00:00
Douglas Gregor dd430f7ec9 Centralize error reporting of improper uses of incomplete types in the
new DiagnoseIncompleteType. It provides additional information about
struct/class/union/enum types when possible, either by pointing to the
forward declaration of that type or by pointing to the definition (if
we're in the process of defining that type). 
Fixes <rdar://problem/6500531>.

llvm-svn: 62521
2009-01-19 19:26:10 +00:00
Anders Carlsson a79203be85 Add sema support for symbolic names in inline asm statements.
llvm-svn: 62441
2009-01-18 01:56:57 +00:00
Nate Begeman bb70bf6dbb Update support for vector component access on ExtVectors.
llvm-svn: 62440
2009-01-18 01:47:54 +00:00
Douglas Gregor 051d8fd809 Warn about typedefs of enums without any declarator name. Fixes rdar://problem/6503878
llvm-svn: 62397
2009-01-17 02:55:50 +00:00
Douglas Gregor dee1be8e95 Teach DeclContext how to find the primary declaration for any TagDecl
even when we are still defining the TagDecl. This is required so that
qualified name lookup of a class name within its definition works (see
the new bits in test/SemaCXX/qualified-id-lookup.cpp).

As part of this, move the nested redefinition checking code into
ActOnTag. This gives us diagnostics earlier (when we try to perform
the nested redefinition, rather than when we try to complete the 2nd
definition) and removes some code duplication.

llvm-svn: 62386
2009-01-17 00:42:38 +00:00
Nuno Lopes 6be2939d5d add support for initializing static vars with a cast to union (gcc extension)
llvm-svn: 62261
2009-01-15 16:44:45 +00:00
Seo Sanghyeon 39a3ebf8f0 PR2746: Implement GCC cast to union extension
llvm-svn: 62255
2009-01-15 04:51:39 +00:00
Fariborz Jahanian f2a3120b77 Patch to keep clang honest that it does not yet support
explicit return type on block literals.

llvm-svn: 62240
2009-01-14 19:39:53 +00:00
Anders Carlsson bc12e92068 Use the unqualified type for GCCs struct/union cast extension
llvm-svn: 62170
2009-01-13 17:00:51 +00:00
Ted Kremenek 94a5f6f949 Fix test case (incomplete "expected-warning" line)
llvm-svn: 62119
2009-01-12 23:09:55 +00:00
Ted Kremenek 6dfeb55897 Patch by Roman Divacky:
Extend string-literal checking for printf() format string to handle conditional
ternary operators where both sides are literals.

This fixes PR 3319: http://llvm.org/bugs/show_bug.cgi?id=3319

llvm-svn: 62117
2009-01-12 23:09:09 +00:00
Douglas Gregor c6f58fe266 Implement support for anonymous structs and unions in C. Both C and
C++ handle anonymous structs/unions in the same way. Addresses several
bugs:

  <rdar://problem/6259534>
  <rdar://problem/6481130>
  <rdar://problem/6483159>

The test case in PR clang/1750 now passes with -fsyntax-only, but
CodeGen for inline assembler still fails.

llvm-svn: 62112
2009-01-12 22:49:06 +00:00
Douglas Gregor 45a33ecce1 Properly set the scope of non-fields declared within a struct, union,
or enum to be outside that struct, union, or enum. Fixes several
regressions: 

  <rdar://problem/6487662>
  <rdar://problem/6487669>
  <rdar://problem/6487684>
  <rdar://problem/6487702>
  PR clang/3305
  PR clang/3312

There is still some work to do in Objective-C++, but this requires
that each of the Objective-C entities (interfaces, implementations,
etc.) to be introduced into the context stack with
PushDeclContext/PopDeclContext. This will be a separate fix, later.

llvm-svn: 62091
2009-01-12 18:45:55 +00:00
Chris Lattner 5cdc94d282 testcase that works now with r62061
llvm-svn: 62062
2009-01-12 00:08:58 +00:00
Douglas Gregor 658b9550bb When we see a reference to a struct, class, or union like "struct X"
that is neither a definition nor a forward declaration and where X has
not yet been declared as a tag, introduce a declaration
into the appropriate scope (which is likely *not* to be the current
scope). The rules for the placement of the declaration differ slightly
in C and C++, so we implement both and test the various corner
cases. This implementation isn't 100% correct due to some lingering
issues with the function prototype scope (for a function parameter
list) not being the same scope as the scope of the function
definition. Testcase is FIXME'd; this probably isn't an important issue.

Addresses <rdar://problem/6484805>.

llvm-svn: 62014
2009-01-09 22:42:13 +00:00
Douglas Gregor 020713e308 Replace DeclContext's vector of ScopedDecl pointers with a linked list
of ScopedDecls (using the new ScopedDecl::NextDeclInScope
pointer). Performance-wise:

  - It's a net win in memory utilization, since DeclContext is now one
    pointer smaller than it used to be (std::vectors are typically 3
    pointers; we now use 2 pointers) and 
  - Parsing Cocoa.h with -fsyntax-only (with a Release-Asserts Clang)
    is about 1.9% faster than before, most likely because we no longer
    have the memory allocations and copying associated with the
    std::vector.

I'll re-enable serialization of DeclContexts once I've sorted out the
NextDeclarator/NextDeclInScope question.

llvm-svn: 62001
2009-01-09 19:42:16 +00:00
Ted Kremenek 339153d3be Re-enable PTH testing for Cocoa.h and Carbon.h (and include testing for Objective-C++).
llvm-svn: 61965
2009-01-09 00:41:48 +00:00
Ted Kremenek cb5a95f3a4 Temporarily revert r61956 and r61957 (PTH tests failing).
llvm-svn: 61960
2009-01-09 00:27:29 +00:00
Ted Kremenek 510b4da49d Enhance -fsyntax-only test of Carbon.h to also include testing for PTH.
llvm-svn: 61958
2009-01-08 23:42:56 +00:00
Douglas Gregor 82ac25e4a7 Unify the code for defining tags in C and C++, so that we always
introduce a Scope for the body of a tag. This reduces the number of
semantic differences between C and C++ structs and unions, and will
help with other features (e.g., anonymous unions) in C. Some important
points:

  - Fields are now in the "member" namespace (IDNS_Member), to keep
    them separate from tags and ordinary names in C. See the new test
    in Sema/member-reference.c for an example of why this matters. In
    C++, ordinary and member name lookup will find members in both the
    ordinary and member namespace, so the difference between
    IDNS_Member and IDNS_Ordinary is erased by Sema::LookupDecl (but
    only in C++!). 
  - We always introduce a Scope and push a DeclContext when we're
    defining a tag, in both C and C++. Previously, we had different
    actions and different Scope/CurContext behavior for enums, C
    structs/unions, and C++ structs/unions/classes. Now, it's one pair
    of actions. (Yay!)

There's still some fuzziness in the handling of struct/union/enum
definitions within other struct/union/enum definitions in C. We'll
need to do some more cleanup to eliminate some reliance on CurContext
before we can solve this issue for real. What we want is for something
like this:

  struct X {
    struct T { int x; } t;
  };

to introduce T into translation unit scope (placing it at the
appropriate point in the IdentifierResolver chain, too), but it should
still have struct X as its lexical declaration
context. PushOnScopeChains isn't smart enough to do that yet, though,
so there's a FIXME test in nested-redef.c

llvm-svn: 61940
2009-01-08 20:45:30 +00:00
Sebastian Redl a2b5e31cb1 Diagnose declarations that don't declare anything, and fix PR3020.
Examples:
int;
typedef int;

llvm-svn: 61454
2008-12-28 15:28:59 +00:00
Sebastian Redl 85cd7bac29 Fix filename typo.
llvm-svn: 61453
2008-12-28 14:19:27 +00:00
Anton Korobeynikov b46e3a8d3b Complete the test after adding handling of merged attributes on decls.
llvm-svn: 61438
2008-12-26 00:52:17 +00:00
Anton Korobeynikov d72f47aa05 Add full dllimport / dllexport support: both sema checks and codegen.
Patch by Ilya Okonsky

llvm-svn: 61437
2008-12-26 00:52:02 +00:00
Anton Korobeynikov 3112c877c1 Testcase for stdcall/fastcall sema checks.
Patch by Ilya Okonsky!

llvm-svn: 61436
2008-12-26 00:51:21 +00:00
Chris Lattner b6ec4e75ad Clean up the C89/C++ warnings about C99 array features to not
emit duplicate diags (some in parser and some in sema) and to
warn about use of typequals in array sizes.  This implements 
PR2759.

llvm-svn: 61197
2008-12-18 06:50:14 +00:00
Chris Lattner 27e5beff70 Merge function-return.c into function.c
Fix PR2790 by making a warning an EXTWARN instead of EXTENSION.
Add a new EXTENSION warning for "return (some void expression);"

llvm-svn: 61187
2008-12-18 02:01:17 +00:00
Chris Lattner 3d72297909 diagnose C99 6.9.1p5, C arguments in definitions that are lacking
a name.  This implements PR3208.

llvm-svn: 61127
2008-12-17 07:32:46 +00:00
Eli Friedman bb2b3be9e1 Make error handling for va_start a bit more robust. Fixes PR3213.
llvm-svn: 61055
2008-12-15 22:05:35 +00:00
Douglas Gregor c811d8f055 Create new EnumDecl nodes for redeclarations of enums, linking them
together in the same way that we link RecordDecl/CXXRecordDecl nodes. 

Unify ActOnTag and ActOnTagStruct.

Fixes PR clang/2753.

llvm-svn: 61034
2008-12-15 16:32:14 +00:00
Chris Lattner 04397358ec Implement the final (hopefully) wrinkle to i-c-e + builtin_constant_p
processing: it allows arbitrary foldable constants as the operand of ?: when
builtin_constant_p is the condition.

llvm-svn: 60954
2008-12-12 18:00:51 +00:00
Chris Lattner 4bf85ffe83 merge these testcases into one file.
llvm-svn: 60936
2008-12-12 07:01:24 +00:00
Chris Lattner 85b25bc344 implement rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
llvm-svn: 60934
2008-12-12 06:55:44 +00:00
Chris Lattner dca17ceb19 add expected diag
llvm-svn: 60927
2008-12-12 05:59:56 +00:00
Chris Lattner 053441f39d Fix rdar://6095061 - gcc allows __builtin_choose_expr as an lvalue
llvm-svn: 60924
2008-12-12 05:35:08 +00:00
Chris Lattner 54139445ba Testcase for something that already works. Clang agrees with Comeau,
and this makes sense.  likely a gcc bug that it doesn't diagnose the bad
restrict.

llvm-svn: 60923
2008-12-12 05:25:55 +00:00
Chris Lattner f45c5ecb3b fix rdar://6097892 - gcc incompat: clang rejects __func__, __FUNCTION__, and __PRETTY_FUNCTION__ outside func
Yeah, this is "useful".

llvm-svn: 60921
2008-12-12 05:05:20 +00:00
Chris Lattner 81ed6805db Implement rdar://6138816 - [sema] named bitfields cannot have 0 width
llvm-svn: 60920
2008-12-12 04:56:04 +00:00
Chris Lattner ece9ae718b add annotation
llvm-svn: 60907
2008-12-11 23:11:52 +00:00
Anders Carlsson 591b2224cb Add another complex promotion test.
llvm-svn: 60863
2008-12-10 23:57:51 +00:00
Anders Carlsson b05961c700 Make sure to promote expressions of the form (floating point + complex integer) correctly, to (complex floating point + complex floating point)
llvm-svn: 60862
2008-12-10 23:30:05 +00:00
Steve Naroff 68e167df8e Fix <rdar://problem/6418623> Bogus block type compatibility warning.
llvm-svn: 60842
2008-12-10 17:49:55 +00:00
Eli Friedman 14fb8587be Workaround for PR3173. The fix is correct in the sense that if the enum
code were working correctly, it would be a no-op, but it's not really a 
proper fix.  That said, I don't really want to touch the enum code at 
the moment because I don't understand it very well, and this seems to 
be a relatively visible regression.

llvm-svn: 60680
2008-12-08 02:21:03 +00:00
Chris Lattner b3582b939e a minor grammar fix
llvm-svn: 60646
2008-12-07 00:59:53 +00:00
Anders Carlsson 0d8f0ba6ed Improve VLA diagnostics/sema checking. Fixes PR2361 and PR2352.
llvm-svn: 60638
2008-12-07 00:20:55 +00:00
Anders Carlsson 3bb1ffca94 Simplify test.
llvm-svn: 60631
2008-12-06 22:27:22 +00:00
Anders Carlsson 5df391e5c7 Add diagnostics for bitfields.
llvm-svn: 60628
2008-12-06 20:33:04 +00:00
Anders Carlsson 1aa679227b Use VerifyIntegerConstantExpression instead of isIntegerConstantExpr. Fixes PR2963
llvm-svn: 60591
2008-12-05 16:33:57 +00:00
Anders Carlsson 1e495d9860 Make Sema::CheckForConstantInitializer use Expr::Evaluate. This fixes PR3130.
llvm-svn: 60580
2008-12-05 05:09:56 +00:00
Chris Lattner 79413956d4 change getCurFunctionDecl to skip through Block contexts to find
the containing block.  Introduce a new getCurFunctionOrMethodDecl
method to check to see if we're in a function or objc method.
Minor cleanups to other related places.  This fixes rdar://6405429.

llvm-svn: 60564
2008-12-04 23:50:19 +00:00
Chris Lattner 2ca529ce61 instead of forcing blocks on by default, make them default to off, but let
specific targets default them to on.  Default blocks to on on 10.6 and later.
Add a -fblocks option that allows the user to override the target's default.
Use -fblocks in the various testcases that use blocks.

llvm-svn: 60563
2008-12-04 23:20:07 +00:00
Sebastian Redl fb5df7235a int-arith-convert.c makes assumptions about integer sizes, so force a specific architecture
llvm-svn: 60420
2008-12-02 16:34:01 +00:00
Anders Carlsson 0309d904f7 Fix test. (0 && (a(),1)) is a valid I-C-E according to C99.
llvm-svn: 60331
2008-12-01 06:27:38 +00:00
Anders Carlsson 1dbffc6e36 Add Sema::isNullPointerConstant which extwarns if necessary. Use it in Sema::CheckConditionalOperands.
llvm-svn: 60319
2008-12-01 02:17:22 +00:00
Anders Carlsson f7fba46331 Use VerifyIntegerConstantExpression for case values.
llvm-svn: 60317
2008-12-01 02:13:02 +00:00
Nuno Lopes 8c6fbc04ee add missing RUN lines
llvm-svn: 60107
2008-11-26 15:50:12 +00:00
Chris Lattner 1e5665e6be Change a whole lot of diagnostics to take QualType's directly
instead of converting them to strings first.  This also fixes a
bunch of minor inconsistencies in the diagnostics emitted by clang
and adds a bunch of FIXME's to DiagnosticKinds.def.

llvm-svn: 59948
2008-11-24 06:25:27 +00:00
Anders Carlsson a42ee44aab The address of a variable is only constant if the variable has global storage.
llvm-svn: 59939
2008-11-24 04:41:22 +00:00
Anders Carlsson 4c76e93507 Fix bug in the constant evaluator. Fixes PR3115.
llvm-svn: 59938
2008-11-24 04:21:33 +00:00
Chris Lattner 4fc69799f5 Rewrite FindDiagnostics to be more strict about the formatting of the
expected-foo strings.  Now the only allowed characters between 
expected-error and {{  is whitespace.

llvm-svn: 59925
2008-11-24 01:28:17 +00:00
Chris Lattner f3ab014308 clean up -verify mode output. If the expected-error string is
mangled, report it using the diagnostics machinery instead of printf.

llvm-svn: 59924
2008-11-23 23:38:26 +00:00
Chris Lattner 03c4041cb5 make the 'to match this' diagnostic a note.
llvm-svn: 59921
2008-11-23 23:17:07 +00:00
Chris Lattner 0369c57ac6 Make all the 'redefinition' diagnostics more consistent, and make the
"previously defined here" diagnostics all notes.

llvm-svn: 59920
2008-11-23 23:12:31 +00:00
Sebastian Redl 632ab20e1e Fix test cases broken by quote normalization in diagnostics.
llvm-svn: 59888
2008-11-22 22:39:41 +00:00
Anders Carlsson 475f4bce36 Case values must be evaluated
llvm-svn: 59884
2008-11-22 21:50:49 +00:00
Anders Carlsson 59689ed764 Use Expr::Evaluate for case statements. Fixes PR2525
llvm-svn: 59881
2008-11-22 21:04:56 +00:00
Chris Lattner 8cd9b96ee1 add a silly testcase
llvm-svn: 59877
2008-11-22 19:57:03 +00:00
Chris Lattner cedef8d111 merge some simple call diagnostics.
llvm-svn: 59831
2008-11-21 18:44:24 +00:00
Chris Lattner 40bb0c83d4 print a type in a diagnostic.
llvm-svn: 59829
2008-11-21 18:27:34 +00:00
Chris Lattner 66c8bebe81 remove expected-error from #if 0 section of code.
llvm-svn: 59772
2008-11-21 01:05:35 +00:00
Chris Lattner 4d7c58f0eb disable expected-errors in #if parts of the test.
llvm-svn: 59771
2008-11-21 01:05:04 +00:00
Chris Lattner 3b05413e9d Switch several more Sema Diag methods over. This simplifies the
__builtin_prefetch code to only emit one diagnostic per builtin_prefetch.
While this has nothing to do with the rest of the patch, the code seemed
like overkill when I was updating it.

llvm-svn: 59588
2008-11-19 05:08:23 +00:00
Chris Lattner 9b3bbe9db7 Implement rdar://6319320: give a good diagnostic for cases where people
are trying to use the old GCC "casts as lvalue" extension.  We don't and
will hopefully never support this.

llvm-svn: 59460
2008-11-17 19:51:54 +00:00
Chris Lattner 962b4eed9d Fix PR3075, __builtin_stdarg_start being misprototyped. This affects netbsd headers.
llvm-svn: 59419
2008-11-16 18:43:46 +00:00
Eli Friedman 5a332ea01f Fix for crash issues with comma operators with a void first operand, and
some more bullet-proofing/enhancements for tryEvaluate.  This shouldn't 
cause any behavior changes except for handling cases where we were 
crashing before and being able to evaluate a few more cases in tryEvaluate.
 
This should settle the minor mess surrounding r59196.

llvm-svn: 59224
2008-11-13 06:09:17 +00:00
Eli Friedman 8553a98b8e Backout of r59196, plus a new ICE test. Sorry if this is a
little rude; I figure it's cleaner to just back this out now so 
it doesn't get forgotten or mixed up with other checkins.

The modification to isICE is simply wrong; I've added a test that the 
change to isICE breaks.

I'm pretty sure the modification to tryEvaluate is also wrong.  
At the very least, there's some serious miscommunication going on here, 
as this is going in exactly the opposite direction of r59105.  My 
understanding is that tryEvaluate is not supposed to care about side 
effects.  That said, a lot of the clients to tryEvaluate are 
expecting it to enforce a no-side-effects policy, so we probably need 
another method that provides that guarantee.

llvm-svn: 59212
2008-11-13 02:13:11 +00:00
Daniel Dunbar c7ec5fcf24 Fix bug in constant evaluation exposed by 176.gcc.
- Evaluation of , operator used bogus assumption that LHS could be
   evaluated as an integral expression even though its type is
   unspecified.

This change is making isICE very permissive of the LHS in non-evaluated 
contexts because it is not clear what predicate we would use to reject 
code here. The standard didn't offer me any guidance; opinions?

llvm-svn: 59196
2008-11-13 00:03:19 +00:00
Chris Lattner 6515bcc3c6 Fix a FIXME by improving a diagnostic, add a testcase for PR3048
llvm-svn: 59167
2008-11-12 21:25:45 +00:00
Sebastian Redl 15b7160a17 64-bit test fixes.
llvm-svn: 59165
2008-11-12 21:19:11 +00:00
Eli Friedman 9a156e5c1e Some additions to tryEvaluate I've had sitting around for a while.
This pushes it a lot closer to being able to deal with most of the stuff 
CodeGen's constant expression evaluator knows how to deal with.  This 
also fixes PR3003.

The test could possibly use some improvement, but this'll work for now.  
Test 6 is inspired by PR3003; the other tests are mostly just designed
to exercise the new code.  The reason for the funny structure of the 
tests is that type fixing for arrays inside of structs is the only place 
in Sema that calls tryEvaluate, at least for the moment.

llvm-svn: 59125
2008-11-12 09:44:48 +00:00
Chris Lattner 8c5dd730ce Fix PR3031 by silencing follow-on errors in invalid declarations.
llvm-svn: 59027
2008-11-11 06:13:16 +00:00
Argyrios Kyrtzidis 6709e7d4cc Fix crash caused by this:
void f() {
   int +; // crash here
}

llvm-svn: 58846
2008-11-07 13:01:22 +00:00
Chris Lattner 8cc7be369c Fix PR3001: if we have an error parsing an initializer, make sure to remove
the designator corresponding to it, otherwise Sema and later parsing will
get confused.

llvm-svn: 58603
2008-11-03 09:28:22 +00:00
Sebastian Redl 5f74e09f47 Fix missing %s in run string causing hang during tests.
llvm-svn: 58394
2008-10-29 19:29:09 +00:00
Ted Kremenek 82c1cc3d52 Fix crash reported in PR2923 where a function declared using typeof(another_function) would have FunctionDecl::getNumParams() return the number of parameters in the original function type and not the number of parameters in the actual FunctionDecl.
llvm-svn: 58392
2008-10-29 18:41:34 +00:00
Daniel Dunbar d7be95d60a PR2919: __builtin_types_compatible_p strips CRV qualifiers.
llvm-svn: 58079
2008-10-24 08:07:57 +00:00
Chris Lattner 2a9d9897b7 Fix rdar://6257721 by tightening up the block "snapshot" check, and
move it to its own predicate to make it more clear.

llvm-svn: 57796
2008-10-20 05:16:36 +00:00
Daniel Dunbar 70e3ebafdb Improve attribute parsing & tests.
- Support noreturn on function-typed variables.

 - Extend isFunctionOrMethod to return true for K&R functions and
   provide hasFunctionProto to check if a decl has information about
   its arguments. This code needs some serious cleaning, but works.

 - Add/improve test cases for noreturn and unused.

llvm-svn: 57778
2008-10-19 02:04:16 +00:00
Daniel Dunbar 472175e545 Exercise #pragma pack(pop, <width>) in test case.
llvm-svn: 57683
2008-10-17 16:05:47 +00:00
Daniel Dunbar c3d79cf6b3 Teach tryEvaluate that fabs, copysign, and unary +/- are constants for
floats.
 - With testcase, which also has some other things GCC folds but we
   don't commented out in it.

llvm-svn: 57624
2008-10-16 03:51:50 +00:00
Daniel Dunbar 4290d46bd4 Implement #pragma pack use in structure packing. The general approach
is to encode the state of the #pragma pack stack as an attribute when
the structure is declared. 

 - Extend PackedAttr to take an alignment (in bits), and reuse for
   both __attribute__((packed)) (which takes no argument, instead
   packing tightly (to "minimize the memory required") and for #pragma
   pack (which allows specification of the maximum alignment in
   bytes). __attribute__((packed)) is just encoded as Alignment=1.

   This conflates two related but different mechanisms, but it didn't
   seem worth another attribute.

 - I have attempted to follow the MSVC semantics as opposed to the gcc
   ones, since if I understand correctly #pragma pack originated with
   MSVC. The semantics are generally equivalent except when the stack
   is altered during the definition of a structure; its not clear if
   anyone does this in practice. See testcase if curious.

llvm-svn: 57623
2008-10-16 02:34:03 +00:00
Daniel Dunbar eee51d125f Fix typo in testcase.
llvm-svn: 57499
2008-10-14 16:46:03 +00:00
Chris Lattner 3211159cab add a testcase.
llvm-svn: 57479
2008-10-14 06:32:07 +00:00
Daniel Dunbar 5460374cd9 Add Sema implementation of #pragma pack stack.
- Follows the MSVC (original) implementation, including support of
   pack(show) (useful for testing).
 - Implements support for named pack records which gcc seems to
   ignore (or implements incorrectly).
 - Not currently wired to anything, only functionality change is the
   type checking of the pragma.

llvm-svn: 57476
2008-10-14 05:35:18 +00:00
Seo Sanghyeon c9e7c272da Tests for return statement checks
llvm-svn: 57341
2008-10-10 07:20:06 +00:00
Chris Lattner c43467526d "Enhance" CheckArithmeticConstantExpression to accept ?: with a constant
condition as a constant even if the unevaluated side is a not a constant.
We don't do this when extensions are off, and we emit a warning when this 
happens:

t.c:22:11: warning: expression is not a constant, but is accepted as one by GNU extensions
short t = __builtin_constant_p(5353) ? 42 : somefunc();
          ^                                 ~~~~~~~~~~

suggestions for improvement are welcome.  This is obviously horrible, but
is required for real-world code.

llvm-svn: 57153
2008-10-06 05:42:39 +00:00
Anders Carlsson c181b01681 Add parsing of the sentinel attribute. Still need to create the attribute.
llvm-svn: 57121
2008-10-05 18:05:59 +00:00
Argyrios Kyrtzidis 72d8149a1e Append the test runs with '&&'.
llvm-svn: 57085
2008-10-05 00:08:56 +00:00
Daniel Dunbar 325601a9e5 Merge postfix attributes on record decls.
llvm-svn: 57019
2008-10-03 17:33:35 +00:00
Daniel Dunbar dc2ab1740a Add Builtins.def attribute for "can be a constant expression".
- Enabled for builtins which are always constant expressions
   (__builtin_huge_val*, __builtin_inf*, __builtin_constant_p,
   __builtin_classify_type, __builtin___CFStringMakeConstantString).

Added Builtin::Context::isConstantExpr.
 - Currently overly simply interface which only works for builtins
   whose constantexprness does not depend on their arguments.

CallExpr::isBuiltinConstantExpr now takes an ASTContext argument.

llvm-svn: 56983
2008-10-02 23:30:31 +00:00
Daniel Dunbar dd9b2d16f9 Add support for format string checking of object-size checking
versions of sprintf and friends.
 - Added FIXME that this mechanism should be generalized.

llvm-svn: 56962
2008-10-02 18:44:07 +00:00
Steve Naroff d40a39626c Changed Sema::CheckForConstantInitializer to allow global block literals.
This commit also includes some name changes in the blocks rewriter (no functionality change).

llvm-svn: 56955
2008-10-02 17:12:56 +00:00
Chris Lattner 4a80a59b6e Fix va_arg handling to do argument decaying at the correct place. This
fixes problems handling references of va_list, which happens on x86_64.
This fixes PR2841 and rdar://6252231

llvm-svn: 56809
2008-09-29 22:28:25 +00:00
Steve Naroff 32d072ca45 Teach Sema::CheckAssignmentConstraints() to allow assignments between id and block pointer types (^{}).
llvm-svn: 56793
2008-09-29 18:10:17 +00:00
Steve Naroff 03fc762a02 Fix <rdar://problem/6251012> clang: Blocks are objects too.
llvm-svn: 56791
2008-09-29 16:51:41 +00:00
Steve Naroff 4831c74d40 Fix <rdar://problem/6252108> assigning to argument passed to block should not require __block.
llvm-svn: 56770
2008-09-28 14:02:55 +00:00
Chris Lattner 037379d767 Fix rdar://6252231 - cannot call vsnprintf with va_list on x86_64,
by decaying __builtin_va_list's type when forming builtins.  On
x86-64 (and other targets) __builtin_va_list is a typedef for
an array.

llvm-svn: 56768
2008-09-28 06:05:35 +00:00
Chris Lattner e9d291c038 Fix rdar://6251437, references to enum constant decls in a block
don't need a BlockDeclRefExpr.

llvm-svn: 56766
2008-09-28 05:30:26 +00:00
Steve Naroff e18f94c20d Fix <rdar://problem/6252216> compare block to NULL.
llvm-svn: 56764
2008-09-28 01:11:11 +00:00
Steve Naroff edec9ba58d Fix <rdar://problem/6252226> parser thinks block argument is undefined identifier in NSServices.m
llvm-svn: 56761
2008-09-28 00:13:36 +00:00
Ted Kremenek 68d2190226 Enter a new scope for a @try block.
llvm-svn: 56668
2008-09-26 17:32:47 +00:00
Steve Naroff ba756cb3fc Tweak Expr::isModifiableLvalue() and Expr::isLvalue() to better deal with BlockDeclRef exprs.
This fixes <rdar://problem/6248392> clang: Error when using address of stack variable inside block.

llvm-svn: 56652
2008-09-26 14:41:28 +00:00
Ted Kremenek a34ea3b9cf Have @finally introduce a new scope.
Fixes: <rdar://problem/6248119> @finally doesn't introduce a new scope

llvm-svn: 56629
2008-09-26 00:31:16 +00:00
Steve Naroff f17c232a9e Downgrade incompatible block pointer error to a warning (to be consistent with incompatible pointer warnings in general).
llvm-svn: 56595
2008-09-24 23:31:10 +00:00
Steve Naroff c60873ce44 Fix <rdar://problem/6243788> clang: Incorrect return statement for Blocks?
llvm-svn: 56590
2008-09-24 22:26:48 +00:00
Steve Naroff 3405a73ab8 Finish pushing blocks attribute through the clang attribute machinery.
Also added a couple simple tests from the "gcc.apple" test suite.

llvm-svn: 56309
2008-09-18 16:44:58 +00:00
Steve Naroff a5629376e8 Fix http://llvm.org/bugs/show_bug.cgi?id=2760.
llvm-svn: 56280
2008-09-17 14:05:40 +00:00
Steve Naroff 7a147c6a3c Remove support for BlockExprExpr. For example...
^(expression) or ^(int arg1, float arg2)(expression)
...is no longer supported. 
All block literals now require a compound statement.

llvm-svn: 56257
2008-09-16 23:11:46 +00:00
Steve Naroff 3b1e172d7e Sema::ActOnBlockReturnStmt(): Need to perform the UsualUnaryConversions on the return type.
Sema::CheckReturnStackAddr(): Make sure we skip over implicit casts.
Added some more test cases...

llvm-svn: 56254
2008-09-16 22:25:10 +00:00
Steve Naroff 2752a17a00 More semantic analysis for blocks...
llvm-svn: 56064
2008-09-10 19:17:48 +00:00
Steve Naroff 3ef15b5c2a Sema::ActOnIdentifierExpr(): Lookup block arguments.
llvm-svn: 56063
2008-09-10 18:33:00 +00:00
Steve Naroff 8de9c3affe More type checking for blocks. Still incomplete (will hopefully finish up this weekend).
llvm-svn: 55862
2008-09-05 22:11:13 +00:00
Daniel Dunbar 0ff4192f3a Set register storage class correctly for function parameters.
- PR2730

llvm-svn: 55739
2008-09-03 21:54:21 +00:00
Daniel Dunbar 20e5db77a3 Add two test cases for builtins (mostly related to object size
builtins).

llvm-svn: 55736
2008-09-03 21:17:21 +00:00
Nuno Lopes dd30e2c677 add the other test case for completeness and to avoid regressions in the future
llvm-svn: 55629
2008-09-02 10:10:14 +00:00
Eli Friedman de09ce03c4 Fix for PR2747: allow pointer->int casts with a null base; these are
offset-of-like expressions.

llvm-svn: 55627
2008-09-02 09:37:00 +00:00
Eli Friedman 7c9ba6a1e3 An extremely hacky version of transparent_union support; it isn't
anywhere near correct in terms of missing cases and missing 
diagnostics, but it's good enough to handle the uses in the 
Linux system headers, which are currently a constant pain for compiling 
applications on Linux.

llvm-svn: 55621
2008-09-02 05:19:23 +00:00
Eli Friedman e7175d83dc Make sure to take the unqualified versions of the canonical types for
type-checking pointer subtraction; if the canonical types aren't used,
the qualifiers won't always get stripped off correctly.

llvm-svn: 55620
2008-09-02 05:09:35 +00:00
Nuno Lopes 4e630967fc readd test as it passes correctly. nice, but weird
llvm-svn: 55615
2008-09-01 22:28:55 +00:00
Eli Friedman 4c55e2c4ed Backing out r55607 due to logic errors and test regression.
I'll try to come up with a correct fix for the testcase sometime soon.

llvm-svn: 55614
2008-09-01 22:08:17 +00:00
Ted Kremenek c4f6d90ba1 Tidy up sema processing of attribute "nonull":
- warn about nonnull being applied to functions with no pointer arguments
- continue processing argument list in the attribute when we encounter a non-pointer parameter being marked as nonnull
- when no argument list is specified, only mark pointers as nonnull.  This fixes PR 2732 and radar 6188814.

llvm-svn: 55610
2008-09-01 19:57:52 +00:00
Nuno Lopes 2c5208c59f fix one more this-is-not-a-constant error. test included
llvm-svn: 55609
2008-09-01 18:42:41 +00:00
Nuno Lopes feac637074 make CheckArithmeticConstantExpression() aware of &foo and pointers
llvm-svn: 55607
2008-09-01 14:47:06 +00:00
Daniel Dunbar 8c8616377d Fix isIntegerConstantExpr eval of __builtin_offsetof to return result
with correct width.
 - PR2728.

Also, fix PR2727 test case.

llvm-svn: 55493
2008-08-28 18:42:20 +00:00
Daniel Dunbar 3e1888e8bd Fix double-free error with sizeof applied to VLA types.
- PR2727.

Also, fix warning in CodeGenTypes for new BlockPointer type.

llvm-svn: 55479
2008-08-28 18:02:04 +00:00
Eli Friedman 0a2ba3f10b Fix for PR2720; be a little bit more permissive in initializers for
casting pointers to integers.

Eventually, we should check whether we can evaluate an expression 
using Expr::tryEvaluate, and this codepath should be tightened to only 
handle standard-compliant cases.

llvm-svn: 55331
2008-08-25 20:46:57 +00:00
Daniel Dunbar 8d57244601 Add test case for function-pointer-cast-of-global as constant
expression.

llvm-svn: 55323
2008-08-25 20:08:27 +00:00
Argyrios Kyrtzidis 3d0f51d703 Move the rest of the Sema C++ tests into the SemaCXX test directory.
llvm-svn: 55178
2008-08-22 15:43:49 +00:00
Chris Lattner ea71438a93 add a simple check to warn people who type "=+" when they probably meant
"+=".

llvm-svn: 55131
2008-08-21 18:04:13 +00:00
Eli Friedman 1be92d297a Fix a regression from my fix to PR2631. Fixes PR2692.
llvm-svn: 55083
2008-08-20 22:17:17 +00:00
Eli Friedman 5dd15a3c45 Fix test failure on Linux.
llvm-svn: 55032
2008-08-20 01:05:41 +00:00
Chris Lattner 5caafe598f add testcase we already handle.
llvm-svn: 54967
2008-08-19 00:58:40 +00:00
Daniel Dunbar aa64b7e0a8 Support initialization of incomplete array with zero size (as
extension).

llvm-svn: 54946
2008-08-18 20:28:46 +00:00
Argyrios Kyrtzidis 3014572ea2 Move the C++ Sema tests into a separate SemaCXX directory.
llvm-svn: 54853
2008-08-16 20:53:59 +00:00
Steve Naroff eaf5853004 InitListChecker::CheckListElementTypes(): Check for function types and issue an appropriate diagnostic.
llvm-svn: 54614
2008-08-10 16:05:48 +00:00
Steve Naroff 84e37356d6 Sema::CheckForFileScopedRedefinitions(): Make sure tentative decls of incomplete array types are completed (and diagnosed properly).
llvm-svn: 54612
2008-08-10 15:20:13 +00:00
Chris Lattner 28b4294ccf wrap some long diagnostics, make 'initializer is not a constant' diagnostic
a bit more clear (rdar://5646070)

llvm-svn: 54606
2008-08-10 01:58:45 +00:00
Eli Friedman a3b2f6f2af Make sure to count the struct elements correctly; here, we want the
member count.  The count returned by numStructUnionElements is the 
number of initializers that will be consumed, not the number of members 
to iterate through.  Fixes PR2534.

llvm-svn: 54601
2008-08-09 23:45:45 +00:00
Eli Friedman 121ba0c4d3 Fix for PR2631; make va_arg work correctly on x86-64.
llvm-svn: 54600
2008-08-09 23:32:40 +00:00
Chris Lattner 572100b648 Fix PR2400 by more graceful handling of invalid decls. Don't try to layout
an invalid struct decl.  Thanks to Martin Doucha for the 
isIncompleteArrayType part of this patch.

llvm-svn: 54592
2008-08-09 21:35:13 +00:00
Argyrios Kyrtzidis 40e9e4828f Implement support for the 'wchar_t' C++ type.
llvm-svn: 54585
2008-08-09 16:51:54 +00:00
Steve Naroff 239255d2a6 Fix Sema::MergeVarDecl() to better handle type compatibility. The previous code was trying to handle arrays specially (which didn't work for pointers to array). Removed local helper function areEquivalentArrayTypes(), replacing it's use with the more general ASTContext::typesAreCompatible() predicate.
Even though the test case this fixes is in "tentative-decls.c", this bug didn't have anything to do with our handling of tentative definitions (which is what I first expected). In any event, this is a tricky area of the spec.

llvm-svn: 54583
2008-08-09 16:04:40 +00:00
Steve Naroff 5bb8f2264b Fix issues with C "tentative" definitions.
- Move checking from MergeVarDecl->FinializeDeclaratorGroup. Since MergeVarDecl is called before the initializer is attacted, it can't be done there (this removes a long standing FIXME).
- Add Sema::isTentativeDefinition() and Sema::CheckForFileScopedRedefinitions().
- Remove FIXME's and touch-up test case.

Still some more work to do (forthcoming)...

llvm-svn: 54533
2008-08-08 17:50:35 +00:00
Daniel Dunbar da8b85b415 Add test for nested enum redefinition.
- <rdar://problem/6093889>

llvm-svn: 54470
2008-08-07 16:22:45 +00:00
Nuno Lopes d86aa9340d fix crash when printing diagnostics with tokens that span through more than one line
llvm-svn: 54365
2008-08-05 19:40:20 +00:00
Daniel Dunbar 81f7f2904c Add EXTWARN Diagnostic class.
- Like EXTENSION but always generates a warning (even without
   -pedantic).
 - Updated ptr -> int, int -> ptr, and incompatible cast warnings to
   be EXTWARN.
 - Other EXTENSION level diagnostics should be audited for upgrade.
 - Updated several test cases to fix code which produced unanticipated
   warnings.

llvm-svn: 54335
2008-08-05 00:07:51 +00:00
Daniel Dunbar b692ef405b Fix several issues in checking of address-of expressions.
- clang was erroneously accepting address-of applied to lvalue
   expressions involving pointer arithmetic.
 - clang was erroneously rejecting address-of applied to deref
   expressions of pointer-typed variables.
 - Improved existing test case.
 - Fixes: <rdar://problem/6113867>, <rdar://problem/6080158>

llvm-svn: 54326
2008-08-04 20:02:37 +00:00
Chris Lattner 7adf076088 Finally fix PR2189. This makes a fairly invasive but important change to
move getAsArrayType into ASTContext instead of being a method on type.
This is required because getAsArrayType(const AT), where AT is a typedef
for "int[10]" needs to return ArrayType(const int, 10).

Fixing this greatly simplifies getArrayDecayedType, which is a good sign.

llvm-svn: 54317
2008-08-04 07:31:14 +00:00
Daniel Dunbar 032db47f0f Support __attribute__(({con,de}structor)) in Parse & Sema
- Including possible priority argument
 - In other news, the attribute parsing code really needs a cleanup

llvm-svn: 54257
2008-07-31 22:40:48 +00:00
Chris Lattner 944d306371 fix some problems handling stmtexprs with labels (PR2374), and
improve 'expression unused' diagnostics for stmtexprs.

llvm-svn: 54098
2008-07-26 19:51:01 +00:00
Chris Lattner bcf2e66b3c testcase for PR2416, which we already handle correctly.
llvm-svn: 54096
2008-07-26 19:15:11 +00:00
Chris Lattner 89026888ef move all objc sema tests into a new SemaObjC directory. Next step is to
remove the objc- prefix from the tests that use it.

llvm-svn: 54084
2008-07-26 00:57:24 +00:00
Chris Lattner a075e63bbc fix several problems with the protocol qualified id handling where id was implicit.
First, fix canonical type handling of these, since protocol qualified id's are always
canonical.  Next, enhance SemaType to actually make these when used (instead of int)
allowing them to actually be used when appropriate.  Finally remove a bunch of logic
relating to the mishandling of canonical types with protocol-qual id's.  This fixes
rdar://5986251

llvm-svn: 54083
2008-07-26 00:46:50 +00:00
Chris Lattner 0974b2380f improve handling of the horrible GCC objc extension that treats "<foo>"
like "id<foo>".  This 1) fixes an infinite loop in the parser on things
like "short<foo>" 2) emits a warning about this bogus construct and 3)
changes the testcase to be substantially reduced.

llvm-svn: 54082
2008-07-26 00:20:22 +00:00
Chris Lattner 0d70761cad GCC supports the complex conjugate operator (an extension) on complex int
as well as complex float. rdar://6097730

llvm-svn: 54080
2008-07-25 23:52:49 +00:00
Chris Lattner 8c217a81ac fix diagnostics.
llvm-svn: 54079
2008-07-25 23:41:08 +00:00
Chris Lattner 903eb518e6 Fix rdar://6095136, various crashes with incomplete enum types.
llvm-svn: 54074
2008-07-25 23:18:17 +00:00
Chris Lattner 61f60a05b2 c89 does not perform array -> pointer promotion unless the array is an lvalue. This
is different than C99.  This fixes the rest of rdar://6095180.

llvm-svn: 54064
2008-07-25 21:33:13 +00:00
Chris Lattner f6e1e309c7 In c99 mode, comma does do function/array promotion even though
it does not do unary promotions (like short->int).

llvm-svn: 54058
2008-07-25 20:54:07 +00:00
Chris Lattner e174acc910 Comma does not perform unary promotions, rdar://6095180
llvm-svn: 54045
2008-07-25 20:02:29 +00:00
Chris Lattner e08e47ab2f gcc requires a semicolon at the end of an interface, unlike its extension for structs.
rdar://6095245.

llvm-svn: 54044
2008-07-25 19:54:55 +00:00