Commit Graph

107 Commits

Author SHA1 Message Date
Daniel Dunbar ce39954d5d Handle constant int -> ptr casts of lvalue results.
- PR3463 (again).

llvm-svn: 65133
2009-02-20 18:22:23 +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 742421e2e7 ExprConstant handling for a couple more cases of pointer-to-int casts
from the testsuite.

llvm-svn: 65098
2009-02-20 01:15:07 +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 cf04aa1a02 Simplify, no functionality change.
llvm-svn: 65073
2009-02-19 22:16:29 +00:00
Mike Stump a67033294a Add enough checking to ensure that non-constant block literals don't
appear to be constant.  I'll probably redo this and throw it all away
later once we have codegen for BlockDeclRefExprs.

llvm-svn: 65070
2009-02-19 22:01:56 +00:00
Daniel Dunbar ca097adca8 Change IntExprEvaluator to operate on an APValue not an APSInt.
- Prep for handling lvalues, no intended functionality change.

llvm-svn: 65063
2009-02-19 20:17:33 +00:00
Daniel Dunbar e3c92bc672 Add another IntExprEvaluator::Success overload to suck up remained of
manual setting of the Result.

 - Idiom now enforces that result will always have correct width and
   type; this exposed three new bugs:

    o Enum constant decl value can have different width than type
      (PR3173).

    o EvaluateInteger should not run an IntExprEvaluator over
      non-integral expressions.

    o FloatExprEvaluate was not handling casts correctly (it was
      evaluating the cast in the IntExprEvaluator!).

llvm-svn: 65053
2009-02-19 18:37:50 +00:00
Daniel Dunbar 8aafc89db8 Add IntExprEvaluator::Success method.
- Handles assignment to Result with appropriate type.

 - Simplifies & encapsulates most direct handling of the Result value;
   prep for allowing IntExprEvaluator to deal with LValue APValues.

 - No intended functionality change.

llvm-svn: 65038
2009-02-19 09:06:44 +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
Mike Stump 5d2534ada7 More codegen for blocks. The type of block literals should be better.
The size calculation is improved.

llvm-svn: 64994
2009-02-19 01:01:04 +00:00
Mike Stump 8dbf1dbdb8 Codegen for int (^bp)(int) = 0;
llvm-svn: 64951
2009-02-18 21:44:49 +00:00
Daniel Dunbar 491812cd76 Rename UnaryTypeTraitExpr::Evaluate to EvaluateTrait to not collide
with Expr::Evaluate().

llvm-svn: 64850
2009-02-17 23:20:26 +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
Fariborz Jahanian ece8582ca2 Renamed ASQualType to ExtQualType to reflect its more
general use; as for, objc2's gc type attributes. No
change in functionality.

llvm-svn: 64778
2009-02-17 18:27:45 +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
Sebastian Redl c9ab3d430b Teach the constant evaluator about C++ const integral variables.
llvm-svn: 64086
2009-02-08 15:51:17 +00:00
Daniel Dunbar 74f2425b89 Evaluate ==,!= for complex types.
llvm-svn: 63280
2009-01-29 06:43:41 +00:00
Daniel Dunbar b6f953e22a Evaluate casts to complex.
- Lift (int,float) -> (int,float) conversion into separate routines.

 - Fix handling of, e.g., char -> _Complex int, which was producing a
   _Complex char value instead.

llvm-svn: 63278
2009-01-29 06:16:07 +00:00
Chris Lattner 60f36223a9 move library-specific diagnostic headers into library private dirs. Reduce
redundant #includes.  Patch by Anders Johnsen!

llvm-svn: 63271
2009-01-29 05:15:15 +00:00
Daniel Dunbar 0aa2606190 Add folding for complex mul and fix some major bugs in complex float
evaluation (alternate part of real/imag init was being set to 3 not 0
because the wrong APFloat constructor was being called).
 - Test cases coming once some more support is in.

llvm-svn: 63264
2009-01-29 01:32:56 +00:00
Daniel Dunbar f50e60b23a Implement basic _Complex integer constant folding.
- Merged into single ComplexEvaluator, these share too much logic to
   be worth splitting for float/int (IMHO). Will split on request.

llvm-svn: 63248
2009-01-28 22:24:07 +00:00
Chris Lattner 7368d581c1 Split the single monolithic DiagnosticKinds.def file into one
.def file for each library.  This means that adding a diagnostic
to sema doesn't require all the other libraries to be rebuilt.

Patch by Anders Johnsen!

llvm-svn: 63111
2009-01-27 18:30:58 +00:00
Eli Friedman c69d454d5a Make the constant folder aware of
__builtin___CFStringMakeConstantString.  (We get into trouble in 
GenerateStaticBlockVarDecl if the constant folder isn't accurate.)

llvm-svn: 62949
2009-01-25 01:54:01 +00:00
Eli Friedman 529a99bcf4 Fix the address of a label to be properly considered and emitted as a
constant.

llvm-svn: 62948
2009-01-25 01:21:06 +00:00
Eli Friedman 2aa38fea35 Refactor sizeof handling to use constant folding logic for constant
sizeof expressions.

llvm-svn: 62941
2009-01-24 22:19:05 +00:00
Chris Lattner 6806131c6b add initial support for the gcc "alignof(decl) is the alignment of the decl
not the type" semantics.  This can definitely be improved, but is better than
what we had.

llvm-svn: 62939
2009-01-24 21:53:27 +00:00
Chris Lattner 24aeeab05c Improve handling of alignof. alignof(VLA) now works properly for example.
llvm-svn: 62932
2009-01-24 21:09:06 +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
Nate Begeman 2f2bdeb5df Support evaluation of vector constant expressions, and codegen of same.
llvm-svn: 62455
2009-01-18 03:20:47 +00:00
Fariborz Jahanian dae9276090 postpone sizeof objc-class computatin to the clients.
llvm-svn: 62292
2009-01-16 01:42:12 +00:00
Daniel Dunbar 435bbe0254 Fix some unused variable, control reaches end of non-void function,
and uninitialized use options.

llvm-svn: 62270
2009-01-15 18:32:35 +00:00
Sebastian Redl baad4e765f PODness and Type Traits
Make C++ classes track the POD property (C++ [class]p4)
Track the existence of a copy assignment operator.
Implicitly declare the copy assignment operator if none is provided.
Implement most of the parsing job for the G++ type traits extension.
Fully implement the low-hanging fruit of the type traits:
__is_pod: Whether a type is a POD.
__is_class: Whether a type is a (non-union) class.
__is_union: Whether a type is a union.
__is_enum: Whether a type is an enum.
__is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1).

llvm-svn: 61746
2009-01-05 20:52:13 +00:00
Anders Carlsson 39def3adc8 Add codegen support for __null
llvm-svn: 61314
2008-12-21 22:39:40 +00:00
Douglas Gregor 2eedc3aa1c Add support for member references (E1.E2, E1->E2) with C++ semantics,
which can refer to static data members, enumerators, and member
functions as well as to non-static data members.

Implement correct lvalue computation for member references in C++. 
Compute the result type of non-static data members of reference type properly.

llvm-svn: 61294
2008-12-20 23:49:58 +00:00
Anders Carlsson 6736d1a2bb Get rid of the old Expr::Evaluate variant.
llvm-svn: 61260
2008-12-19 20:58:05 +00:00
Douglas Gregor 91f84216f7 Unifies the name-lookup mechanisms used in various parts of the AST
and separates lexical name lookup from qualified name lookup. In
particular:
  * Make DeclContext the central data structure for storing and
    looking up declarations within existing declarations, e.g., members
    of structs/unions/classes, enumerators in C++0x enums, members of
    C++ namespaces, and (later) members of Objective-C
    interfaces/implementations. DeclContext uses a lazily-constructed
    data structure optimized for fast lookup (array for small contexts,
    hash table for larger contexts). 

  * Implement C++ qualified name lookup in terms of lookup into
    DeclContext.

  * Implement C++ unqualified name lookup in terms of
    qualified+unqualified name lookup (since unqualified lookup is not
    purely lexical in C++!)

  * Limit the use of the chains of declarations stored in
    IdentifierInfo to those names declared lexically.

  * Eliminate CXXFieldDecl, collapsing its behavior into
    FieldDecl. (FieldDecl is now a ScopedDecl).

  * Make RecordDecl into a DeclContext and eliminates its
    Members/NumMembers fields (since one can just iterate through the
    DeclContext to get the fields).

llvm-svn: 60878
2008-12-11 16:49:14 +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
Anders Carlsson 98463cd44d This wasn't such a good idea after all as it broke some tests.
llvm-svn: 60582
2008-12-05 05:24:13 +00:00
Anders Carlsson 3bc1d7d3d3 Handle __builtin___CFStringMakeConstantString in Expr::Evaluate.
llvm-svn: 60581
2008-12-05 05:18:05 +00:00
Anders Carlsson 5b3638b6e7 Generate the correct results for the comma expression. Fixes PR3123.
llvm-svn: 60334
2008-12-01 06:44:05 +00:00
Anders Carlsson 564730a857 Emit the correct diagnostic when a comma is in an ICE.
llvm-svn: 60316
2008-12-01 02:07:06 +00:00
Anders Carlsson b33d6c8611 Change the diagnostics that the evaluator reports to be of type NOTE.
llvm-svn: 60301
2008-11-30 18:37:00 +00:00
Anders Carlsson 5862001157 Replace the isEvaluated bool with a ShortCircuit int, making it easier to handle recursion
llvm-svn: 60300
2008-11-30 18:26:25 +00:00
Anders Carlsson 27b8c5c464 Pass the expression to the Error and Extension methods.
llvm-svn: 60299
2008-11-30 18:14:57 +00:00
Anders Carlsson 7b6f0af83f Add a new variant of Evaluate and reimplement the old Evaluate in terms of the new.
llvm-svn: 60298
2008-11-30 16:58:53 +00:00
Anders Carlsson f50de0c590 General cleanup, evaluate the RHS of a logical op even if the LHS will give us the result.
llvm-svn: 60297
2008-11-30 16:51:17 +00:00
Anders Carlsson bd1df8e866 EvalInfo now holds a reference to an EvalResult struct.
llvm-svn: 60296
2008-11-30 16:38:33 +00:00
Nuno Lopes 615f34c719 remove debug-only assertion in the complex float evaluator as it makes some real apps crash
llvm-svn: 60069
2008-11-26 00:39:53 +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