aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
AgeCommit message (Collapse)AuthorFilesLines
2011-07-26Cleanup the stray comments and variables I could dig out of Sema toChandler Carruth1-4/+4
refer to 'expansion' instead of 'instantiation'. llvm-svn: 136060
2011-07-25Mechanically rename SourceManager::getInstantiationLoc andChandler Carruth1-1/+1
FullSourceLoc::getInstantiationLoc to ...::getExpansionLoc. This is part of the API and documentation update from 'instantiation' as the term for macros to 'expansion'. llvm-svn: 135914
2011-07-23remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner1-9/+9
LLVM.h imports them into the clang namespace. llvm-svn: 135852
2011-07-06Build up statistics about the work done for analysis based warnings.Chandler Carruth1-2/+11
Special detail is added for uninitialized variable analysis as this has serious performance problems than need to be tracked. Computing some of this data is expensive, for example walking the CFG to determine its size. To avoid doing that unless the stats data is going to be used, we thread a bit into the Sema object to track whether detailed stats should be collected or not. This bit is used to avoid computations whereever the computations are likely to be more expensive than checking the state of the flag. Thus, counters are in some cases unconditionally updated, but the more expensive (and less frequent) aggregation steps are skipped. With this patch, we're able to see that for 'gcc.c': *** Analysis Based Warnings Stats: 232 functions analyzed (0 w/o CFGs). 7151 CFG blocks built. 30 average CFG blocks per function. 1167 max CFG blocks per function. 163 functions analyzed for uninitialiazed variables 640 variables analyzed. 3 average variables per function. 94 max variables per function. 96409 block visits. 591 average block visits per function. 61546 max block visits per function. And for the reduced testcase in PR10183: *** Analysis Based Warnings Stats: 98 functions analyzed (0 w/o CFGs). 8526 CFG blocks built. 87 average CFG blocks per function. 7277 max CFG blocks per function. 68 functions analyzed for uninitialiazed variables 1359 variables analyzed. 19 average variables per function. 1196 max variables per function. 2540494 block visits. 37360 average block visits per function. 2536495 max block visits per function. That last number is the somewhat scary one that indicates the problem in PR10183. llvm-svn: 134494
2011-06-28Add support for C++ namespace-aware typo correction, e.g., correctingDouglas Gregor1-0/+6
vector<int> to std::vector<int> Patch by Kaelyn Uhrain, with minor tweaks + PCH support from me. Fixes PR5776/<rdar://problem/8652971>. Thanks Kaelyn! llvm-svn: 134007
2011-06-15Automatic Reference Counting.John McCall1-5/+35
Language-design credit goes to a lot of people, but I particularly want to single out Blaine Garst and Patrick Beard for their contributions. Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself, in no particular order. llvm-svn: 133103
2011-05-31Whenever we instantiate a static data member, make sure to define any newNick Lewycky1-24/+16
vtables! Fixes PR10020 This also allows us to revert the part of r130023 which added a big loop around the template instantiation. llvm-svn: 132331
2011-05-11Implement CWG1170, which makes access-control errors into templateDouglas Gregor1-3/+6
argument deduction failures. Only implemented in C++0x, since this is a significant change in behavior from C++98/03. llvm-svn: 131209
2011-05-05Look through block pointers and ObjC object pointersMatt Beaumont-Gay1-4/+3
llvm-svn: 130906
2011-05-05Change cycle detection to be based off of a warning flag.Alexis Hunt1-1/+4
llvm-svn: 130898
2011-05-04Implement Sema::isExprCallable.Matt Beaumont-Gay1-0/+100
We can use this to produce nice diagnostics (and try to fixit-and-recover) in various cases where we might see "MyFunction" instead of "MyFunction()". The changes in SemaExpr are an example of how to use isExprCallable. llvm-svn: 130878
2011-05-04Implement a better version of delegating constructor cycle detection.Alexis Hunt1-0/+3
This is more efficient as it's all done at once at the end of the TU. This could still get expensive, so a flag is provided to disable it. As an added bonus, the diagnostics will now print out a cycle. The PCH test is XFAILed because we currently can't deal with a note emitted in the header and I, being tired, see no other way to verify the serialization of delegating constructors. We should probably address this problem /somehow/ but no good solution comes to mind. llvm-svn: 130836
2011-04-25Recognize gcc's ms_struct pragma (and ignore for now).Fariborz Jahanian1-2/+2
This is wip. llvm-svn: 130138
2011-04-24Synthesizing the definition of an implicit member is an AST modification, so ↵Sebastian Redl1-0/+4
notify any mutation listeners of it. This fixes a crasher in chained PCH, where an implicit destructor in a PCH gets a definition in a chained PCH, which is then lost. However, any further use of the destructor would cause its definition to be regenerated in the final file, hiding the bug. llvm-svn: 130103
2011-04-22At the end of the translation unit, defining a vtable can introduceDouglas Gregor1-16/+24
new templates that need to be instantiated and vice-versa. Iterate until we've instantiated all required templates and defined all required vtables. Fixed PR9325 / <rdar://problem/9055177>. llvm-svn: 130023
2011-04-22Add -fdelayed-template-parsing option. Using this option all templated ↵Francois Pichet1-0/+1
function definitions are parsed at the end of the translation unit only if it is required by an actual instantiation. As such all the symbols of the TU are available during name lookup. Using this flag is necessary for compatibility with Microsoft template code. This also provides some parsing speed improvement. llvm-svn: 130022
2011-04-19We regard a function as 'unused' from the codegen perspective, so our ↵Argyrios Kyrtzidis1-6/+20
warnings diverge from gcc's unused warnings which don't get emitted if the function is referenced even in an unevaluated context (e.g. in templates, sizeof, etc.). Also, saying that a function is 'unused' because it won't get codegen'ed is somewhat misleading. - Don't emit 'unused' warnings for functions that are referenced in any part of the user's code. - A warning that an internal function/variable won't get emitted is useful though, so introduce -Wunneeded-internal-declaration which will warn if a function/variable with internal linkage is not "needed" ('used' from the codegen perspective), e.g: static void foo() { } template <int> void bar() { foo(); } test.cpp:1:13: warning: function 'foo' is not needed and will not be emitted static void foo() { } ^ Addresses rdar://8733476. llvm-svn: 129794
2011-04-08Use ExprResult& instead of Expr *& in SemaJohn Wiegley1-10/+10
This patch authored by Eric Niebler. Many methods on the Sema class (e.g. ConvertPropertyForRValue) take Expr pointers as in/out parameters (Expr *&). This is especially true for the routines that apply implicit conversions to nodes in-place. This design is workable only as long as those conversions cannot fail. If they are allowed to fail, they need a way to report their failures. The typical way of doing this in clang is to use an ExprResult, which has an extra bit to signal a valid/invalid state. Returning ExprResult is de riguour elsewhere in the Sema interface. We suggest changing the Expr *& parameters in the Sema interface to ExprResult &. This increases interface consistency and maintainability. This interface change is important for work supporting MS-style C++ properties. For reasons explained here <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-February/013180.html>, seemingly trivial operations like rvalue/lvalue conversions that formerly could not fail now can. (The reason is that given the semantics of the feature, getter/setter method lookup cannot happen until the point of use, at which point it may be found that the method does not exist, or it may have the wrong type, or overload resolution may fail, or it may be inaccessible.) llvm-svn: 129143
2011-04-07In C++ the argument of logical not should always be bool. Added missing ↵Abramo Bagnara1-0/+15
implicit cast for scalars. llvm-svn: 129066
2011-03-08Fix my earlier commit to work with escaped newlines and leave breadcrumbsJohn McCall1-0/+21
in case we want to make a world where we can check intermediate instantiations for this kind of breadcrumb. llvm-svn: 127221
2011-03-06Fixed TypedefDecl and TemplateTypeParameter source range.Abramo Bagnara1-3/+8
llvm-svn: 127119
2011-03-03Don't emit unused warning for deleted functions. Fixes rdar://8365684 & ↵Argyrios Kyrtzidis1-0/+2
http://llvm.org/PR9391. llvm-svn: 126950
2011-02-23Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the ↵Ted Kremenek1-1/+12
related code is reachable. This suppresses some diagnostics that occur in unreachable code (e.g., -Warray-bound). We only pay the cost of doing the reachability analysis when we issue one of these diagnostics. llvm-svn: 126290
2011-02-23Have IdempotentOperationsChecker pull its CFGStmtMap from AnalysisContext.Ted Kremenek1-1/+1
llvm-svn: 126288
2011-02-23Issue AnalysisBasedWarnings as part of calling ↵Ted Kremenek1-2/+8
Sema::PopBlockOrFunctionScope(). No real functionality change. llvm-svn: 126287
2011-02-21Tweaks to C++0x deduced auto type support:Richard Smith1-0/+6
* Flag indicating 'we're parsing this auto typed variable's initializer' moved from VarDecl to Sema * Temporary template parameter list for auto deduction is now allocated on the stack. * Deduced 'auto' types are now uniqued. llvm-svn: 126139
2011-02-19Warn about code that uses variables and functions with internal linkageJohn McCall1-0/+61
without defining them. This should be an error, but I'm paranoid about "uses" that end up not actually requiring a definition. I'll revisit later. Also, teach IR generation to not set internal linkage on variable declarations, just for safety's sake. Doing so produces an invalid module if the variable is not ultimately defined. Also, fix several places in the test suite where we were using internal functions without definitions. llvm-svn: 126016
2011-02-18Switch labels over to using normal name lookup, instead of their Chris Lattner1-49/+0
own weird little DenseMap. Hey look, we now emit unused label warnings deterministically, amazing. llvm-svn: 125813
2011-02-17add a fixmeChris Lattner1-0/+2
llvm-svn: 125772
2011-02-17Step #2/N of __label__ support: keep pushing LabelDecl forward,Chris Lattner1-2/+1
making them be template instantiated in a more normal way and make them handle attributes like other decls. This fixes the used/unused label handling stuff, making it use the same infrastructure as other decls. llvm-svn: 125771
2011-02-17Step #1/N of implementing support for __label__: split labels intoChris Lattner1-0/+48
LabelDecl and LabelStmt. There is a 1-1 correspondence between the two, but this simplifies a bunch of code by itself. This is because labels are the only place where we previously had references to random other statements, causing grief for AST serialization and other stuff. This does cause one regression (attr(unused) doesn't silence unused label warnings) which I'll address next. This does fix some minor bugs: 1. "The only valid attribute " diagnostic was capitalized. 2. Various diagnostics printed as ''labelname'' instead of 'labelname' 3. This reduces duplication of label checking between functions and blocks. Review appreciated, particularly for the cindex and template bits. llvm-svn: 125733
2011-02-14When parsing an out-of-line member function declaration, we must delayJohn McCall1-1/+1
access-control diagnostics which arise from the portion of the declarator following the scope specifier, just in case access is granted by friending the individual method. This can also happen with in-line member function declarations of class templates due to templated-scope friend declarations. We were really playing fast-and-loose before with this sort of thing, and it turned out to work because *most* friend functions are in file scope. Making us delay regardless of context exposed several bugs with how we were manipulating delay. I ended up needing a concept of a context that's independent of the declarations in which it appears, and then I actually had to make some things save contexts correctly, but delay should be much cleaner now. I also encapsulated all the delayed-diagnostics machinery in a single subobject of Sema; this is a pattern we might want to consider rolling out to other components of Sema. llvm-svn: 125485
2011-02-14Move support for "#pragma STDC FP_CONTRACT" to Parser; add Sema actionsPeter Collingbourne1-1/+1
llvm-svn: 125474
2011-02-01Perform the bad-address-space conversions check as part of John McCall1-9/+0
CheckPointerTypesForAssignment. llvm-svn: 124632
2011-01-31If there were errors, disable 'unused' warnings since they will mostly be noise.Argyrios Kyrtzidis1-19/+23
Fixes rdar://8736362. llvm-svn: 124577
2011-01-27Teach the evaluation of the __is_convertible_to trait to translateDouglas Gregor1-5/+11
access control errors into SFINAE errors, so that the trait provides enough support to implement the C++0x std::is_convertible type trait. To get there, the SFINAETrap now knows how to set up a SFINAE context independent of any template instantiations or template argument deduction steps, and (separately) can set a Sema flag to translate access control errors into SFINAE errors. The latter can also be useful if we decide that access control errors during template argument deduction should cause substitution failure (rather than a hard error) as has been proposed for C++0x. llvm-svn: 124446
2011-01-27Separate the access-control diagnostics from other diagnostics that do not ↵Douglas Gregor1-0/+2
have SFINAE behavior. llvm-svn: 124441
2011-01-25Don't insert class templates into the DynamicClasses vector.Anders Carlsson1-0/+2
llvm-svn: 124201
2010-12-20Implement basic support for template instantiation of pack expansionsDouglas Gregor1-1/+2
whose patterns are template arguments. We can now instantiate, e.g., typedef tuple<pair<OuterTypes, InnerTypes>...> type; where OuterTypes and InnerTypes are template type parameter packs. There is a horrible inefficiency in TemplateArgumentLoc::getPackExpansionPattern(), where we need to create copies of TypeLoc data because our interfaces traffic in TypeSourceInfo pointers where they should traffic in TypeLocs instead. I've isolated in efficiency in this one routine; once we refactor our interfaces to traffic in TypeLocs, we can eliminate it. llvm-svn: 122278
2010-12-12Move the functionality to mark all vtables of key functions as used withinChandler Carruth1-0/+12
a translation unit to the ActOnEndOfTranslationUnit function instead of doing it at the start of DefineUsedVTables. The latter is now called *recursively* during template instantiation, which causes an absolutely insane number of walks of every record decl in the translation unit. After this patch, an extremely template instantiation heavy test case's compile time drops by 10x, and we see between 15% and 20% improvement in average compile times across a project. This is just recovering a regression, it doesn't make anything faster than it was several weeks ago. llvm-svn: 121644
2010-11-25Tie DefineVTablesUsed() in with recursive function instantiation so that we emitNick Lewycky1-20/+18
a useful template instantiation stack. Fixes PR8640. This also causes a slight change to where the "instantianted from" note shows up in truly esoteric cases (see the change to test/SemaCXX/destructor.cpp), but that isn't directly the fault of this patch. llvm-svn: 120135
2010-11-19Refactoring. Get FunctionScopeInfo to use DiagnosticErrorTrap.Argyrios Kyrtzidis1-9/+7
llvm-svn: 119764
2010-11-18Refactoring of Diagnostic class.Argyrios Kyrtzidis1-6/+6
-Move the stuff of Diagnostic related to creating/querying diagnostic IDs into a new DiagnosticIDs class. -DiagnosticIDs can be shared among multiple Diagnostics for multiple translation units. -The rest of the state in Diagnostic object is considered related and tied to one translation unit. -Have Diagnostic point to the SourceManager that is related with. Diagnostic can now accept just a SourceLocation instead of a FullSourceLoc. -Reflect the changes to various interfaces. llvm-svn: 119730
2010-10-13Fix a silly bug in the suppression of non-error diagnostics in aDouglas Gregor1-0/+2
SFINAE context, where we weren't getting the right diagnostic argument count. I blame DiagnosticBuilder's weirdness. Fixes PR8372. llvm-svn: 116411
2010-10-12Introduce support for emitting diagnostics (warnings + their notes)Douglas Gregor1-19/+36
that are suppressed during template argument deduction. This change queues diagnostics computed during template argument deduction. Then, if the resulting function template specialization or partial specialization is chosen by overload resolution or partial ordering (respectively), we will emit the queued diagnostics at that point. This addresses most of PR6784. However, the check for unnamed/local template arguments (which existed before this change) is still only skin-deep, and needs to be extended to look deeper into types. It must be improved to finish PR6784. llvm-svn: 116373
2010-09-28Move ExternalSemaSource::ReadMethodPool's implementation to Sema.cpp so that ↵Sebastian Redl1-0/+6
the header can get away with forward declarations only for ObjCMethodList and Selector. Fixes <rdar://8467631>. llvm-svn: 114978
2010-09-08Fix a few minor issues with parsing and semantic analysis of C++Douglas Gregor1-1/+1
typeid expressions: - make sure we have a proper source location for the closing ')' - cache the declaration of std::type_info once we've found it llvm-svn: 113441
2010-09-08Initialize the MSVCGuidDecl variable in the correct order.Bill Wendling1-2/+3
llvm-svn: 113412
2010-09-08Microsoft's __uuidof operator implementation part 1.Francois Pichet1-1/+1
llvm-svn: 113356
2010-09-03Devirtualize Sema, kill off DeleteExpr and DeleteStmt, and reformat.John McCall1-5/+0
llvm-svn: 112945