summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* If a function decl cannot be merged, mark it as invalid.Nico Weber2015-01-171-0/+1
| | | | | | | | | | | | | | | | | | | Clang currently crashes on class C { C() = default; C() = delete; }; My cunning plan for fixing this was to change the `if (!FnD)` in Parser::ParseCXXInlineMethodDef() to `if (!FnD || FnD->isInvalidDecl)` – but alas, the second constructor decl wasn't marked as invalid. This lets Sema::MergeFunctionDecl() return true on function redeclarations, which leads to them being marked invalid. This also improves error messages when functions are redeclared. llvm-svn: 226365
* Sema: Recover when a function template is in an extern "C" blockDavid Majnemer2015-01-151-2/+2
| | | | llvm-svn: 226135
* Sema: It's cheaper to ask LookupResult::empty than to calculate linkageDavid Majnemer2015-01-141-1/+1
| | | | llvm-svn: 225960
* Sema: Check type compatibility with the most recent decl when mergingDavid Majnemer2015-01-141-1/+8
| | | | | | | | | | We would check the type information from the declaration found by lookup but we would neglect checking compatibility with the most recent declaration. This would make it possible for us to not correctly diagnose inconsistencies with declarations which were made in a different scope. llvm-svn: 225934
* Sema: An extern declaration can't be a redeclaration of a parameterDavid Majnemer2015-01-141-2/+2
| | | | | | | | | | | | In the following: void f(int x) { extern int x; } The second declaration of 'x' shouldn't be considered a redeclaration of the parameter. This is a different approach to r225780. llvm-svn: 225875
* When attribute 'optnone' appears on the same declaration with aPaul Robinson2015-01-131-1/+3
| | | | | | | | | | | | conflicting attribute, warn about the conflict and pick a "winning" attribute to preserve, instead of emitting an error. This matches the behavior when the conflicting attributes are on different declarations. Along the way I discovered that conflicts involving __forceinline were reported as 'always_inline' (alternate spelling, same attribute) so fixed that up to report the attribute as spelled in the source. llvm-svn: 225813
* Revert "Sema: An extern declaration can't be a redeclaration of a parameter"David Majnemer2015-01-131-2/+4
| | | | | | | This reverts commit r225780, we can't compile line 181 in sanitizer_platform_limits_posix.cc with this commit. llvm-svn: 225781
* Sema: An extern declaration can't be a redeclaration of a parameterDavid Majnemer2015-01-131-4/+2
| | | | | | | | | | In the following: void f(int x) { extern int x; } The second declaration of 'x' shouldn't be considered a redeclaration of the parameter. llvm-svn: 225780
* Mark vtable used on explicit destructor definitions.Nico Weber2015-01-131-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two things in a C++ program that need to read the vtable pointer: Constructors and destructors. (A few other operations -- virtual calls, dynamic cast, rtti -- read the vtable pointer off a this pointer, but for this they don't need the vtable symbol.) Implicit constructors and destructors and explicit constructors already marked the vtable as used, but explicit destructors didn't. Note that the only thing sema's "mark a class's vtable used" does is to mark all final overriders of the class as referenced, it does _not_ cause emission of the vtable itself. This is done on demand by codegen, independent of sema, since sema might emit functions that are not referenced. (The exception are vtables that are forced via key functions -- these are forced onto codegen by sema.) This bug went unnoticed for years because it doesn't have observable effects (yet -- I want to change this in PR20337, which is why I noticed this). r213109 made it so that _calls_ to constructors don't mark the vtable used. Currently, _calls_ to destructors still mark the vtable used. If that wasn't the case, this program would tickle the problem: test.h: template <typename T> struct B { int* p; virtual ~B() { delete p; } virtual void f() {} }; struct __attribute__((visibility("default"))) C { C(); B<int> m; }; test2.cc: #include "test.h" int main() { C* c = new C; delete c; } test3.cc: #include "test.h" C::C() {} # This bin/clang++ binary doesn't MarkVTableUsed() for virtual dtor calls: $ bin/clang++ -shared test3.cc -std=c++11 -O2 -fvisibility=hidden \ -fvisibility-inlines-hidden -o libtest3.dylib $ bin/clang++ test2.cc -std=c++11 -O2 -fvisibility=hidden \ -fvisibility-inlines-hidden libtest3.dylib Undefined symbols for architecture x86_64: "B<int>::f()", referenced from: vtable for B<int> in test2-af8f4f.o ld: symbol(s) not found for architecture x86_64 What's happening here is that there's a copy of B's vtable hidden in libtest3.dylib, because C's constructor caused an implicit instantiation of that (and implicit constructors generate vtables). test2.cc calls C's destructDr, which destroys the B<int> member, which wants to overwrite the vtable back to B (think of B as the base of a class hierarchy, and of hierarchical destruction -- maybe we shouldn't do the vtable writing in destructors of final classes), but there's nothing in test2.cc that marks B's vtable used. So codegen writes out the vtable, but since it wasn't marked used, sema didn't mark all the virtual functions (in particular f()) as used. Note that this change makes us reject programs we didn't reject before (see the included Sema test case), but both gcc and cl also reject this code, and clang used to reject it before r213109. llvm-svn: 225761
* Rename RefersToCapturedVariable to RefersToEnclosingVariableOrCapture, NFCAlexey Bataev2015-01-121-1/+1
| | | | llvm-svn: 225624
* Sema: Don't crash when variable is redefined as a constexpr functionDavid Majnemer2015-01-091-1/+1
| | | | | | | | | We have a diagnostic describing that constexpr changed in C++14 when compiling in C++11 mode. While doing this, it examines the previous declaration and assumes that it is a function. However it is possible, in the context of error recovery, for this to not be the case. llvm-svn: 225518
* Sema: RecordDecl shouldn't have a FunctionDecl as a DeclDavid Majnemer2015-01-091-1/+6
| | | | | | | RecordDecls should have things like CXXMethodDecls or FriendDecls as a decl but not things like FunctionDecls. llvm-svn: 225511
* Sema: Don't crash when specializing a global scope function in a classDavid Majnemer2015-01-091-1/+1
| | | | | | | | We assumed that class-scope specializations would result in a CXXMethodDecl for that class. However, globally qualified functions will result in normal FunctionDecls. llvm-svn: 225508
* Sema: Remove some dead code from CreateNewFunctionDeclDavid Majnemer2015-01-091-3/+0
| | | | | | | The same code is already in Sema::ActOnFunctionDeclarator, the only caller of CreateNewFunctionDecl. llvm-svn: 225506
* Handle OpaqueValueExprs more intelligently in the TransformTypos treeKaelyn Takata2015-01-071-1/+3
| | | | | | | | | | | | transform. Also diagnose typos in the initializer of an invalid C++ declaration. Both issues were hit using the same line of test code, depending on whether the code was treated as C or C++. Fixes PR22092. llvm-svn: 225389
* Sema: Don't crash when solitary :: token appears before { in struct defDavid Majnemer2014-12-291-1/+1
| | | | | | | | hasDeclaratorForAnonDecl, getDeclaratorForAnonDecl and getTypedefNameForAnonDecl are expected to handle the case where NamedDeclOrQualifier holds the wrong type or nothing at all. llvm-svn: 224912
* Sema: Don't crash when an inject class name has a nested redefinitionDavid Majnemer2014-12-281-3/+2
| | | | | | | | | We expected the type of a TagDecl to be a TagType, not an InjectedClassNameType. Introduced a helper method, Type::getAsTagDecl, to abstract away the difference; redefine Type::getAsCXXRecordDecl to be in terms of it. llvm-svn: 224898
* Try typo correction on all initialization arguments and be lessKaelyn Takata2014-12-161-7/+5
| | | | | | | | | pessimistic about when to do so. This also fixes PR21905 as the initialization argument was no longer viewed as being type dependent due to the TypoExpr being type-cast. llvm-svn: 224386
* Renamed RefersToEnclosingLocal bitfield to RefersToCapturedVariable.Alexey Bataev2014-12-161-1/+1
| | | | | | | Bitfield RefersToEnclosingLocal of Stmt::DeclRefExprBitfields renamed to RefersToCapturedVariable to reflect latest changes introduced in commit 224323. Also renamed method Expr::refersToEnclosingLocal() to Expr::refersToCapturedVariable() and comments for constant arguments. No functional changes. llvm-svn: 224329
* Warn when attribute 'optnone' conflicts with attributes on aPaul Robinson2014-12-151-0/+6
| | | | | | different declaration of the same function. llvm-svn: 224256
* Create a new 'flag_enum' attribute.Alexis Hunt2014-11-281-8/+78
| | | | | | | | | | | This attribute serves as a hint to improve warnings about the ranges of enumerators used as flag types. It currently has no working C++ implementation due to different semantics for enums in C++. For more explanation, see the docs and testcases. Reviewed by Aaron Ballman. llvm-svn: 222906
* When checking for uninitialized values, do not confuse "std::move" with everyRichard Trieu2014-11-271-1/+2
| | | | | | other function named "move". llvm-svn: 222863
* Properly correct initializer expressions based on whether they would be valid.Kaelyn Takata2014-11-211-0/+17
| | | | llvm-svn: 222550
* Fix missing diagnostic for unsupported TLS for some thread_local variables.Bob Wilson2014-11-211-16/+14
| | | | | | | | | Clang r181627 moved a check for block-scope variables into this code for handling thread storage class specifiers, but in the process, it broke the logic for checking if the target supports TLS. Fix this with some simple restructuring of the code. rdar://problem/18796883 llvm-svn: 222512
* Fix an assertion when ending a function definition.John McCall2014-11-181-1/+2
| | | | | | | | | | | | | | | | | | | | The bug is that ExprCleanupObjects isn't always empty in a fresh evaluation context. New evaluation contexts just track the current depth of the stack. The assertion will misfire whenever we finish processing a function body inside an expression that contained an earlier block literal with non-trivial captures. That's actually a lot less likely than you'd think, though, because it has to be a real function declaration, not just another block. Mixed block/lambda code would work, as would a template instantiation or a local class definition. The code works correctly if the assertion is disabled. rdar://16356628 llvm-svn: 222194
* Remove some redundant virtual specifiers on overriden functions.David Blaikie2014-11-141-1/+1
| | | | llvm-svn: 222024
* PR21437, final part of DR1330: delay-parsing of exception-specifications. ThisRichard Smith2014-11-131-0/+1
| | | | | | | is a re-commit of Doug's r154844 (modernized and updated to fit into current Clang). llvm-svn: 221918
* Move the no-prototype calling conv check after decl mergingReid Kleckner2014-11-031-13/+14
| | | | | | | | | | | Now we don't warn on this code: void __stdcall f(void); void __stdcall f(); My previous commit regressed this functionality because I didn't update the relevant test case which used a definition. llvm-svn: 221188
* Don't diagnose no-prototype callee-cleanup function definitionsReid Kleckner2014-11-031-15/+15
| | | | | | | | | | | | We already have a warning on the call sites of code like this: void f() { } void g() { f(1, 2, 3); } t.c:2:21: warning: too many arguments in call to 'f' We can limit ourselves to diagnosing unprototyped forward declarations of f to cut down on noise. llvm-svn: 221184
* Don't dllimport inline functions when targeting MinGW (PR21366)Hans Wennborg2014-11-031-0/+8
| | | | | | | | | | | | It turns out that MinGW never dllimports of exports inline functions. This means that code compiled with Clang would fail to link with MinGW-compiled libraries since we might try to import functions that are not imported. To fix this, make Clang never dllimport inline functions when targeting MinGW. llvm-svn: 221154
* Have -Wuninitialized catch uninitalized use in overloaded operator arguments.Richard Trieu2014-10-311-4/+7
| | | | llvm-svn: 221000
* Remove StorageClass typedefs from VarDecl and FunctionDecl since ↵Craig Topper2014-10-311-14/+11
| | | | | | StorageClass is in the clang namespace. llvm-svn: 220956
* Follow-up to r216619: use isCXXCLassMember() instead of trying toHans Wennborg2014-10-291-1/+1
| | | | | | | check the context ourselves when selectively allowing late-added dll attributes on unused free functions and variables (PR20746) llvm-svn: 220874
* Pass around CorrectionCandidateCallbacks as unique_ptrs soKaelyn Takata2014-10-271-29/+28
| | | | | | TypoCorrectionConsumer can keep the callback around as long as needed. llvm-svn: 220693
* Add frontend support for __vectorcallReid Kleckner2014-10-241-2/+2
| | | | | | | | | | | | | Wire it through everywhere we have support for fastcall, essentially. This allows us to parse the MSVC "14" CTP headers, but we will miscompile them because LLVM doesn't support __vectorcall yet. Reviewed By: Aaron Ballman Differential Revision: http://reviews.llvm.org/D5808 llvm-svn: 220573
* Add RestrictQualifierLoc to DeclaratorChunk::FunctionTypeInfoHal Finkel2014-10-201-0/+1
| | | | | | | | | | | | | | Clang supports __restrict__ as a function qualifier, but DeclaratorChunk::FunctionTypeInfo lacked a field to track the qualifier's source location (as we do with volatile, etc.). This was the subject of a FIXME in GetFullTypeForDeclarator (in SemaType.cpp). This should also prove useful as we add more warnings regarding questionable uses of the restrict qualifier. There is no significant functional change (except for an improved source range associated with the err_invalid_qualified_function_type diagnostic fixit generated by GetFullTypeForDeclarator). llvm-svn: 220215
* Sema: handle additional case of qualified typesSaleem Abdulrasool2014-10-161-2/+1
| | | | | | | | | | | | | | | A second instance of attributed types escaped the previous change, identified thanks to Richard Smith! When deducing the void case, we would also assume that the type would not be attributed. Furthermore, properly handle multiple attributes being applied to a single TypeLoc. Properly handle this case and future-proof a bit by ignoring parenthesis further. The test cases do use the additional parenthesis to ensure that this case remains properly handled. Addresses post-commit review comments from Richard Smith to SVN r219851. llvm-svn: 219974
* MS Compat: mark globals emitted in read-only sections constHans Wennborg2014-10-161-4/+6
| | | | | | | | | | | | | | | | | | | | They cannot be written to, so marking them const makes sense and may improve optimisation. As a side-effect, SectionInfos has to be moved from Sema to ASTContext. It also fixes this problem, that occurs when compiling ATL: warning LNK4254: section 'ATL' (C0000040) merged into '.rdata' (40000040) with different attributes The ATL headers are putting variables in a special section that's marked read-only. However, Clang currently can't model that read-onlyness in the IR. But, by making the variables const, the section does become read-only, and the linker warning is avoided. Differential Revision: http://reviews.llvm.org/D5812 llvm-svn: 219960
* Adding attributes to the IndirectFieldDecl that we generate for anonymous ↵Aaron Ballman2014-10-151-4/+6
| | | | | | struct/union fields. This fixes PR20930. llvm-svn: 219807
* -ms-extensions: Allow __super in return stements.Nikola Smiljanic2014-10-041-5/+1
| | | | llvm-svn: 219050
* MS ABI: Disallow dllimported/exported variables from having TLSDavid Majnemer2014-10-041-1/+12
| | | | | | | | | | | | | | | | | | | Windows TLS relies on indexing through a tls_index in order to get at the DLL's thread local variables. However, this index is not exported along with the variable: it is assumed that all accesses to thread local variables are inside the same module which created the variable in the first place. While there are several implementation techniques we could adopt to fix this (notably, the Itanium ABI gets this for free), it is not worth the heroics. Instead, let's just ban this combination. We could revisit this in the future if we need to. This fixes PR21111. llvm-svn: 219049
* Sema: Simplify checkAttributesAfterMergingDavid Majnemer2014-10-041-8/+1
| | | | | | Use getDLLAttr to factor out some common dllimport/dllexport code. llvm-svn: 219048
* Update -Wuninitialized to be stricter on CK_NoOp casts.Richard Trieu2014-09-301-5/+10
| | | | llvm-svn: 218715
* Add back checking for condition of conditional operator for -WuninitializedRichard Trieu2014-09-261-0/+1
| | | | llvm-svn: 218556
* -ms-extensions: Implement __super scope specifier (PR13236).Nikola Smiljanic2014-09-261-1/+8
| | | | | | | | | We build a NestedNameSpecifier that records the CXXRecordDecl in which __super appeared. Name lookup is performed in all base classes of the recorded CXXRecordDecl. Use of __super is allowed only inside class and member function scope. llvm-svn: 218484
* Add increment/decrement operators and compound assignment operators to theRichard Trieu2014-09-251-0/+16
| | | | | | uninitialized checkers that did not have them before. llvm-svn: 218435
* Sema: Inherit the flexible array property from struct fieldsDavid Majnemer2014-09-241-9/+6
| | | | | | | | A record which contains a flexible array member is itself a flexible array member. A struct which contains such a record should also consider itself to be a flexible array member. llvm-svn: 218378
* Fix an edge case with BinaryOperator's in -Wuninitialized. Add testcases forRichard Trieu2014-09-241-2/+4
| | | | | | the other visitors as well. llvm-svn: 218366
* Improve -Wuninitialized to take into account field ordering with initializerRichard Trieu2014-09-231-1/+87
| | | | | | | lists. Since the fields are inititalized one at a time, using a field with lower index to initialize a higher indexed field should not be warned on. llvm-svn: 218339
* ms-inline-asm: Scope inline asm labels to functionsEhsan Akhgari2014-09-221-2/+8
| | | | | | | | | | | | | | | | Summary: This fixes PR20023. In order to implement this scoping rule, we piggy back on the existing LabelDecl machinery, by creating LabelDecl's that will carry the "internal" name of the inline assembly label, which we will rewrite the asm label to. Reviewers: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4589 llvm-svn: 218230
OpenPOWER on IntegriCloud