Commit Graph

3691 Commits

Author SHA1 Message Date
Fariborz Jahanian 26d8371b07 objc: allow block pointer matching 'id' type when
they show up as argument types of two block pointers.
// rdar://10734265

llvm-svn: 149007
2012-01-26 00:45:38 +00:00
Richard Smith 1b78b3d1b1 constexpr: add support for anonymous struct and union members in literal types.
llvm-svn: 148987
2012-01-25 22:15:11 +00:00
Richard Smith 928be491e0 Fix PR11848: decree that an alias template contains an unexpanded parameter pack
iff its substitution contains an unexpanded parameter pack. This has the effect
that we now reject declarations such as this (which we used to crash when
expanding):

  template<typename T> using Int = int;
  template<typename ...Ts> void f(Int<Ts> ...ints);

The standard is inconsistent on how this case should be treated.

llvm-svn: 148905
2012-01-25 02:14:59 +00:00
Douglas Gregor 63db9717a5 Only try to import a definition if there is an definition to import.
llvm-svn: 148894
2012-01-25 01:13:20 +00:00
Douglas Gregor 95d8283931 When importing a RecordDecl as a DeclContext, make sure that we pull
in the definition as well.

llvm-svn: 148831
2012-01-24 18:36:04 +00:00
Douglas Gregor 2aa53777e7 Teach the AST importer about redeclaration chains for Objective-C
classes and protocols, implementing lazy-import semantics for both.

llvm-svn: 148816
2012-01-24 17:42:07 +00:00
Argyrios Kyrtzidis 034e83ca17 In CXXRecordDecl::isCLike(), also check for PODness.
llvm-svn: 148765
2012-01-24 01:37:11 +00:00
Argyrios Kyrtzidis 5c4e065a9a Introduce CXXRecordDecl::isCLike() that is true if the class is C-like,
without C++-specific features.

Use it to set the language to C++ when indexing non-C-like structs.
rdar://10732579

llvm-svn: 148708
2012-01-23 16:58:45 +00:00
David Blaikie e4d798f078 More dead code removal (using -Wunreachable-code)
llvm-svn: 148577
2012-01-20 21:50:17 +00:00
Ted Kremenek f2a2f5f2bf Add ability to specifiy 'restrict' on parameters of builtins, and correct this oversight for scanf functions.
llvm-svn: 148573
2012-01-20 21:40:12 +00:00
Richard Smith 66e05fe630 Move narrowing conversion detection code from SemaInit to SemaOverload, ready
for it to be used in converted constant expression checking, and fix a couple
of issues:
 - Conversion operators implicitly invoked prior to the narrowing conversion
   were not being correctly handled when determining whether a constant value
   was narrowed.
 - For conversions from floating-point to integral types, the diagnostic text
   incorrectly always claimed that the source expression was not a constant
   expression.

llvm-svn: 148381
2012-01-18 05:21:49 +00:00
Richard Smith 9cf080fba3 A call to strlen is not a constant expression, even if we're treating it as a
builtin.

llvm-svn: 148374
2012-01-18 03:06:12 +00:00
Anna Zaks 28db7ceabd Constify FunctionDecl::getmemoryFunctionKind().
llvm-svn: 148369
2012-01-18 02:45:01 +00:00
Richard Smith 4ef685becf Enable constant evaluation of implicit calls to constexpr conversion operators.
llvm-svn: 148333
2012-01-17 21:17:26 +00:00
Douglas Gregor d53ae83516 Delay the creation of the built-in Objective-C class 'Protocol' by
moving it from a "special type" to a predefined declaration, as we do
for id, Class, and SEL.

llvm-svn: 148313
2012-01-17 18:09:05 +00:00
David Blaikie 8a40f700e6 Remove unreachable code in Clang. (replace with llvm_unreachable where appropriate or when GCC requires it)
llvm-svn: 148292
2012-01-17 06:56:22 +00:00
David Blaikie f47fa304a4 Remove unnecessary default cases in switches over enums.
This allows -Wswitch-enum to find switches that need updating when these enums are modified.

llvm-svn: 148281
2012-01-17 02:30:50 +00:00
Anna Zaks 2212270e71 Use Builtin ID as the return value
for FunctionDecl::getMemoryFunctionKind().

This is a follow up on the Chris's review for r148142: We don't want to
pollute FunctionDecl with an extra enum. (To make this work, added
memcmp and family to the library builtins.)

llvm-svn: 148267
2012-01-17 00:37:07 +00:00
David Chisnall fa35df628a Some improvements to the handling of C11 atomic types:
- Add atomic-to/from-nonatomic cast types
- Emit atomic operations for arithmetic on atomic types
- Emit non-atomic stores for initialisation of atomic types, but atomic stores and loads for every other store / load
- Add a __atomic_init() intrinsic which does a non-atomic store to an _Atomic() type.  This is needed for the corresponding C11 stdatomic.h function.
- Enables the relevant __has_feature() checks.  The feature isn't 100% complete yet, but it's done enough that we want people testing it.

Still to do:

- Make the arithmetic operations on atomic types (e.g. Atomic(int) foo = 1; foo++;) use the correct LLVM intrinsic if one exists, not a loop with a cmpxchg.
- Add a signal fence builtin
- Properly set the fenv state in atomic operations on floating point values
- Correctly handle things like _Atomic(_Complex double) which are too large for an atomic cmpxchg on some platforms (this requires working out what 'correctly' means in this context)
- Fix the many remaining corner cases

llvm-svn: 148242
2012-01-16 17:27:18 +00:00
Douglas Gregor c03c52ea01 When deserializing the definition of a C++ class/ObjC class/ObjC
protocol, record the definition pointer in the canonical declaration
for that entity, and then propagate that definition pointer from the
canonical declaration to all other deserialized declarations. This
approach works well even when deserializing declarations that didn't
know about the original definition, which can occur with modules.

A nice bonus from this definition-deserialization approach is that we
no longer need update records when a definition is added, because the
redeclaration chains ensure that the if any declaration is loaded, the
definition will also get loaded.

llvm-svn: 148223
2012-01-15 18:08:05 +00:00
Richard Smith bd1530949d decltype(e) is type-dependent if e is instantiation-dependent. Scary but true.
Don't consider decltype(e) for an instantiation-dependent, but not
type-dependent, e to be non-type-dependent but canonical(!).

llvm-svn: 148210
2012-01-15 06:24:57 +00:00
Richard Smith b19ac0d6ca constexpr: casts to void* are allowed in constant expressions, don't set the
designator invalid. (Since we can't read the value of such a pointer, this only
affects the quality of diagnostics.)

llvm-svn: 148208
2012-01-15 03:25:41 +00:00
Eli Friedman 839192fd29 Change linkage computation so it doesn't depend on FunctionDecl::isExternC or VarDecl::isExternC, and instead queries what it actually cares about: whether the given declaration is inside an extern "C" context. Fundamentally, figuring out whether a function/variable uses C linkage requires knowing the linkage, and the logic in FunctionDecl::isExternC and VarDecl::isExternC was getting it wrong. Given that, fix FunctionDecl::isExternC and VarDecl::isExternC to use much simpler implementations that depend on the fixed linkage computation.
Fixes a regression to test/SemaCXX/linkage.cpp caused by a new warning exposing the fact that the internal state was wrong.

llvm-svn: 148207
2012-01-15 01:23:58 +00:00
Douglas Gregor ec9fd13c77 De-virtualize getPreviousDecl() and getMostRecentDecl() when we know
we have a redeclarable type, and only use the new virtual versions
(getPreviousDeclImpl() and getMostRecentDeclImpl()) when we don't have
that type information. This keeps us from penalizing users with strict
type information (and is the moral equivalent of a "final" method).

Plus, settle on the names getPreviousDecl() and getMostRecentDecl()
throughout.

llvm-svn: 148187
2012-01-14 16:38:05 +00:00
Douglas Gregor 463c8e7070 Add a FIXME for mutation of the common pointer of a RedeclarableTemplateDecl. It is not clear that it's worth delaying the allocation of said pointer
llvm-svn: 148182
2012-01-14 15:30:55 +00:00
Douglas Gregor 68444de354 Reimplement RedeclarableTemplateDecl in terms of
Redeclarable<RedeclarableTemplateDecl>, eliminating a bunch of
redeclaration-chain logic both in RedeclarableTemplateDecl and
especially in its (de-)serialization.

As part of this, eliminate the RedeclarableTemplate<> class template,
which was an abstraction that didn't actually save anything.

llvm-svn: 148181
2012-01-14 15:13:49 +00:00
Richard Smith dafff94759 constexpr irgen: Add irgen support for APValue::Struct, APValue::Union,
APValue::Array and APValue::MemberPointer. All APValue values can now be emitted
as constants.

Add new CGCXXABI entry point for emitting an APValue MemberPointer. The other
entrypoints dealing with constant member pointers are no longer necessary and
will be removed in a later change.

Switch codegen from using EvaluateAsRValue/EvaluateAsLValue to
VarDecl::evaluateValue. This performs caching and deals with the nasty cases in
C++11 where a non-const object's initializer can refer indirectly to
previously-initialized fields within the same object.

Building the intermediate APValue object incurs a measurable performance hit on
pathological testcases with huge initializer lists, so we continue to build IR
directly from the Expr nodes for array and record types outside of C++11.

llvm-svn: 148178
2012-01-14 04:30:29 +00:00
Rafael Espindola 2f869a3f4f Remember if a type has its visibility set explicitly or implicitly.
With that, centralize the way we merge visibility, always preferring explicit over
implicit and then picking the most restrictive one.
Fixes pr10113 and pr11690.

llvm-svn: 148163
2012-01-14 00:30:36 +00:00
Eli Friedman 1c29e7297a Fix a silly mistake in ComplexExprEvaluator::ZeroInitialization. <rdar://problem/10691092>.
llvm-svn: 148157
2012-01-13 23:34:56 +00:00
Anna Zaks 201d489cb8 Move identification of memory setting and copying functions (memset,
memcmp, strncmp,..) out of Sema and into FunctionDecl so that the logic
could be reused in the analyzer.

llvm-svn: 148142
2012-01-13 21:52:01 +00:00
Eli Friedman 2e108376d5 Recommit r148056 with fixes to deal with weirdness with bitfields in unions.
Original message: Make sure adding a field to a struct never reduces its size.  PR11745.

llvm-svn: 148070
2012-01-12 23:48:56 +00:00
Eli Friedman 43f1834fad Revert r148056 while I investigate failures.
llvm-svn: 148068
2012-01-12 23:27:03 +00:00
Eli Friedman 8c89d125ff Make sure adding a field to a struct never reduces its size. PR11745.
llvm-svn: 148056
2012-01-12 22:41:25 +00:00
Argyrios Kyrtzidis 0037e08811 If an ObjCMessageExpr is implicit, there are no source locations for the
selector identifiers.

It was difficult to form a test case for it unfortunately.

llvm-svn: 148053
2012-01-12 22:34:19 +00:00
Richard Smith 9eae723c18 constexpr: initialization of a union from an empty initializer-list should
zero-initialize the first union member. Also fix a bug where initializing an
array of types compatible with wchar_t from a wide string literal failed in C,
and fortify the C++ tests in this area. This part can't be tested without a code
change to enable array evaluation in C (where an existing test fails).

llvm-svn: 148035
2012-01-12 18:54:33 +00:00
Richard Smith 02ab9c2940 Allow constant-folding of references which were formed in a manner not permitted
in a constant expression, for compatibility with g++.

llvm-svn: 148020
2012-01-12 06:08:57 +00:00
Argyrios Kyrtzidis a80f1bf262 Add IsImplicit field in ObjCMessageExpr that is true when the message
was constructed, e.g. for a property access.

This allows the selector identifier locations machinery for ObjCMessageExpr
to function correctly, in that there are not real locations to handle/report for
such a message.

llvm-svn: 148013
2012-01-12 02:34:39 +00:00
Richard Smith c101e61d31 constexpr: fix typo resulting in move constructors sometimes not being
implicitly marked constexpr when they should be.

llvm-svn: 147955
2012-01-11 18:26:05 +00:00
Akira Hatanaka 428f5b2008 Add field IsIEEE in FloatingLiteral to distinguish between different 128-bit
floating point formats.

llvm-svn: 147887
2012-01-10 22:40:09 +00:00
Eli Friedman c4b251dc2b Implement the missing pieces of Evaluate for _Complex types. With that complete, remove some code from CGExprConstant which is no longer necessary. While I'm here, a couple minor tweaks to _Complex-in-C++. (Specifically, make _Complex types literal types, and don't warn for _Complex int.)
llvm-svn: 147840
2012-01-10 04:58:17 +00:00
Richard Smith 1bc5c2c7ef PR11724: Implement evaluation for constexpr defaulted trivial union copy/move
constructors. These are a special case whose behavior cannot be modeled as a
user-written constructor.

llvm-svn: 147839
2012-01-10 04:32:03 +00:00
Douglas Gregor cfe7dc6b2f Implement redeclaration merging for namespaces defined in distinct
modules. Teach name lookup into namespaces to search in each of the
merged DeclContexts as well as the (now-primary) DeclContext. This
supports the common case where two different modules put something
into the same namespace.

llvm-svn: 147778
2012-01-09 17:30:44 +00:00
Benjamin Kramer e78f8ee57f Pack UsingDecl more.
88 -> 80 bytes on x86_64.

llvm-svn: 147736
2012-01-07 19:09:05 +00:00
Douglas Gregor e57e752b71 Switch NamespaceDecl from its own hand-rolled redeclaration chain over
to Redeclarable<NamespaceDecl>, so that we benefit from the improveed
redeclaration deserialization and merging logic provided by
Redeclarable<T>. Otherwise, no functionality change.

As a drive-by fix, collapse the "inline" bit into the low bit of the
original namespace/anonymous namespace, saving 8 bytes per
NamespaceDecl on x86_64.

llvm-svn: 147729
2012-01-07 09:11:48 +00:00
Eli Friedman 73a040906d More lambda work: semantic analysis of capturing 'this'. It's a bit complicated, but we have to be careful about when exactly captures are marked given PotentiallyPotentiallyEvaluated contexts. (Actually, it's not 100% correct yet, but it's close enough for the moment.)
llvm-svn: 147723
2012-01-07 04:59:52 +00:00
Eli Friedman 48fd89ad14 Revert r147664; it's breaking clang regression tests.
llvm-svn: 147681
2012-01-06 20:42:20 +00:00
Jakub Staszak a78c20d734 Silence GCC warnings.
llvm-svn: 147664
2012-01-06 17:44:30 +00:00
Douglas Gregor 781f713deb Stash Decl's TopLevelDeclInObjCContainer and ModulePrivate bits
into the two unused lower bits of the NextDeclInContext link, dropping
the number of bits in Decl down to 32, and saving 8 bytes per
declaration on x86-64.

llvm-svn: 147660
2012-01-06 16:59:53 +00:00
Richard Smith a8105bc9ce C++11 generalized constant expressions: implement checking and diagnostics for
pointer-arithmetic-related undefined behavior and unspecified results. We
continue to fold such values, but now notice they aren't constant expressions.

llvm-svn: 147659
2012-01-06 16:39:00 +00:00
John McCall 8ba2f20bc0 Fix the mangling of class template arguments in a particular
dependent case.  Thanks to Jason Merrill for pointing this out.

llvm-svn: 147653
2012-01-06 05:06:35 +00:00