template argument (described by an expression, of course). For
example:
template<int...> struct int_tuple { };
template<int ...Values>
struct square {
typedef int_tuple<(Values*Values)...> type;
};
It also lays the foundation for pack expansions in an initializer-list.
llvm-svn: 122751
new gcc warning that complains on self-assignments and
self-initializations. Fix one bug found by the warning, in which one
clang::OverloadCandidate constructor failed to initialize its
FunctionTemplate member.
llvm-svn: 122459
zextOrTrunc(), and APSInt methods extend(), extOrTrunc() and new method
trunc(), to be const and to return a new value instead of modifying the
object in place.
llvm-svn: 121121
implicit conversions; the last batch was specific to promotions.
I think this is the full set we need. I do think dividing the cast
kinds into floating and integral is probably a good idea.
Annotate a *lot* more C casts with useful cast kinds.
llvm-svn: 119036
own subcategory, -Wconstant-conversion, which is on by default.
Tweak the constant folder to give better results in the invalid
case of a negative shift amount.
Implements rdar://problem/6792488
llvm-svn: 118636
initializers, so the result of the evaluation doesn't leak through
inconsistently. Also, don't evaluate references to variables with
initializers with side-effects.
llvm-svn: 113128
The extra data stored on user-defined literal Tokens is stored in extra
allocated memory, which is managed by the PreprocessorLexer because there isn't
a better place to put it that makes sure it gets deallocated, but only after
it's used up. My testing has shown no significant slowdown as a result, but
independent testing would be appreciated.
llvm-svn: 112458
just means "not a function type", not "not a function type or void". This
changes behavior slightly, but generally in a way which accepts more code.
llvm-svn: 110303
reinterpret_casts (possibly indirectly via C-style/functional casts)
on values, e.g.,
int i;
reinterpret_cast<short&>(i);
The IR generated for this is essentially the same as for
*reinterpret_cast<short*>(&i).
Fixes PR6437, PR7593, and PR7344.
llvm-svn: 108294
in C++ that involve both integral and enumeration types. Convert all
of the callers to Type::isIntegralType() that are meant to work with
both integral and enumeration types over to
Type::isIntegralOrEnumerationType(), to prepare to eliminate
enumeration types as integral types.
llvm-svn: 106071
initializer, don't fold paramters. Their initializers are just default
arguments which can be overridden. This fixes some spectacular regressions due
to more things making it into the constant folding.
llvm-svn: 103904
of constant-evaluation. Formerly you could control whether it accepted
local l-values or not; now it always evaluates local l-values in the core
routines, but filters them out where consumed by the top-level routines.
This will make it much easier to cache evaluability.
llvm-svn: 103444
but whose operand isn't a float: specifically, __real__ and __imag__. Instead
of filtering these out, just implement them.
Fixes <rdar://problem/7958272>.
llvm-svn: 103307
classes, since we only warn (not error) on offsetof() for non-POD
types. We store the base path within the OffsetOfExpr itself, then
evaluate the offsets within the constant evaluator.
llvm-svn: 102571
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
thing. Audit all uses of Type::isStructure(), changing those calls to
isStructureOrClassType() as needed (which is alsmost
everywhere). Fixes the remaining failure in Boost.Utility/Swap.
llvm-svn: 102386
expression computation in the wrong bit-width, and end up generating a totally
bogus array reference (_g0+8589934546).
- This showed up on Prolangs/cdecl.
llvm-svn: 99042
void f(int a = 10) {
return a;
}
would always return 10, regardless of the passed in argument.
This fixes another 600 test failures. We're now down to only 137 failures!
llvm-svn: 95262
"ASTContext::getTypeSize() / 8". Replace [u]int64_t variables with CharUnits
ones as appropriate.
Also rename RawType, fromRaw(), and getRaw() in CharUnits to QuantityType,
fromQuantity(), and getQuantity() for clarity.
llvm-svn: 93153
try to evaluate an expression as a constant boolean condition. This has
the same intended semantics as used in folding conditional operators.
llvm-svn: 92805
only takes a boolean second argument now. Update tests accordingly.
Currently the builtin still accepts the full range for compatibility.
llvm-svn: 91983
static member constants. No significant visible difference at the moment
because it conservatively assumes the base has side effects. I'm planning to
use this for CodeGen.
llvm-svn: 89738
integral constant expression, make sure to find where the initializer
was provided---inside or outside the class definition---since that can
affect whether we have an integral constant expression (and, we need
to see the initializer itself).
llvm-svn: 85741
using the new LLVM support for this. This is temporarily hiding
behind horrible and ugly #ifdefs until the time when the optimizer
is stable (hopefully a week or so). Until then, lets make it "opt in" :)
llvm-svn: 85446
side-effects up front, as when we switch to the llvm intrinsic call
for __builtin_object_size later, it will have two evaluations.
We also finish off the intrinsic version of the code so we can just
turn it on once llvm has the intrinsic.
llvm-svn: 85324
Type hierarchy. Demote 'volatile' to extended-qualifier status. Audit our
use of qualifiers and fix a few places that weren't dealing with qualifiers
quite right; many more remain.
llvm-svn: 82705
Several of the existing methods were identical to their respective
specializations, and so have been removed entirely. Several more 'leaf'
optimizations were introduced.
The getAsFoo() methods which imposed extra conditions, like
getAsObjCInterfacePointerType(), have been left in place.
llvm-svn: 82501
Type::getAsReferenceType() -> Type::getAs<ReferenceType>()
Type::getAsRecordType() -> Type::getAs<RecordType>()
Type::getAsPointerType() -> Type::getAs<PointerType>()
Type::getAsBlockPointerType() -> Type::getAs<BlockPointerType>()
Type::getAsLValueReferenceType() -> Type::getAs<LValueReferenceType>()
Type::getAsRValueReferenceType() -> Type::getAs<RValueReferenceType>()
Type::getAsMemberPointerType() -> Type::getAs<MemberPointerType>()
Type::getAsReferenceType() -> Type::getAs<ReferenceType>()
Type::getAsTagType() -> Type::getAs<TagType>()
And remove Type::getAsReferenceType(), etc.
This change is similar to one I made a couple weeks ago, but that was partly
reverted pending some additional design discussion. With Doug's pending smart
pointer changes for Types, it seemed natural to take this approach.
llvm-svn: 77510
and __has_trivial_constructor builtin pseudo-functions and
additionally implements __has_trivial_copy and __has_trivial_assign,
from John McCall!
llvm-svn: 76916
until Doug Gregor's Type smart pointer code lands (or more discussion occurs).
These methods just call the new Type::getAs<XXX> methods, so we still have
reduced implementation redundancy. Having explicit getAsXXXType() methods makes
it easier to set breakpoints in the debugger.
llvm-svn: 76193
This method is intended to eventually replace the individual
Type::getAsXXXType<> methods.
The motivation behind this change is twofold:
1) Reduce redundant implementations of Type::getAsXXXType() methods. Most of
them are basically copy-and-paste.
2) By centralizing the implementation of the getAs<Type> logic we can more
smoothly move over to Doug Gregor's proposed canonical type smart pointer
scheme.
Along with this patch:
a) Removed 'Type::getAsPointerType()'; now clients use getAs<PointerType>.
b) Removed 'Type::getAsBlockPointerTypE()'; now clients use getAs<BlockPointerType>.
llvm-svn: 76098
The idea is to segregate Objective-C "object" pointers from general C pointers (utilizing the recently added ObjCObjectPointerType). The fun starts in Sema::GetTypeForDeclarator(), where "SomeInterface *" is now represented by a single AST node (rather than a PointerType whose Pointee is an ObjCInterfaceType). Since a significant amount of code assumed ObjC object pointers where based on C pointers/structs, this patch is very tedious. It should also explain why it is hard to accomplish this in smaller, self-contained patches.
This patch does most of the "heavy lifting" related to moving from PointerType->ObjCObjectPointerType. It doesn't include all potential "cleanups". The good news is additional cleanups can be done later (some are noted in the code). This patch is so large that I didn't want to include any changes that are purely aesthetic.
By making the ObjC types truly built-in, they are much easier to work with (and require fewer "hacks"). For example, there is no need for ASTContext::isObjCIdStructType() or ASTContext::isObjCClassStructType()! We believe this change (and the follow-up cleanups) will pay dividends over time.
Given the amount of code change, I do expect some fallout from this change (though it does pass all of the clang tests). If you notice any problems, please let us know asap! Thanks.
llvm-svn: 75314
For ExtVectorType, initializer is splatted to all elements.
For VectorType, initializer is bitcast to vector type.
Verified that for VectorType, output is identical to gcc.
llvm-svn: 74600
Remove ASTContext parameter from DeclContext's methods. This change cascaded down to other Decl's methods and changes to call sites started "escalating".
Timings using pre-tokenized "cocoa.h" showed only a ~1% increase in time run between and after this commit.
llvm-svn: 74506
preprocessor and initialize it early in clang-cc. This
ensures that __has_builtin works in all modes, not just
when ASTContext is around.
llvm-svn: 73319
an integral constant expression, maintain a cache of the value and the
is-an-ICE flag within the VarDecl itself. This eliminates
exponential-time behavior of the Fibonacci template metaprogram.
llvm-svn: 72428
"aligned" attribute. Previously, we were skipping over these
attributes when we jumped directly to the canonical type. Now,
ASTContext::getTypeInfo walks through typedefs and other
"non-canonical" types manually, looking for "aligned" attributes on
typedefs.
As part of this change, I moved the GNU-specific logic (such as
determining the alignment of void or of a function pointer) out of the
expression evaluator and into ASTContext::getTypeInfo.
llvm-svn: 70497
addRecordToClass.
- Among other things, this fixes a crash when applying sizeof to an
interface with synthesized ivars, although things still aren't
"correct" here.
llvm-svn: 69675
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
- For types whose native representation is a pointer.
- Use to replace ExprConstant.cpp:HasPointerEvalType,
CodeGenFunction::isObjCPointerType.
llvm-svn: 65569
pretty sure we want to keep constant expression verification outside of
Evaluate. Because of that, the short-circuit evaluation doesn't
generally make sense, and the comma warning doesn't make sense in its
current form.
llvm-svn: 65525
I know, these follow the exact same rules as pointers, so I just made
them use the same codepath. Someone more familiar with ObjC should
double-check this, though.
llvm-svn: 65261
- 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
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
- 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
- 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
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
- 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
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
.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
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
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
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
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
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
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
- 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
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
crashing because we errors are ignored in subexpressions that are not evaluated,
but we still evaluate the result of parents. This would cause an assertion
because the erroneous subexpr didn't have its result value set to the right type.
llvm-svn: 59110
- Kill unnecessary #includes in .cpp files. This is an automatic
sweep so some things removed are actually used, but happen to be
included by a previous header. I tried to get rid of the obvious
examples and this was the easiest way to trim the #includes in one
fell swoop.
- We now return to regularly scheduled development.
llvm-svn: 54632