Commit Graph

2323 Commits

Author SHA1 Message Date
Daniel Dunbar 8d42281150 Add coverage of "member of anonymous union redeclares ..." diagnostic.
llvm-svn: 65637
2009-02-27 17:07:01 +00:00
Ted Kremenek dd34e06eeb Add test case for PR 3675.
llvm-svn: 65635
2009-02-27 16:48:08 +00:00
Eli Friedman 988a16b9b8 Change the AST generated for offsetof a bit so that it looks like a
normal expression, and change Evaluate and IRGen to evaluate it like a 
normal expression.  This simplifies the code significantly, and fixes 
PR3396.

llvm-svn: 65622
2009-02-27 06:44:11 +00:00
Eli Friedman 8d03f59479 Some additional ICE tests.
llvm-svn: 65614
2009-02-27 04:46:32 +00:00
Chris Lattner 09e592ea33 rename test
llvm-svn: 65587
2009-02-26 23:36:18 +00:00
Chris Lattner 7ec0bb6bc0 ok, not as broken as I thought, just confusing. This allows
initialization of wchar_t arrays with wide strings, and generalizes
wchar_size.c to work on all targets.

llvm-svn: 65586
2009-02-26 23:36:02 +00:00
Fariborz Jahanian 7285cf57a3 Do not issue bogus error on __weak/__strong ivar access.
llvm-svn: 65583
2009-02-26 23:05:51 +00:00
Chris Lattner d42c29f9a2 fix some sema problems with wide strings and hook up basic codegen for them.
llvm-svn: 65582
2009-02-26 23:01:51 +00:00
Douglas Gregor 87f95b0a6a Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:

  - Insert some new code (a text string) at a particular source
    location
  - Remove the code within a given range
  - Replace the code within a given range with some new code (a text
    string)

Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:

  template<int I> class B { };
  B<1000 >> 2> *b1;

we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:

test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
  B<1000 >> 2> *b1;
         ^
    (        )


Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.

In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.

This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).

llvm-svn: 65570
2009-02-26 21:00:50 +00:00
Steve Naroff de68001e76 Fix <rdar://problem/6574319> clang issues error on 'readonly' property with a defaul setter attribute.
Needed to make isPropertyReadonly() non-const (for this fix to compile). I imagine there's a way to retain the const-ness, however I have more important fish to fry.

llvm-svn: 65562
2009-02-26 19:11:32 +00:00
Mike Stump 92000e54ac Add end of line at end.
llvm-svn: 65557
2009-02-26 19:00:14 +00:00
Steve Naroff 42ab0dd1ee Fix <rdar://problem/6614945> method not found.
This was a fairly recent regression.

llvm-svn: 65547
2009-02-26 18:16:19 +00:00
Anders Carlsson 43e8a2b36e Add test for enum types
llvm-svn: 65540
2009-02-26 17:38:19 +00:00
Steve Naroff b162f170da Fix http://llvm.org/bugs/show_bug.cgi?id=3544.
The code for looking up local/private method in Sema::ActOnInstanceMessage() was not handling categories properly. Sema::ActOnClassMessage() didn't have this bug.
Created a helper with the correct logic and changed both methods to use it.

llvm-svn: 65532
2009-02-26 15:55:06 +00:00
Sebastian Redl 8d2ccae28b Make more AST nodes and semantic checkers dependent-expression-aware.
llvm-svn: 65529
2009-02-26 14:39:58 +00:00
Steve Naroff 8ec2784f58 Fix ObjCInterfaceDecl::lookupInstanceMethod()/lookupClassMethod() to search in inherited protocols.
Also changed ObjCInterfaceDecl::lookupClassMethod() to look through a categories protocols.

Test/patch submitted by Jean-Daniel Dupas (thanks!).

llvm-svn: 65526
2009-02-26 11:32:02 +00:00
Eli Friedman adf40d4bef Fix for PR3663/3669: use TryToFixInvalidVariablyModifiedType for
variable declarations where applicable.  Also, a few fixes to 
TryToFixInvalidVariablyModifiedType for issues that this exposed.

llvm-svn: 65500
2009-02-26 03:58:54 +00:00
Douglas Gregor 8d0921617e Use RecordFirst/RecordLast range checks in DeclContext
llvm-svn: 65489
2009-02-26 00:02:51 +00:00
Douglas Gregor d54dfb8718 Implementing parsing of template-ids as class-names, so that we can
derive from a class template specialization, e.g.,

  class B : public A<int> { };

llvm-svn: 65488
2009-02-25 23:52:28 +00:00
Douglas Gregor cbb45d0c65 Cope with use of the token '>>' inside a template argument list, e.g.,
vector<vector<double>> Matrix;

In C++98/03, this token always means "right shift". However, if we're in
a context where we know that it can't mean "right shift", provide a
friendly reminder to put a space between the two >'s and then treat it
as two >'s as part of recovery.

In C++0x, this token is always broken into two '>' tokens.

llvm-svn: 65484
2009-02-25 23:02:36 +00:00
Ted Kremenek dc3f50fbd9 Add experimental logic in GRExprEngine::EvalEagerlyAssume() to handle
expressions of the form: 'short x = (y != 10);' While we handle 'int x = (y !=
10)' lazily, the cast to another integer type currently loses the symbolic
constraint. Eager evaluation of the constraint causes the paths to bifurcate and
eagerly evaluate 'y != 10' to a constant of 1 or 0. This should address
<rdar://problem/6619921> until we have a better (more lazy approach) for
handling promotions/truncations of symbolic integer values.

llvm-svn: 65480
2009-02-25 22:32:02 +00:00
Douglas Gregor 1e249f8641 Improve location information on "reused" class template specialization
decls. Test and document the semantic location of class template
specialization definitions that occur within a scope enclosing the
scope of the class template.

llvm-svn: 65478
2009-02-25 22:18:32 +00:00
Douglas Gregor f47b911f6e Perform additional semantic checking of class template
specializations. In particular:

  - Make sure class template specializations have a "template<>"
    header, and complain if they don't.
  - Make sure class template specializations are declared/defined
    within a valid context. (e.g., you can't declare a specialization
    std::vector<MyType> in the global namespace).

llvm-svn: 65476
2009-02-25 22:02:03 +00:00
Daniel Dunbar 4208835eec Temporarily disable clearing of insert point (to indicate unreachable
code) when calling noreturn functions; general expression emission
isn't ready to do the right thing in all cases.

llvm-svn: 65473
2009-02-25 20:59:29 +00:00
Daniel Dunbar 1cdbc5404b Allow constant initializers to reference their defining decl.
- PR3662.

llvm-svn: 65472
2009-02-25 20:08:33 +00:00
Douglas Gregor 441f24118a Include the appropriate header for malloc
llvm-svn: 65471
2009-02-25 19:48:02 +00:00
Douglas Gregor 7f74112756 Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type

When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:

  template<> class Outer::Inner<int> { ... };

We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.

Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.

llvm-svn: 65467
2009-02-25 19:37:18 +00:00
Anders Carlsson f2f2e7f6a1 Use CheckAssignmentConstraints for checking the cleanup attr function. Fixes PR3656.
llvm-svn: 65461
2009-02-25 17:19:08 +00:00
Douglas Gregor 739ef0c183 C99 DR #316 implies that the function parameter types that are known
only from a function definition (that does not have a prototype) are
only used to determine the compatible with other declarations of that
same function. In particular, when referencing the function we pretend
as if it does not have a prototype. Implement this behavior, which
fixes PR3626.

llvm-svn: 65460
2009-02-25 16:33:18 +00:00
Daniel Dunbar a1047857f7 Remove a FIXME; I was mistaken in believing gcc rejected this.
llvm-svn: 65420
2009-02-25 00:22:25 +00:00
Chris Lattner d8b741c85f handle @encode interactions with array initializers.
llvm-svn: 65401
2009-02-24 23:10:27 +00:00
Chris Lattner 0cb7803341 move some initialization checking code from SemaDecl.cpp
to SemaInit.cpp, no functionality change.

llvm-svn: 65394
2009-02-24 22:27:37 +00:00
Chris Lattner d7e7b8e411 first wave of fixes for @encode sema support. This is part of PR3648.
The big difference here is that (like string literal) @encode has 
array type, not pointer type.

llvm-svn: 65391
2009-02-24 22:18:39 +00:00
Douglas Gregor eddf4333fd When we're declaring an object or function with linkage, teach name
lookup to skip over names without linkage. This finishes
<rdar://problem/6127293>.

llvm-svn: 65386
2009-02-24 20:03:32 +00:00
Douglas Gregor 5d68a20949 Extend the implicit declaration and checking against out-of-scope
external declarations to also support external variable
declarations. Unified the code for these two cases into two new
subroutines.

Note that we fail to diagnose cases like the one Neil pointed
out, where a visible non-external declaration hides an external
declaration by the same name. That will require some reshuffling of
name lookup.

llvm-svn: 65385
2009-02-24 19:23:27 +00:00
Daniel Dunbar d4ecca135a Fix IRgen of constant expressions referring to external/static
variables.
 - PR3657.

llvm-svn: 65381
2009-02-24 18:41:57 +00:00
Chris Lattner 59da739613 Fix PR3635 by handling ## magically
llvm-svn: 65374
2009-02-24 05:29:33 +00:00
Douglas Gregor de681d43eb In C, when we see a function declaration within a local scope, export
that declaration to global scope so that it can be found from other
scopes. This allows us to diagnose redeclaration errors for external
declarations across scopes. We also warn when name lookup finds such
an out-of-scope declaration. This is part of <rdar://problem/6127293>;
we'll also need to do the same thing for variables.

llvm-svn: 65373
2009-02-24 04:26:15 +00:00
Ted Kremenek cce27f5502 Fix <rdar://problem/6611677>: Add basic transfer function support in the static
analyzer for array subscript expressions involving bases that are vectors. This
solution is probably a hack: it gets the lvalue of the vector instead of an
rvalue like all other types. This should be reviewed (big FIXME in
GRExprEngine).

llvm-svn: 65366
2009-02-24 02:23:11 +00:00
Daniel Dunbar 94ceb61574 Fix two @synchronized bugs found by inspection: the expression to sychronize on should only be evaluated once, and it is evaluated outside the cleanup scope.
Also, lift SyncEnter and SyncExit up in nervous anticipation of x86-64
zero cost EH.

llvm-svn: 65362
2009-02-24 01:43:46 +00:00
Douglas Gregor e62c0a45dd Improve merging of function declarations. Specifically:
- When we are declaring a function in local scope, we can merge with
    a visible declaration from an outer scope if that declaration
    refers to an entity with linkage. This behavior now works in C++
    and properly ignores entities without linkage.
  - Diagnose the use of "static" on a function declaration in local
    scope.
  - Diagnose the declaration of a static function after a non-static
    declaration of the same function.
  - Propagate the storage specifier to a function declaration from a
    prior declaration (PR3425)
  - Don't name-mangle "main"

llvm-svn: 65360
2009-02-24 01:23:02 +00:00
Chris Lattner d13b8b55ca fix rdar://6611778, a redefinition of an interface was causing an
assertion when the ivars and method list was reset into the existing
interface.  To fix this, mark decls as invalid when they are redefined,
and don't insert ivars/methods into invalid decls.

llvm-svn: 65340
2009-02-23 22:00:08 +00:00
Steve Naroff a94e52c687 - Generate error for protocol qualifiers on 'Class'.
- Generate error for protocol qualifiers on non-ObjC types.

llvm-svn: 65333
2009-02-23 18:53:24 +00:00
Steve Naroff 91362dd011 Revert http://llvm.org/viewvc/llvm-project?view=rev&revision=65244.
Remove support for "Class<P>". Will be making this an error.

llvm-svn: 65332
2009-02-23 18:36:16 +00:00
Eli Friedman 3ae5911042 A few small improvements to Evaluate for stuff I noted in FIXMEs.
llvm-svn: 65305
2009-02-23 04:23:56 +00:00
Ted Kremenek e73f282213 retain/release checker: For now don't track the retain count of NSWindow objects (opt for false negatives).
llvm-svn: 65304
2009-02-23 02:51:29 +00:00
Ted Kremenek e6d2b40bcc More retain/release naming convention tests.
llvm-svn: 65303
2009-02-23 02:50:20 +00:00
Ted Kremenek 5fa0d070a5 Add test case for PR 2599.
llvm-svn: 65299
2009-02-23 01:29:25 +00:00
Steve Naroff c4173fa704 Contains the following (related to problems found while investigting <rdar://problem/6497631> Message lookup is sometimes different than gcc's).
- Implement instance/class overloading in ObjCContainerDecl (removing a FIXME). This involved hacking NamedDecl::declarationReplaces(), which took awhile to figure out (didn't realize replace was the default).
- Changed Sema::ActOnInstanceMessage() to remove redundant warnings when dealing with protocols. For now, I've omitted the "protocol" term in the diagnostic. It simplifies the code flow and wan't always 100% accurate (e.g. "Foo<Prot>" looks in the class interface, not just the protocol).
- Changed several test cases to jive with the above changes.

llvm-svn: 65292
2009-02-22 19:35:57 +00:00
Mike Stump 624497c29a Cleanp code with some recent suggestions.
llvm-svn: 65285
2009-02-22 13:27:11 +00:00
Eli Friedman fd85266342 Fix test to be legal on 64-bit systems.
llvm-svn: 65270
2009-02-22 07:40:57 +00:00
Eli Friedman 7bfab36877 Throw the switch to exclusively use Evaluate (along with the small
helper isConstantInitializer) to check whether an initializer is 
constant.  This passes tests, but it's possible that it'll cause 
regressions with real-world code.

Future work:
1. The diagnostics obtained this way are lower quality at the moment; 
some work both here and in Evaluate is needed for accurate diagnostics.
2. We probably need some extra code when we're in -pedantic mode so we 
can strictly enforce the rules in C99 6.6p7.
3. Dead code cleanup (this should wait until after 2, because we might 
want to re-use some of the code).

llvm-svn: 65265
2009-02-22 06:45:27 +00:00
Eli Friedman 3f8c01a110 Fix for PR3433: map __alignof__ to preferred alignment. (This was
partially done in r65258.)

llvm-svn: 65260
2009-02-22 03:31:23 +00:00
Eli Friedman 19a546c15b Improvements to ASTContext::getDeclAlignInBytes; fixes the testcase in
PR3254 and part of PR3433.

The isICE changes are necessary to keep the computed results 
consistent with Evaluate.

llvm-svn: 65258
2009-02-22 02:56:25 +00:00
Anders Carlsson b8482c5d5d Match gcc and always perform array/function conversion for asm input exprs. Fixes PR3641.
llvm-svn: 65256
2009-02-22 02:11:23 +00:00
Anders Carlsson d05f44b5ca Correctly encode incomplete and variable length arrays. Fixes PR3639.
llvm-svn: 65255
2009-02-22 01:38:57 +00:00
Eli Friedman 2194bb78ec Sanity fix for PR3642: if we're treating a diagnostic as an error, it's
required to actually be an error for correctness.  The attached testcase 
now gives an error instead of mysteriously crashing.

Now, it's possible we actually want to support the given usage, but I 
haven't looked at the relevant code closely.

llvm-svn: 65253
2009-02-22 00:20:44 +00:00
Daniel Dunbar 9cbbd99c4b Force arch for these test cases.
llvm-svn: 65252
2009-02-21 23:45:41 +00:00
Steve Naroff 670e72ddc7 Add support for GCC ObjC extension "Class<protocol>". Sigh.
Found while researching <rdar://problem/6497631> Message lookup is sometimes different than gcc's.

Will never be seen in user code. Needed to pass dejagnu testsuite.

llvm-svn: 65244
2009-02-21 20:17:11 +00:00
Steve Naroff cd8d572283 Warn about bogus protocol qualifiers.
llvm-svn: 65241
2009-02-21 19:50:43 +00:00
Fariborz Jahanian 0c9404e0a7 Warn on use of __weak attribute on local
variable (objc2 gc specific).

llvm-svn: 65240
2009-02-21 19:44:02 +00:00
Fariborz Jahanian ccfd554024 Fixed an ICE in meta-data generation of __weak/__strong ivars.
llvm-svn: 65235
2009-02-21 18:23:24 +00:00
Daniel Dunbar 79e042a8b5 Evaluation of unary deref could call integer evaluator on non-integral
expr; hilarity ensued.
 - PR3640.

llvm-svn: 65234
2009-02-21 18:14:20 +00:00
Steve Naroff da88fb9c73 Add test case to record a couple inconsistencies with GCC (found in <rdar://problem/6561076> [clang on Xcode] warning: cannot find protocol definition for 'OzzyP').
Removing the "cannot find protocol" warning is trivial if necessary (but I don't think it's the right thing to do).

llvm-svn: 65232
2009-02-21 17:03:43 +00:00
Steve Naroff 7a7814c32b This fixes <rdar://problem/6497650> More type mismatches issues with clang.
Move two key ObjC typechecks from Sema::CheckPointerTypesForAssignment() to ASTContext::mergeTypes().

This allows us to take advantage of the recursion in ASTContext::mergeTypes(), removing some bogus warnings.

This test case I've added includes an example where we still warn (and GCC doesn't). Need to talk with folks and decide what to do. At this point, the major bogosities should be fixed.

llvm-svn: 65231
2009-02-21 16:18:07 +00:00
Ted Kremenek 8a73c71486 Improved naming convention heuristics in the retain/release checker to better
handle method names that contain 'new', 'copy', etc., but those words might be
the substring of larger words such as 'newsgroup' and 'photocopy' that do not
indicate the allocation of objects. This should address the issues discussed in
<rdar://problem/6552389>.

llvm-svn: 65224
2009-02-21 05:13:43 +00:00
Daniel Dunbar 3c81dabd76 Emit extern_weak when needed.
- PR3629.

llvm-svn: 65203
2009-02-21 00:24:10 +00:00
Daniel Dunbar 0c4eda5923 We must always mangle attribute overloadable functions; even if in a
system header.
 - Prevents a codegen crash when anything used anything in tgmath! :)

llvm-svn: 65200
2009-02-20 23:09:27 +00:00
Steve Naroff 326064168a Fix <rdar://problem/6500554> missing objc error message.
llvm-svn: 65198
2009-02-20 22:59:16 +00:00
Anders Carlsson c4c6031859 Always try to fold array sizes, and warn if we could fold something that isn't an ICE. This makes us compatible with GCC.
llvm-svn: 65140
2009-02-20 18:53:20 +00:00
Daniel Dunbar ce39954d5d Handle constant int -> ptr casts of lvalue results.
- PR3463 (again).

llvm-svn: 65133
2009-02-20 18:22:23 +00:00
Daniel Dunbar cdbb5e336d Set call attribute for direct calls (i.e. noreturn).
- Remove an unused variant of EmitCallExpr overload.

llvm-svn: 65130
2009-02-20 18:06:48 +00:00
Steve Naroff 17b2f5d728 Fix <rdar://problem/6586239> bitfield constraints not enforced (for ObjC)
llvm-svn: 65128
2009-02-20 17:57:11 +00:00
Daniel Dunbar e4be42c17f Add some stdlib builtins
llvm-svn: 65115
2009-02-20 06:36:40 +00:00
Eli Friedman 7157825d44 Use -verify for consistency.
llvm-svn: 65106
2009-02-20 02:03:47 +00:00
Eli Friedman 0b8337c30b Add support for * (unary dereference) operator to ExprConstant.
llvm-svn: 65105
2009-02-20 01:57:15 +00:00
Eli Friedman ce98257691 Suppress constant initializer checking when the declaration isn't valid.
This prevents emitting diagnostics which are almost certainly useless.

(Note that the test is checking that we emit only one diagnostic.)

llvm-svn: 65101
2009-02-20 01:34:21 +00:00
Ted Kremenek a26ad40e41 Add test case for <rdar://problem/6562655>.
llvm-svn: 65085
2009-02-20 00:10:09 +00:00
Chris Lattner 810d330cd3 Fix a long standard problem with clang retaining "too much" sugar
information about types.  We often print diagnostics where we say 
"foo_t" is bad, but the user doesn't know how foo_t is declared 
(because it is a typedef).  Fix this by expanding sugar when present
in a diagnostic (and not one of a few special cases, like vectors).

Before:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' and 'typeof(F)')
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

After:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

llvm-svn: 65081
2009-02-19 23:45:49 +00:00
Daniel Dunbar 1c8560d93e Extend Evaluate() to fold (int) <pointer type>.
- PR3463, PR3398, <rdar://problem/6553401> crash on relocatable
   symbol addresses as constants in static locals.

 - There are many more scenarious we could handle (like arithmetic on
   such an int) but this is the main use case.

llvm-svn: 65074
2009-02-19 22:24:01 +00:00
Daniel Dunbar 96f8677e11 Arguments to unordered comparison builtins may need implicit casts.
- <rdar://problem/6094103> sema fails to promote type arguments to __builtin_isgreater (and friends)

llvm-svn: 65059
2009-02-19 19:28:43 +00:00
Anders Carlsson f96954ca30 Add irgen support for the noinline attribute.
llvm-svn: 65056
2009-02-19 19:22:11 +00:00
Anders Carlsson 880971241b Add sema support for the noinline attribute.
llvm-svn: 65055
2009-02-19 19:16:48 +00:00
Ted Kremenek bea465aefb Update test case to include a leak that occurs at the place of allocation.
llvm-svn: 65048
2009-02-19 18:20:28 +00:00
Zhongxing Xu e6e76aa571 fix test case
llvm-svn: 65037
2009-02-19 08:45:23 +00:00
Zhongxing Xu 5b9223fcf2 add test case.
llvm-svn: 65036
2009-02-19 08:42:43 +00:00
Daniel Dunbar f0acf7bd4c Don't emit K&R unprototyped function definitions as varargs.
- <rdar://problem/6584606> clang/x86-64 - too many reg saves

llvm-svn: 65032
2009-02-19 07:15:39 +00:00
Anders Carlsson 0756c97dae Emit the correct diagnostics when we constant fold an array size to a negative value.
llvm-svn: 65023
2009-02-19 06:30:50 +00:00
Anders Carlsson 0bbcfa6bb9 Make sure to check the value of the constant expression, as suggested by Daniel.
llvm-svn: 65021
2009-02-19 06:19:15 +00:00
Daniel Dunbar b2f4cdb233 Emission of global variable initialializer was broken in rare
situation where a tentative decl was emitted *after* the actual
initialization. This occurs in some rare situations with static decls.
 - PR3613.

 - I'm not particularly happy with this fix, but I don't see a simpler
   or more elegant solution yet.

llvm-svn: 65018
2009-02-19 05:36:41 +00:00
Anders Carlsson ef56fbaa39 Handle the GNU void* and function pointer arithmetic extensions for constant expressions as well.
llvm-svn: 65013
2009-02-19 04:55:58 +00:00
Ted Kremenek e571c4eeb7 Add test case for 'nil receiver returns undefined struct value' check.
llvm-svn: 65004
2009-02-19 04:07:38 +00:00
Douglas Gregor 0f3dd9a86b Provide a proper source location when building an implicit dereference. Fixes PR3600
llvm-svn: 64993
2009-02-19 00:52:42 +00:00
Douglas Gregor 120951391c Make error-message check platform-agnostic
llvm-svn: 64985
2009-02-19 00:03:13 +00:00
Douglas Gregor 1cba5fe1d1 Downgrade the "excess elements in initializer" errors to warnings *in
C*. They're required errors in C++.

llvm-svn: 64964
2009-02-18 22:23:55 +00:00
Ted Kremenek 443e040d06 Add a few more GC-only test cases for the retain/release checker.
llvm-svn: 64960
2009-02-18 22:11:23 +00:00
Douglas Gregor 222e5e4ad2 Return true on errors, return true on errors, return true on errors
llvm-svn: 64957
2009-02-18 22:00:45 +00:00
Douglas Gregor 171c45ab0c Downgrade complaints about calling unavailable functions to a warning
(as GCC does), except when we've performed overload resolution and
found an unavailable function: in this case, we actually error.

Merge the checking of unavailable functions with the checking for
deprecated functions. This unifies a bit of code, and makes sure that
we're checking for unavailable functions in the right places. Also,
this check can cause an error. We may, eventually, want an option to
make "unavailable" warnings into errors.

Implement much of the logic needed for C++0x deleted functions, which
are effectively the same as "unavailable" functions (but always cause
an error when referenced). However, we don't have the syntax to
specify deleted functions yet :)

llvm-svn: 64955
2009-02-18 21:56:37 +00:00
Daniel Dunbar aac5bf19a5 __attribute__((aligned)) was being ignored!
This knocks out another 8 gcc/compat/i386 & x86_64 failures.

llvm-svn: 64947
2009-02-18 20:06:09 +00:00
Chris Lattner f638b97fe0 use the full spelling of a string literal token so that trigraphs
and escaped newlines don't throw off the offset computation.

On this testcase:
  printf("abc\
def"
         "%*d", (unsigned) 1, 1);

Before:
t.m:5:5: warning: field width should have type 'int', but argument has type 'unsigned int'
def"
    ^

after:
t.m:6:12: warning: field width should have type 'int', but argument has type 'unsigned int'
         "%*d", (unsigned) 1, 1);
           ^    ~~~~~~~~~~~~

llvm-svn: 64930
2009-02-18 18:34:12 +00:00
Chris Lattner df18c6a9af add c testcase for string literal diagnostic improvement.
llvm-svn: 64929
2009-02-18 18:25:31 +00:00
Chris Lattner a26fb347a0 Start improving diagnostics that relate to subcharacters of string literals.
First step, handle diagnostics in StringLiteral's that are due to token pasting.

For example, we now handle:
  id str2 = @"foo" 
            "bar"
           @"baz"
           " b\0larg";  // expected-warning {{literal contains NUL character}}

Correctly:

test/SemaObjC/exprs.m:17:15: warning: CFString literal contains NUL character
           " b\0larg";  // expected-warning {{literal contains NUL character}}
           ~~~^~~~~~~

There are several other related issues still to be done.

llvm-svn: 64924
2009-02-18 17:49:48 +00:00
Douglas Gregor 94349fd8cb Allow "overloadable" functions in C to be declared as variadic without
any named parameters, e.g., this is accepted in C:

  void f(...) __attribute__((overloadable));

although this would be rejected:

  void f(...);

To do this, moved the checking of the "ellipsis without any named
arguments" condition from the parser into Sema (where it belongs anyway).

llvm-svn: 64902
2009-02-18 07:07:28 +00:00
Douglas Gregor b2809a0a1b Don't allow calls to functions marked "unavailable". There's more work
to do in this area, since there are other places that reference
FunctionDecls.

Don't allow "overloadable" functions (in C) to be declared without a
prototype.

llvm-svn: 64897
2009-02-18 06:34:51 +00:00
Chris Lattner c96e0c4399 pass -verify in exprs.m, merge const-id.m into message.m
llvm-svn: 64886
2009-02-18 04:41:38 +00:00
Chris Lattner 2c4866057d fix rdar://6597252: two exactly identical pointer types are always
compatible, even if they are weird implicit objc pointer types like
Class.

llvm-svn: 64885
2009-02-18 04:38:20 +00:00
Eli Friedman 61d484ea8b Fix test: config.h is not guaranteed to exist at the location in
question.  Use __builtin_alloca instead, which is guaranteed to mean the right
thing without any includes.

llvm-svn: 64868
2009-02-18 01:02:14 +00:00
Eli Friedman 1e3a02f090 Fix test on platforms where size_t != unsigned long.
llvm-svn: 64867
2009-02-18 00:52:29 +00:00
Daniel Dunbar 4750e63486 isICE was evaluating ?: incorrectly with missing-gcc-LHS extension.
Add assert to isICE that, on success, result must be the same as
EvaluateAsInt()... this enforces a minimum level of sanity.

llvm-svn: 64865
2009-02-18 00:47:45 +00:00
Ted Kremenek 51189468ea Update several tests to explicitly use BasicConstraintManager as well as to use RangeConstraintManager with RegionStoreManager.
llvm-svn: 64854
2009-02-17 23:32:18 +00:00
Douglas Gregor 67a6564091 Implement basic parsing and semantic analysis for explicit
specialization of class templates, e.g.,

  template<typename T> class X;

  template<> class X<int> { /* blah */ };

Each specialization is a different *Decl node (naturally), and can
have different members. We keep track of forward declarations and
definitions as for other class/struct/union types.

This is only the basic framework: we still have to deal with checking
the template headers properly, improving recovery when there are
failures, handling nested name specifiers, etc.

llvm-svn: 64848
2009-02-17 23:15:12 +00:00
Daniel Dunbar abdc0f1e07 Eliminate dependency on where test is run from.
llvm-svn: 64837
2009-02-17 22:47:27 +00:00
Daniel Dunbar 43a5d9e409 Eek! getDeclAlign sometimes returned alignment in bits.
- Renamed to getDeclAlignInBytes since most other query functions
   work in bits.

 - Fun to track down as isIntegerConstantExpr was getting it right,
   but Evaluate() was getting it wrong. Maybe we should assert they
   compute the same thing when they succeed?

llvm-svn: 64828
2009-02-17 22:16:19 +00:00
Ted Kremenek 35b13439cc Convert tabs to spaces.
llvm-svn: 64799
2009-02-17 19:53:58 +00:00
Ted Kremenek 47c853007e Enhance tests to exercise more combinations of using the RangeConstraintManager with the RegionStoreManager.
llvm-svn: 64788
2009-02-17 19:29:07 +00:00
Douglas Gregor 13c6362a43 Proof that attribute __overloadable__ works as well as overloadable
llvm-svn: 64781
2009-02-17 18:51:14 +00:00
Daniel Dunbar 38ad1e6138 Change EmitConstantExpr to allow failure.
IRgen no longer relies on isConstantInitializer, instead we just try
to emit the constant. If that fails then in C we emit an error
unsupported (this occurs when Sema accepted something that it doesn't
know how to fold, and IRgen doesn't know how to emit) and in C++ we
emit a guarded initializer.

This ends up handling a few more cases, because IRgen was actually
able to emit some of the constants Sema accepts but can't Evaluate().
For example, PR3398.

llvm-svn: 64780
2009-02-17 18:43:32 +00:00
Ben Laurie c8f1ab5035 Don't include alloca.h if it doesn't exist.
llvm-svn: 64771
2009-02-17 17:33:31 +00:00
Douglas Gregor 7a0febe66d Remove the error about redefining library functions. It's causing too
much pain when compiling the Linux kernel (PR3592).

llvm-svn: 64767
2009-02-17 16:03:01 +00:00
Ted Kremenek b535181199 Static Analyzer driver/options (partial) cleanup:
- Move all analyzer options logic to AnalysisConsumer.cpp.
- Unified specification of stores/constraints/output to be:
   -analyzer-output=...
   -analyzer-store=...
   -analyzer-constraints=...
  instead of -analyzer-range-constraints, -analyzer-store-basic, etc.
- Updated drivers (ccc-analyzer, scan-builds, new ccc) to obey this new
  interface
- Updated test cases to conform to new driver options

llvm-svn: 64737
2009-02-17 04:27:41 +00:00
Douglas Gregor a908e7fccc Static variables and functions won't collide with standard library
functions, so if we're declaring a static we should implicitly declare
a library function by the same name (e.g., malloc, strdup). Fixes PR3592.

llvm-svn: 64736
2009-02-17 03:23:10 +00:00
Douglas Gregor 264ec4f237 Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,

  template<> class vector<bool> { };

or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.

llvm-svn: 64716
2009-02-17 01:05:43 +00:00
Chris Lattner 8a04c5ad03 add support for -fno-math-errno, and validate that it affects sema properly.
llvm-svn: 64708
2009-02-17 00:35:09 +00:00
Chris Lattner a89050c788 sema no longer explodes, yay!
llvm-svn: 64707
2009-02-17 00:32:04 +00:00
Daniel Dunbar 6e8c07d0ea Diagnose non-power-of-2 arguments to attribute aligned.
llvm-svn: 64700
2009-02-16 23:37:57 +00:00
Daniel Dunbar 8eb018ab9c Support IRgen of sqrt -> llvm.sqrt, pow -> llvm.pow.
- Define pow[lf]?, sqrt[lf]? as builtins.

 - Add -fmath-errno option which binds to LangOptions.MathErrno

 - Add new builtin flag Builtin::Context::isConstWithoutErrno for
   functions which can be marked as const if errno isn't respected for
   math functions. Sema automatically marks these functions as const
   when they are defined, if MathErrno=0.

 - IRgen uses const attribute on sqrt and pow library functions to
   decide if it can use the llvm intrinsic.

llvm-svn: 64689
2009-02-16 22:43:43 +00:00
Douglas Gregor 5978cdb5ef Make "implicit int" an error in C++ (unless we're allowing Microsoft
extensions). This caught a couple bugs in our test suite :)

llvm-svn: 64686
2009-02-16 22:38:20 +00:00
Chris Lattner a377833888 diagnose uses of deprecated typenames and tags.
We now pass all the deprecation tests in the objc.dg suite.

llvm-svn: 64679
2009-02-16 22:07:16 +00:00
Daniel Dunbar e28b359881 Fix IRgen of __builtin_memset.
- Fix test case to not only have negative tests.

llvm-svn: 64674
2009-02-16 21:52:05 +00:00
Fariborz Jahanian 1dd6094517 Fixes a bug in property type encoding.
llvm-svn: 64672
2009-02-16 21:41:04 +00:00
Chris Lattner e404d0ba05 warn about interfaces that inherit from deprecated classes.
llvm-svn: 64671
2009-02-16 21:33:09 +00:00
Chris Lattner ced903b793 warn about categories that implement deprecated interfaces.
llvm-svn: 64670
2009-02-16 21:30:01 +00:00
Chris Lattner 6c7ce109e0 enhance ExtVectorElementExpr to allow V->xxyy to work like (*V).xxyy
llvm-svn: 64667
2009-02-16 21:11:58 +00:00
Douglas Gregor bfdd607372 When merging from a function with a prototype to a function without a
prototype, synthesize ParmVarDecls for prototype-less FunctionDecl.

llvm-svn: 64666
2009-02-16 20:58:07 +00:00
Ted Kremenek 227811afca Test passes with -analyzer-range-contraints.
llvm-svn: 64663
2009-02-16 19:43:20 +00:00
Chris Lattner 46d6b13448 do not warn about uses of deprecated decls when in an out-of-line objc method
whose declaration was declared as deprecated.

llvm-svn: 64658
2009-02-16 19:35:30 +00:00
Douglas Gregor f15f5d3e9f When inside an Objective-C++ method, name lookup should look into the
interface for ivars before assuming that this is an unresolved
function name.

Fixes <rdar://problem/6590445>.

llvm-svn: 64653
2009-02-16 19:28:42 +00:00
Chris Lattner 43df556ab5 Add support for deprecating ObjC properties. Unlike GCC, we warn that the
property is deprecated, not the getter/setter if the attribute is on
the property.

llvm-svn: 64644
2009-02-16 18:35:08 +00:00
Douglas Gregor bcbf86399f When a function with a prototype is redeclared without a prototype,
merge the prototype into the redeclaration (and make a note in the
declaration). Fixes PR3588.

llvm-svn: 64641
2009-02-16 18:20:44 +00:00
Douglas Gregor 75a45ba2a4 Adopt a more principled approach to invalid declarations:
- If a declaration is an invalid redeclaration of an existing name,
    complain about the invalid redeclaration then avoid adding it to
    the AST (we can still parse the definition or initializer, if any).
  - If the declaration is invalid but there is no prior declaration
    with that name, introduce the invalid declaration into the AST
    (for later error recovery).
  - If the declaration is an invalid redeclaration of a builtin that
    starts with __builtin_, we produce an error and drop the
    redeclaration. If it is an invalid redeclaration of a library
    builtin (e.g., malloc, printf), warn (don't error!) and drop the
    redeclaration.

If a user attempts to define a builtin, produce an error and (if it's
a library builtin like malloc) suggest -ffreestanding.

This addresses <rdar://problem/6097585> and PR2892. However, PR3588 is
still going to cause some problems when builtins are redeclared
without a prototype.

llvm-svn: 64639
2009-02-16 17:45:42 +00:00
Chris Lattner 50afe31b43 add support for deprecated objc ivars.
llvm-svn: 64637
2009-02-16 17:19:12 +00:00
Chris Lattner 96895e8dcd specify a triple to use, otherwise we get errors on this test for
hosts with a different size_t type.

llvm-svn: 64636
2009-02-16 17:11:14 +00:00
Chris Lattner f06a702e46 update expected-warning line.
llvm-svn: 64635
2009-02-16 17:08:46 +00:00
Chris Lattner ee4b5235e3 Add support for deprecated members of RecordDecls (e.g. struct fields).
llvm-svn: 64634
2009-02-16 17:07:21 +00:00
Nate Begeman a6b47a4142 Don't allow taking the address of an element in an ext_vector
llvm-svn: 64614
2009-02-15 22:45:20 +00:00
Chris Lattner 8510b902fb implement gcc/testsuite/objc.dg/method-attribute-3.m, by improving error recovery.
llvm-svn: 64609
2009-02-15 22:24:30 +00:00
Chris Lattner 2edf0fcb75 fix PR3579: __LINE__ expands to the presumed location of the
*end* of a macro instantiation, not the start of it.  This is
really all about bug-for-bug compatibility with GCC, but not
doing this breaks the FreeBSD kernel.

llvm-svn: 64603
2009-02-15 21:06:15 +00:00
Chris Lattner 9dc9c206d3 track "just a little more" location information for macro instantiations.
Now instead of just tracking the expansion history, also track the full
range of the macro that got replaced.  For object-like macros, this doesn't
change anything.  For _Pragma and function-like macros, this means we track
the locations of the ')'.

This is required for PR3579 because apparently GCC uses the line of the ')'
of a function-like macro as the location to expand __LINE__ to.

llvm-svn: 64601
2009-02-15 20:52:18 +00:00
Daniel Dunbar f898638eee PR3589: Don't simplify libcalls with -ffreestanding.
llvm-svn: 64599
2009-02-15 20:00:15 +00:00
Chris Lattner 4c6ea8612a allow implementations of deprecated functions to use deprecated symbols.
llvm-svn: 64572
2009-02-15 01:38:09 +00:00
Douglas Gregor 2563d0fa08 Add a test case for -ffreestanding that redefines malloc.
Warn that complex numbers are an extension in a freestanding C99
implementation.

llvm-svn: 64568
2009-02-14 21:06:05 +00:00
Mike Stump 6bae7a1b2a Add expected note. Surely people test before the check in stuff.
llvm-svn: 64565
2009-02-14 20:35:19 +00:00
Cedric Venet 08438133da Add svn:eol-style=native to some files
Correct two files with inconsistent lines endings.

llvm-svn: 64564
2009-02-14 20:20:19 +00:00
Fariborz Jahanian 99bed6fd21 Fixed a problem caused by foreward @class use
which consequently caused a Seg fault. during meta-data
generation. It also addresses an issue related to
late binding of newly synthesize ivars (when we support it).

llvm-svn: 64563
2009-02-14 20:13:28 +00:00
Anders Carlsson b6ba4682b5 Add support for deprecated Obj-C methods. The semantics mostly match what gcc has.
llvm-svn: 64562
2009-02-14 19:08:58 +00:00
Douglas Gregor e711f7052e Add hook to add attributes to function declarations that we know
about, whether they are builtins or not. Use this to add the
appropriate "format" attribute to NSLog, NSLogv, asprintf, and
vasprintf, and to translate builtin attributes (from Builtins.def)
into actual attributes on the function declaration.

Use the "printf" format attribute on function declarations to
determine whether we should do format string checking, rather than
looking at an ad hoc list of builtins and "known" function names.

Be a bit more careful about when we consider a function a "builtin" in
C++.

llvm-svn: 64561
2009-02-14 18:57:46 +00:00
Chris Lattner aff301478a new tests, it would be nice to not warn on the second one.
llvm-svn: 64549
2009-02-14 08:27:44 +00:00
Chris Lattner 677a35804f add parser and type checking support for attribute((objc_exception)).
We don't have "zero cost" exceptions for ObjC yet, so there is no codegen
support required.

llvm-svn: 64546
2009-02-14 08:09:34 +00:00
Chris Lattner 9844408ad6 rename test
llvm-svn: 64545
2009-02-14 08:08:05 +00:00
Chris Lattner 237f27573f Several related changes:
1) implement parser and sema support for reading and verifying attribute(warnunusedresult).
2) rename hasLocalSideEffect to isUnusedResultAWarning, inverting the sense
   of its result.
3) extend isUnusedResultAWarning to directly return the loc and range 
   info that should be reported to the user.  Make it substantially more
   precise in some cases than what was previously reported.
4) teach isUnusedResultAWarning about CallExpr to decls that are 
   pure/const/warnunusedresult, fixing a fixme.
5) change warn_attribute_wrong_decl_type to not pass in english strings, instead,
   pass in integers and use %select.

llvm-svn: 64543
2009-02-14 07:37:35 +00:00
Ted Kremenek d25fb7a613 GRExprEngine: Handle empty statement expressions.
llvm-svn: 64541
2009-02-14 05:55:08 +00:00
Ted Kremenek 4e9d4b5d48 Added GRStateManager::scanReachableSymbols(), a method which scans the reachable
symbols from an SVal.

- Fixed a bug in EnvironmentManager::RemoveDeadBindings() where it did not mark
  live all the symbols reachable from a live block-level expression.

- Fixed a bug in the retain/release checker where it did not stop tracking
  symbols that 'escaped' via compound literals being assigned to something the
  BasicStoreManager didn't reason about.

llvm-svn: 64534
2009-02-14 03:16:10 +00:00
Daniel Dunbar 019ef0bbfe x86_64 ABI: Pass simple types directly when possible. This is
important for both keeping the generated LLVM simple and for ensuring
that integer types are passed/promoted correctly.

llvm-svn: 64529
2009-02-14 02:09:24 +00:00
Douglas Gregor 538c3d8459 Make it possible for builtins to expression FILE* arguments, so that
we can define builtins such as fprintf, vfprintf, and
__builtin___fprintf_chk. Give a nice error message when we need to
implicitly declare a function like fprintf.

llvm-svn: 64526
2009-02-14 01:52:53 +00:00
Douglas Gregor 2de3e31cf8 Add test case to insure that implicit builtin declarations for C library functions aren't created in C++
llvm-svn: 64513
2009-02-14 00:37:42 +00:00
Douglas Gregor ac5d4c5f8e Extend builtin "attribute" syntax to include a notation for
printf-like functions, both builtin functions and those in the
C library. The function-call checker now queries this attribute do
determine if we have a printf-like function, rather than scanning
through the list of "known functions IDs". However, there are 5
functions they are not yet "builtins", so the function-call checker
handles them specifically still:

  - fprintf and vfprintf: the builtins mechanism cannot (yet)
    express FILE* arguments, so these can't be encoded.
  - NSLog: the builtins mechanism cannot (yet) express NSString*
    arguments, so this (and NSLogv) can't be encoded.
  - asprintf and vasprintf: these aren't part of the C99 standard
    library, so we really shouldn't be defining them as builtins in
    the general case (and we don't seem to have the machinery to make
    them builtins only on certain targets and depending on whether
    extensions are enabled).

llvm-svn: 64512
2009-02-14 00:32:47 +00:00
Chris Lattner cd7bc144f6 fix rdar://6586493, a bug in codegen of the GNU
missing-?:-true-value extension.

llvm-svn: 64505
2009-02-13 23:35:32 +00:00
Douglas Gregor b9063fc1b3 Implicitly declare certain C library functions (malloc, strcpy, memmove,
etc.) when we perform name lookup on them. This ensures that we
produce the correct signature for these functions, which has two
practical impacts:

  1) When we're supporting the "implicit function declaration" feature
  of C99, these functions will be implicitly declared with the right
  signature rather than as a function returning "int" with no
  prototype. See PR3541 for the reason why this is important (hint:
  GCC always predeclares these functions).
 
  2) If users attempt to redeclare one of these library functions with
  an incompatible signature, we produce a hard error.

This patch does a little bit of work to give reasonable error
messages. For example, when we hit case #1 we complain that we're
implicitly declaring this function with a specific signature, and then
we give a note that asks the user to include the appropriate header
(e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In
case #2, we show the type of the implicit builtin that was incorrectly
declared, so the user can see the problem. We could do better here:
for example, when displaying this latter error message we say
something like:

  'strcpy' was implicitly declared here with type 'char *(char *, char
  const *)'

but we should really print out a fake code line showing the
declaration, like this:

  'strcpy' was implicitly declared here as:

    char *strcpy(char *, char const *)

This would also be good for printing built-in candidates with C++
operator overloading.

The set of C library functions supported by this patch includes all
functions from the C99 specification's <stdlib.h> and <string.h> that
(a) are predefined by GCC and (b) have signatures that could cause
codegen issues if they are treated as functions with no prototype
returning and int. Future work could extend this set of functions to
other C library functions that we know about.

llvm-svn: 64504
2009-02-13 23:20:09 +00:00
Daniel Dunbar f9f039865f Set constant bit on static block vars as well. Patch by Anders Johnson!q
llvm-svn: 64502
2009-02-13 22:58:39 +00:00
Daniel Dunbar 311bf2916b Warn about attribute used ignored on "extern int a
__attribute__((used))".

llvm-svn: 64499
2009-02-13 22:48:56 +00:00
Ted Kremenek 02b63b4287 Add test case illustrating special handling of 'SenTestCase' subclasses for the missing -dealloc check.
llvm-svn: 64494
2009-02-13 22:26:30 +00:00
Daniel Dunbar 128a138a57 IRgen support for attribute used.
- PR3566

llvm-svn: 64492
2009-02-13 22:08:43 +00:00
Chris Lattner 303284acfc If x is an invalid field decl, don't construct an expression for P->x,
just silently return an error to avoid bogus diagnostics.

llvm-svn: 64491
2009-02-13 22:08:30 +00:00
Daniel Dunbar 6b8720e723 Pull MayDeferGeneration out of EmitGlobal.
- Fix emission of static functions with constructor attribute while I
   was here.
<rdar://problem/6140899> [codegen] "static" and attribute-constructor interact poorly

llvm-svn: 64488
2009-02-13 21:18:01 +00:00
Chris Lattner 9ef847be12 Fix rdar://6562329, a static analyzer crash Ted noticed on
wine sources.  This was happening because HighlightMacros was 
calling EnterMainFile multiple times on the same preprocessor
object and getting an assert due to the new #line stuff (the
file in question was bison output with #line directives).

The fix for this is to not reenter the file.  Instead, 
relex the tokens in raw mode, swizzle them a bit and repreprocess
the token stream.  An added bonus of this is that rewrite macros
will now hilight the macro definition as well as its uses.  Woo.

llvm-svn: 64480
2009-02-13 19:33:24 +00:00
Daniel Dunbar fee07a0b47 Sema/AST support for attribute used. Patch by Anders Johnson (with small tweaks & test case)!
llvm-svn: 64478
2009-02-13 19:23:53 +00:00
Douglas Gregor 1d672f84a6 Fix capitalization in a diagnostic
llvm-svn: 64472
2009-02-13 18:20:19 +00:00
Fariborz Jahanian d8fc1053ab Fixed a 64bit code gen bug of a cateogory
implementation with no category declaration!

llvm-svn: 64470
2009-02-13 17:52:22 +00:00
Anders Carlsson 6ee8a7dac5 Start warning about unknown attributes.
llvm-svn: 64447
2009-02-13 08:22:04 +00:00
Anders Carlsson 63784f4e5e Add CodeGen support for the nodebug attribute.
llvm-svn: 64445
2009-02-13 08:11:52 +00:00
Anders Carlsson 76187b4d68 Add sema support for the nodebug attribute.
llvm-svn: 64441
2009-02-13 06:46:13 +00:00
Eli Friedman 1efaaeaa69 Initial implementation of arbitrary fixed-width integer types.
Currently only used for 128-bit integers.

Note that we can't use the fixed-width integer types for other integer 
modes without other changes because glibc headers redefines (u)int*_t 
and friends using the mode attribute.  For example, this means that uint64_t
has to be compatible with unsigned __attribute((mode(DI))), and 
uint64_t is currently defined to long long.  And I have a feeling we'll 
run into issues if we try to define uint64_t as something which isn't 
either long or long long.

This doesn't get the alignment right in most cases, including 
the 128-bit integer case; I'll file a PR shortly.  The gist of the issue 
is that the targets don't really expose the information necessary to 
figure out the alignment outside of the target description, so there's a 
non-trivial amount of work involved in getting it working right.  That 
said, the alignment used is conservative, so the only issue with the 
current implementation is ABI compatibility.

This makes it trivial to add some sort of "bitwidth" attribute to make 
arbitrary-width integers; I'll do that in a followup.

We could also use this for stuff like the following for compatibility 
with gcc, but I have a feeling it would be a better idea for clang to be 
consistent between C and C++ modes rather than follow gcc's example for 
C mode.
struct {unsigned long long x : 33;} x;
unsigned long long a(void) {return x.x+1;}

llvm-svn: 64434
2009-02-13 02:31:07 +00:00
Douglas Gregor adb0201418 Add mangling for variadic functions and conversion functions
llvm-svn: 64425
2009-02-13 01:28:03 +00:00
Ted Kremenek ae63cf0b64 This test now passes.
llvm-svn: 64417
2009-02-13 00:39:34 +00:00
Douglas Gregor 633b73783f Tighten checking of the "overloadable" attribute. If any function by a
given name in a given scope is marked as "overloadable", every
function declaration and definition with that same name and in that
same scope needs to have the "overloadable" attribute. Essentially,
the "overloadable" attribute is not part of attribute merging, so it
must be specified even for redeclarations. This keeps users from
trying to be too sneaky for their own good:

  double sin(double) __attribute__((overloadable)); // too sneaky
  #include <math.h>

Previously, this would have made "sin" overloadable, and therefore
given it a mangled name. Now, we get an error inside math.h when we
see a (re)declaration of "sin" that doesn't have the "overloadable"
attribute.

llvm-svn: 64414
2009-02-13 00:26:38 +00:00
Douglas Gregor 5fec5b0495 Add basic support for C++ name mangling according to the Itanium C++
ABI to the CodeGen library. Since C++ code-generation is so
incomplete, we can't exercise much of this mangling code. However, a
few smoke tests show that it's doing the same thing as GCC. When C++
codegen matures, we'll extend the ABI tester to verify name-mangling
as well, and complete the implementation here.

At this point, the major client of name mangling is in the uses of the
new "overloadable" attribute in C, which allows overloading. Any
"overloadable" function in C (or in an extern "C" block in C++) will
be mangled the same way that the corresponding C++ function would be
mangled.

llvm-svn: 64413
2009-02-13 00:10:09 +00:00
Daniel Dunbar 53bf741208 Honor attribute section on static block var decls.
llvm-svn: 64411
2009-02-12 23:32:54 +00:00
Mike Stump 6b63074de9 Fix limits.h for linux, as glibc does a #include_next unless
_GCC_LIMITS_H_ is defined, when __GNUC__ is defined.

Also, we need to stay away from possible conflicts with header guards.
We should use CLANG_ to prefix all header guards.

llvm-svn: 64408
2009-02-12 23:06:31 +00:00
Douglas Gregor 41e3fc1ff5 Add missing test for the "overloadable" attribute
llvm-svn: 64396
2009-02-12 19:25:19 +00:00
Steve Naroff 344e74a986 Fix <rdar://problem/6499801> clang does not detect objc type mismatch in conditional expr
llvm-svn: 64393
2009-02-12 19:05:07 +00:00
Douglas Gregor a9add4ea76 Fix a bug with designated initializers where we were stepping out of a
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
2009-02-12 19:00:39 +00:00
Daniel Dunbar 648bf78333 Support __attribute__(section(<name>))
llvm-svn: 64380
2009-02-12 17:28:23 +00:00
Steve Naroff 0fa412cc6d Turn warning into error. Minor incompatibility with GCC (for scalar types, GCC only produces a warning).
llvm-svn: 64375
2009-02-12 15:54:59 +00:00
Daniel Dunbar 6d0402d468 Fix va_arg bug noticed by Eli, __builtin_va_arg is not an l-value
designating an object.

llvm-svn: 64371
2009-02-12 09:21:08 +00:00
Daniel Dunbar eef883327a Test case for emitting va_arg as l-value; apparently I only *thought* I had committed this.
llvm-svn: 64368
2009-02-12 08:41:10 +00:00
Douglas Gregor 4d0bd8bfc9 Add test for overloading with _Complex in C
llvm-svn: 64347
2009-02-12 00:57:03 +00:00
Douglas Gregor 6752502b81 Expand the definition of a complex promotion to include complex ->
complex conversions where the conversion between the real types is an
integral promotion. This is how G++ handles complex promotions for its
complex integer extension.

llvm-svn: 64344
2009-02-12 00:26:06 +00:00
Douglas Gregor 78ca74d81d Introduce _Complex conversions into the function overloading
system. Since C99 doesn't have overloading and C++ doesn't have
_Complex, there is no specification for    this. Here's what I think
makes sense.

Complex conversions come in several flavors:

  - Complex promotions:  a complex -> complex   conversion where the
    underlying real-type conversion is a floating-point promotion. GCC
    seems to call this a promotion, EDG does something else. This is
    given "promotion" rank for determining the best viable function.
  - Complex conversions: a complex -> complex conversion that is
    not a complex promotion. This is given "conversion" rank for
    determining the best viable   function.
  - Complex-real conversions: a real -> complex or complex -> real
    conversion. This is given "conversion" rank for determining the
    best viable function.

These rules are the same for C99 (when using the "overloadable"
attribute) and C++. However, there is one difference in the handling
of floating-point promotions: in C99, float -> long double and double
-> long double are considered promotions (so we give them "promotion" 
rank), while C++ considers these conversions ("conversion" rank).

llvm-svn: 64343
2009-02-12 00:15:05 +00:00
Steve Naroff 22cc840947 Remove some non-ascii characters. Thanks Gabor.
llvm-svn: 64330
2009-02-11 22:01:48 +00:00
Steve Naroff 7a54c0d7d4 Fix <rdar://problem/6505139> [clang on growl]: need to allow unnamed selectors as the first argument
llvm-svn: 64320
2009-02-11 20:43:13 +00:00