summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/Sema.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Rework when and how vtables are emitted, by tracking where vtables areDouglas Gregor2010-05-131-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "used" (e.g., we will refer to the vtable in the generated code) and when they are defined (i.e., because we've seen the key function definition). Previously, we were effectively tracking "potential definitions" rather than uses, so we were a bit too eager about emitting vtables for classes without key functions. The new scheme: - For every use of a vtable, Sema calls MarkVTableUsed() to indicate the use. For example, this occurs when calling a virtual member function of the class, defining a constructor of that class type, dynamic_cast'ing from that type to a derived class, casting to/through a virtual base class, etc. - For every definition of a vtable, Sema calls MarkVTableUsed() to indicate the definition. This happens at the end of the translation unit for classes whose key function has been defined (so we can delay computation of the key function; see PR6564), and will also occur with explicit template instantiation definitions. - For every vtable defined/used, we mark all of the virtual member functions of that vtable as defined/used, unless we know that the key function is in another translation unit. This instantiates virtual member functions when needed. - At the end of the translation unit, Sema tells CodeGen (via the ASTConsumer) which vtables must be defined (CodeGen will define them) and which may be used (for which CodeGen will define the vtables lazily). From a language perspective, both the old and the new schemes are permissible: we're allowed to instantiate virtual member functions whenever we want per the standard. However, all other C++ compilers were more lazy than we were, and our eagerness was both a performance issue (we instantiated too much) and a portability problem (we broke Boost test cases, which now pass). Notes: (1) There's a ton of churn in the tests, because the order in which vtables get emitted to IR has changed. I've tried to isolate some of the larger tests from these issues. (2) Some diagnostics related to implicitly-instantiated/implicitly-defined virtual member functions have moved to the point of first use/definition. It's better this way. (3) I could use a review of the places where we MarkVTableUsed, to see if I missed any place where the language effectively requires a vtable. Fixes PR7114 and PR6564. llvm-svn: 103718
* Delete a dead function at sabre's request.Chandler Carruth2010-05-131-11/+0
| | | | llvm-svn: 103705
* Merged Elaborated and QualifiedName types.Abramo Bagnara2010-05-111-2/+2
| | | | llvm-svn: 103517
* Rearchitect -Wconversion and -Wsign-compare. Instead of computing themJohn McCall2010-05-061-2/+0
| | | | | | | | | | | | | | "bottom-up" when implicit casts and comparisons are inserted, compute them "top-down" when the full expression is finished. Makes it easier to coordinate warnings and thus implement -Wconversion for signedness conversions without double-warning with -Wsign-compare. Also makes it possible to realize that a signedness conversion is okay because the context is performing the inverse conversion. Also simplifies some logic that was trying to calculate the ultimate comparison/result type and getting it wrong. Also fixes a problem with the C++ explicit casts which are often "implemented" in the AST with a series of implicit cast expressions. llvm-svn: 103174
* Add base paths to CK_UncheckedDerivedToBase and CK_DerivedToBaseMemberPointer.Anders Carlsson2010-04-241-2/+1
| | | | llvm-svn: 102260
* CastExpr should not hold a pointer to the base path. More cleanup.Anders Carlsson2010-04-241-3/+2
| | | | llvm-svn: 102249
* Rename InheritancePath to BasePath, rename CastExpr::CXXBaseVector to ↵Anders Carlsson2010-04-241-4/+3
| | | | | | CXXBaseSpecifierArray. More to come. llvm-svn: 102245
* Add an InheritancePath parameter to the ImplicitCastExpr constructor.Anders Carlsson2010-04-231-2/+6
| | | | llvm-svn: 102218
* Remove all "used" static functions *after* we have performed all ofDouglas Gregor2010-04-091-8/+7
| | | | | | | | | the implicit template instantiations we need to perform. Otherwise, we end up erroneously diagnosing static functions as used if they were only used within an implicit template instantiation. Fixes a bunch of spurious failures when building Clang with Clang. llvm-svn: 100872
* Teach the diagnostic engine to provide more detailed information aboutDouglas Gregor2010-03-251-0/+24
| | | | | | | | | how to handle a diagnostic during template argument deduction, which may be "substitution failure", "suppress", or "report". This keeps us from, e.g., emitting warnings while performing template argument deduction. llvm-svn: 99560
* Only perform CFG-based warnings on 'static inline' functions thatTed Kremenek2010-03-231-1/+2
| | | | | | | are called (transitively) by regular functions/blocks within a translation untion. llvm-svn: 99233
* Remove the capture, serialization, and deserialization of commentDouglas Gregor2010-03-191-5/+0
| | | | | | | | ranges as part of the ASTContext. This code is not and was never used, but contributes ~250k to the size of the Cocoa.h precompiled header. llvm-svn: 99007
* Keep an explicit stack of function and block scopes, each element ofDouglas Gregor2010-03-011-4/+60
| | | | | | | | | | | | | | | | | | | | which has the label map, switch statement stack, etc. Previously, we had a single set of maps in Sema (for the function) along with a stack of block scopes. However, this lead to funky behavior with nested functions, e.g., in the member functions of local classes. The explicit-stack approach is far cleaner, and we retain a 1-element cache so that we're not malloc/free'ing every time we enter a function. Fixes PR6382. Also, tweaked the unused-variable warning suppression logic to look at errors within a given Scope rather than within a given function. The prior code wasn't looking at the right number-of-errors count when dealing with blocks, since the block's count would be deallocated before we got to ActOnPopScope. This approach works with nested blocks/functions, and gives tighter error recovery. llvm-svn: 97518
* Implement jump checking for initialized c++ variables, implementingChris Lattner2010-03-011-0/+2
| | | | | | | | | | | | | | | | | | a fixme and PR6451. Only perform jump checking if the containing function has no errors, and add the infrastructure needed to do this. On the testcase in the PR, we produce: t.cc:6:3: error: illegal goto into protected scope goto later; ^ t.cc:7:5: note: jump bypasses variable initialization X x; ^ llvm-svn: 97497
* Implementing unused function warning.Tanya Lattner2010-02-121-0/+15
| | | | llvm-svn: 95940
* Move the diagnostic argument formatting function out of Sema and makeDouglas Gregor2010-02-091-245/+3
| | | | | | | it available within the AST library, of which Sema is one client. No functionality change. llvm-svn: 95701
* Add a stop gap to Sema::CorrectTypo() to correct only up to 20 typos.Ted Kremenek2010-02-021-1/+1
| | | | | | | | | | | | | | | | | This is to address a serious performance problem observed when running 'clang -fsyntax-only' on really broken source files. In one case, repeatedly calling CorrectTypo() caused one source file to be rejected after 2 minutes instead of 1 second. This patch causes typo correction to take neglible time on that file while still providing correction results for the first 20 cases. I felt this was a reasonable number for moderately broken source files. I don't claim this is the best solution. Comments welcome. It is necessary for us to address this issue because it is a serious performance problem. llvm-svn: 95049
* Add VarDecl::isThisDeclarationADefinition(), which properly encapsulates the ↵Sebastian Redl2010-01-311-6/+9
| | | | | | logic for when a variable declaration is a (possibly tentativ) definition. Add a few functions building on this, and shift C tentative definition handling over to this new functionality. This shift also kills the Sema::TentativeDefinitions map and instead simply stores all declarations in the renamed list. The correct handling for multiple tentative definitions is instead shifted to the final walk of the list. llvm-svn: 94968
* Don't a.k.a. through the primary typedef of an anonymous tag decl.John McCall2010-01-131-0/+6
| | | | llvm-svn: 93362
* Generalize target weirdness handling having proper layering in mind:Anton Korobeynikov2010-01-101-1/+8
| | | | | | | | | 1. Add helper class for sema checks for target attributes 2. Add helper class for codegen of target attributes As a proof-of-concept - implement msp430's 'interrupt' attribute. llvm-svn: 93118
* Move the -Wconversion logic into SemaChecking.cpp. There's a fair amount ofJohn McCall2010-01-041-310/+1
| | | | | | | overlap between this and -Wsign-compare, which is why I want them in the same place. llvm-svn: 92543
* Get rid of FixedWidthIntType, as suggested by Chris and Eli.Anders Carlsson2009-12-291-8/+1
| | | | llvm-svn: 92246
* Kill off PreDeclaratorDC.John McCall2009-12-191-2/+2
| | | | llvm-svn: 91772
* Rework how virtual member functions are marked. If a class has no key ↵Anders Carlsson2009-12-071-12/+21
| | | | | | function, we now wait until the end of the translation unit to mark its virtual member functions as references. This lays the groundwork for fixing PR5557. llvm-svn: 90752
* DeclaratorInfo -> TypeSourceInfo. Makes an effort to rename associated ↵John McCall2009-12-071-8/+8
| | | | | | | | | | | | | | | | | | | | | variables, but the results are imperfect. For posterity, I did: cat <<EOF > $cmdfile s/DeclaratorInfo/TypeSourceInfo/g s/DInfo/TInfo/g s/TypeTypeSourceInfo/TypeSourceInfo/g s/SourceTypeSourceInfo/TypeSourceInfo/g EOF find lib -name '*.cpp' -not -path 'lib/Parse/*' -exec sed -i '' -f $cmdfile '{}' \; find lib -name '*.h' -exec sed -i '' -f $cmdfile '{}' \; find include -name '*.h' -not -path 'include/clang/Parse/*' -not -path 'include/clang/Basic/*' -exec sed -i '' -f $cmdfile '{}' \; llvm-svn: 90743
* Refactor our handling of expression evaluation contexts, so that SemaDouglas Gregor2009-11-261-2/+5
| | | | | | | | | | | | maintains a stack of evaluation contexts rather than having the parser do it. This change made it simpler to track in which contexts temporaries were created, so that we could... "Forget" about temporaries created within unevaluated contexts, so that we don't build a CXXExprWithTemporaries and, therefore, destroy the integral-constness of our expressions. Fixes PR5609. llvm-svn: 89908
* Allow user re-definition of SEL as well as accessing its fields.Fariborz Jahanian2009-11-251-1/+1
| | | | | | This fixes pr5611. llvm-svn: 89895
* Make 'SEL' pointer to a builtin type and not anFariborz Jahanian2009-11-231-1/+1
| | | | | | | objective-c pointer type. This was a serious mishap and luckily, Ted's test caught that (and patch fixes the test case). llvm-svn: 89680
* This patch implements objective-c's 'SEL' type as a built-inFariborz Jahanian2009-11-211-5/+3
| | | | | | | | | | | | | | | | | | type and fixes a long-standing code gen. crash reported in at least two PRs and a radar. (radar 7405040 and pr5025). There are couple of remaining issues that I would like for Ted. and Doug to look at: Ted, please look at failure in Analysis/MissingDealloc.m. I have temporarily added an expected-warning to make the test pass. This tests has a declaration of 'SEL' type which may not co-exist with the new changes. Doug, please look at a FIXME in PCHWriter.cpp/PCHReader.cpp. I think the changes which I have ifdef'ed out are correct. They need be considered for in a few Indexer/PCH test cases. llvm-svn: 89561
* Do not enter forward class 'Protocol' in decl context.Fariborz Jahanian2009-11-181-1/+1
| | | | | | Will do it later. Fixes pr5552. llvm-svn: 89269
* Rework Sema code completion interface.Daniel Dunbar2009-11-131-2/+3
| | | | | | | | | | | | | - Provide Sema in callbacks, instead of requiring it in constructor. This eliminates the need for a factory function. Clients now just pass the object to consume the results in directly. - CodeCompleteConsumer is cheap to construct, so building it whenever we are doing code completion is reasonable. Doug, please review. llvm-svn: 87099
* Fix PR 5422: handle lvalue results when evaluating 'based' ptrtoints as part ofJohn McCall2009-11-111-3/+9
| | | | | | the -Wconversion check. llvm-svn: 86891
* Improve diagnostics when a default template argument does not matchDouglas Gregor2009-11-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | with its corresponding template parameter. This can happen when we performed some substitution into the default template argument and what we had doesn't match any more, e.g., template<int> struct A; template<typename T, template<T> class X = A> class B; B<long> b; Previously, we'd emit a pretty but disembodied diagnostic showing how the default argument didn't match the template parameter. The diagnostic was good, but nothing tied it to the *use* of the default argument in "B<long>". This commit fixes that. Also, tweak the counting of active template instantiations to avoid counting non-instantiation records, such as those we create for (surprise!) checking default arguments, instantiating default arguments, and performing substitutions as part of template argument deduction. llvm-svn: 86884
* Support -Wshorten-64-to-32 for integer types only, which seems to satisfy theJohn McCall2009-11-071-0/+4
| | | | | | core requirements. Fixes rdar://problem/6389954 llvm-svn: 86364
* Improve -Wconversion by permitting binary operations on values of the targetJohn McCall2009-11-071-42/+129
| | | | | | type (or smaller) to stay "closed" within the type. llvm-svn: 86356
* Implement -Wconversion. Off by default, in the non-gcc group. There'sJohn McCall2009-11-071-6/+225
| | | | | | significant work left to be done to reduce the false-positive rate here. llvm-svn: 86326
* Change our basic strategy for avoiding deprecation warnings when the decl useJohn McCall2009-11-041-1/+1
| | | | | | | | | | | | appears in a deprecated context. In the new strategy, we emit the warnings as usual unless we're currently parsing a declaration, where "declaration" is restricted to mean a decl group or a few special cases in Objective C. If we *are* parsing a declaration, we queue up the deprecation warnings until the declaration has been completely parsed, and then emit them only if the decl is not deprecated. We also standardize the bookkeeping for deprecation so as to avoid special cases. llvm-svn: 85998
* Preserve type source information in TypedefDecls. Preserve it acrossJohn McCall2009-10-241-16/+22
| | | | | | | | | template instantiation. Preserve it through PCH. Show it off to the indexer. I'm healthily ignoring the vector type cases because we don't have a sensible TypeLoc implementation for them anyway. llvm-svn: 84994
* Implement PR5242: don't desugar a type more than once in a diagnostic. ThisChris Lattner2009-10-201-14/+33
| | | | | | | | | | | | | | implements a framework that allows us to use information about previously substituted values to simplify subsequent ones. Maybe this would be useful for C++'y stuff, who knows. We now get: t.c:4:21: error: invalid operands to binary expression ('size_t' (aka 'unsigned long *') and 'size_t') return (size_t) 0 + (size_t) 0; ~~~~~~~~~~ ^ ~~~~~~~~~~ on the testcase. Note that size_t is only aka'd once. llvm-svn: 84604
* teach FormatDiagnostic to aggregate previously formatted arguments andChris Lattner2009-10-201-0/+2
| | | | | | | | | pass them down into the ArgToStringFn implementation. This allows redundancy across operands to a diagnostic to be eliminated. This isn't used yet, so no functionality change. llvm-svn: 84602
* code cleanup, convert if tree to switch etc.Chris Lattner2009-10-201-19/+26
| | | | llvm-svn: 84599
* When performing template-substitution into a type, don't just replace theJohn McCall2009-10-181-28/+100
| | | | | | | | | | | | | | | | | | TemplateTypeParmType with the substituted type directly; instead, replace it with a SubstTemplateTypeParmType which will note that the type was originally written as a template type parameter. This makes it reasonable to preserve source information even through template substitution. Also define the new SubstTemplateTypeParmType class, obviously. For consistency with current behavior, we stringize these types as if they were the underlying type. I'm not sure this is the right thing to do. At any rate, I paled at adding yet another clause to the don't-desugar 'if' statement, so I extracted a function to do it. The new function also does The Right Thing more often, I think: e.g. if we have a chain of typedefs leading to a vector type, we will now desugar all but the last one. llvm-svn: 84412
* Remove the ConstantArrayType subtypes. This information is preserved in theJohn McCall2009-10-161-3/+2
| | | | | | | | | | TypeLoc records for declarations; it should not be necessary to represent it directly in the type system. Please complain if you were using these classes and feel you can't replicate previous functionality using the TypeLoc API. llvm-svn: 84222
* Improve diagnostics when the parser encounters a declarator with anDouglas Gregor2009-10-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | unknown type name, e.g., foo::bar x; when "bar" does not refer to a type in "foo". With this change, the parser now calls into the action to perform diagnostics and can try to recover by substituting in an appropriate type. For example, this allows us to easily diagnose some missing "typename" specifiers, which we now do: test/SemaCXX/unknown-type-name.cpp:29:1: error: missing 'typename' prior to dependent type name 'A<T>::type' A<T>::type A<T>::f() { return type(); } ^~~~~~~~~~ typename Fixes PR3990. llvm-svn: 84053
* Unify our diagnostic printing for errors of the form, "we didn't likeDouglas Gregor2009-10-131-68/+89
| | | | | | | | | | what we found when we looked into <blah>", where <blah> is a DeclContext*. We can now format DeclContext*'s in nice ways, e.g., "namespace N", "the global namespace", "'class Foo'". This is part of PR3990, but we're not quite there yet. llvm-svn: 84028
* Desugaring optimizations. Add single-step desugaring methods to allJohn McCall2009-09-291-3/+10
| | | | | | | | | concrete types. Use unqualified desugaring for getAs<> and sundry. Fix a few users to either not desugar or use qualified desugar, as seemed appropriate. Removed Type's qualified desugar method, as it was easy to accidentally use instead of QualType's. llvm-svn: 83116
* Refactor the representation of qualifiers to bring ExtQualType out of theJohn McCall2009-09-241-3/+1
| | | | | | | | 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
* Initial implementation of a code-completion interface in Clang. InDouglas Gregor2009-09-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | essence, code completion is triggered by a magic "code completion" token produced by the lexer [*], which the parser recognizes at certain points in the grammar. The parser then calls into the Action object with the appropriate CodeCompletionXXX action. Sema implements the CodeCompletionXXX callbacks by performing minimal translation, then forwarding them to a CodeCompletionConsumer subclass, which uses the results of semantic analysis to provide code-completion results. At present, only a single, "printing" code completion consumer is available, for regression testing and debugging. However, the design is meant to permit other code-completion consumers. This initial commit contains two code-completion actions: one for member access, e.g., "x." or "p->", and one for nested-name-specifiers, e.g., "std::". More code-completion actions will follow, along with improved gathering of code-completion results for the various contexts. [*] In the current -code-completion-dump testing/debugging mode, the file is truncated at the completion point and EOF is translated into "code completion". llvm-svn: 82166
* When implicitly declaring operators new, new[], delete, and delete[],Douglas Gregor2009-09-151-1/+1
| | | | | | | | | | | | give them the appropriate exception specifications. This, unfortunately, requires us to maintain and/or implicitly generate handles to namespace "std" and the class "std::bad_alloc". However, every other approach I've come up with was more hackish, and this standard requirement itself is quite the hack. Fixes PR4829. llvm-svn: 81939
* Only reuse an already existing ImplicitCastExpr if the cast kinds are the same.Anders Carlsson2009-09-151-4/+8
| | | | llvm-svn: 81841
OpenPOWER on IntegriCloud