summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [modules] If we reach a definition of a class for which we already have aRichard Smith2015-03-261-5/+21
| | | | | | | | non-visible definition, skip the new definition and make the old one visible instead of trying to parse it again and failing horribly. C++'s ODR allows us to assume that the two definitions are identical. llvm-svn: 233250
* MS ABI: Implement the MSVC 2015 scheme for scope disambiguationDavid Majnemer2015-03-191-11/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | consider C++ that looks like: inline int &f(bool b) { if (b) { static int i; return i; } static int i; return i; } Both 'i' variables must have distinct (and stable) names for linkage purposes. The MSVC 2013 ABI would number the variables using a count of the number of scopes that have been created. However, the final 'i' returns to a scope that has already been created leading to a mangling collision. MSVC 2015 fixes this by giving the second 'i' the name it would have if it were declared before the 'if'. However, this results in ABI breakage because the mangled name, in cases where there was no ambiguity, would now be different. We implement the new behavior and only enable it if we are targeting the MSVC 2015 ABI, otherwise the old behavior will be used. This fixes PR18131. llvm-svn: 232766
* Remove many superfluous SmallString::str() calls.Yaron Keren2015-03-181-1/+1
| | | | | | | | | | | | | | | Now that SmallString is a first-class citizen, most SmallString::str() calls are not required. This patch removes a whole bunch of them, yet there are lots more. There are two use cases where str() is really needed: 1) To use one of StringRef member functions which is not available in SmallString. 2) To convert to std::string, as StringRef implicitly converts while SmallString do not. We may wish to change this, but it may introduce ambiguity. llvm-svn: 232622
* Fix a crash when the size of an 'auto' is needed and its initalizerKaelyn Takata2015-03-171-0/+14
| | | | | | | | contained a typo correction (the auto decl was being marked as dependent unnecessarily, which triggered an assertion in cases where the size of the type is needed). llvm-svn: 232568
* MS ABI: Delay default constructor closure checking until the outermost class ↵Reid Kleckner2015-03-171-27/+1
| | | | | | | | | | | | | | | | | scope ends Previously, we would error out on this code because the default argument wasn't parsed until the end of Outer: struct __declspec(dllexport) Outer { struct __declspec(dllexport) Inner { Inner(void *p = 0); }; }; Now we do the checking on the closing brace of Outer instead of Inner. llvm-svn: 232519
* Comment parsing: move a diagnostic to the correct group.Dmitri Gribenko2015-03-171-2/+5
| | | | | | Based on a patch by LE GARREC Vincent. llvm-svn: 232511
* MS ABI: Generate default constructor closuresDavid Majnemer2015-03-131-1/+27
| | | | | | | | | | | | | | | | | | | | The MS ABI utilizes a compiler generated function called the "vector constructor iterator" to construct arrays of objects with non-trivial constructors/destructors. For this to work, the constructor must follow a specific calling convention. A thunk must be created if the default constructor has default arguments, is variadic or is otherwise incompatible. This thunk is called the default constructor closure. N.B. Default constructor closures are only generated if the default constructor is exported because clang itself does not utilize vector constructor iterators. Failing to export the default constructor closure will result in link/load failure if a translation unit compiled with MSVC is on the import side. Differential Revision: http://reviews.llvm.org/D8331 llvm-svn: 232229
* Sema: Don't emit a missing prototype warning for deleted functions.Benjamin Kramer2015-03-121-26/+30
| | | | | | | | | | | | | This is a bit more involved than I anticipated, so here's a breakdown of the changes: 1. Call ActOnFinishFunctionBody _after_ we parsed =default and =delete specifiers. Saying that we finished the body before parsing =default is just wrong. Changing this allows us to use isDefaulted and isDeleted on a decl in ActOnFinishFunctionBody. 2. Check for -Wmissing-prototypes after we parsed the function body. 3. Disable -Wmissing-prototypes when the Decl isDeleted. llvm-svn: 232040
* Sema: Properly track mangling number/name for linkage for using declsDavid Majnemer2015-03-111-46/+52
| | | | | | | | | | | | Using declarations which are aliases to struct types have their name used as the struct type's name for linkage purposes. Otherwise, make sure to give an anonymous struct defined inside a using declaration a mangling number to disambiguate it from other anonymous structs in the same context. This fixes PR22809. llvm-svn: 231909
* Wrap to 80 columns. No behavior change.Nico Weber2015-03-091-3/+3
| | | | llvm-svn: 231621
* Wrap to 80 columns. No behavior change.Nico Weber2015-03-071-3/+5
| | | | llvm-svn: 231573
* Replace Sema's map of locally-scoped extern "C" declarations with a DeclContextRichard Smith2015-03-071-18/+4
| | | | | | | | | | of extern "C" declarations. This is simpler and vastly more efficient for modules builds (we no longer need to load *all* extern "C" declarations to determine if we have a redeclaration). No functionality change intended. llvm-svn: 231538
* Implement section pragma feedback on r205810Reid Kleckner2015-03-041-8/+11
| | | | | | | Mostly short-circuits some conditionals. Adds target validation of sections passed to these pragmas. llvm-svn: 231317
* Make -Wuninitialized warn on pointer-to-member and comma operators.Manuel Klimek2015-03-031-1/+6
| | | | | | | | | | | `isTrackedVar` has been updated to also track records. `DeclRefExpr`s appearing on the left side of a comma operator are ignored, while those appearing on the right side are classified as `Use`. Patch by Enrico Pertoso. llvm-svn: 231068
* Rework our handling of key functions. We used to track a complete list of allRichard Smith2015-02-281-23/+27
| | | | | | | | | | | | | | dynamic classes in the translation unit and check whether each one's key function is defined when we got to the end of the TU (and when we got to the end of each module). This is really terrible for modules performance, since it causes unnecessary deserialization of every dynamic class in every compilation. We now use a much simpler (and, in a modules build, vastly more efficient) system: when we see an out-of-line definition of a virtual function, we check whether that function was in fact its class's key function. (If so, we need to emit the vtable.) llvm-svn: 230830
* [MSVC] Improved lookup into dependent/non-dependent bases of dependent classAlexey Bataev2015-02-191-32/+72
| | | | | | | | Patch improves lookup into dependendt bases of dependent class and adds lookup into non-dependent bases. Differential Revision: http://reviews.llvm.org/D7173 llvm-svn: 229817
* Sema: Allow 'constexpr' variables in range loopsMeador Inge2015-02-181-2/+0
| | | | | | | | This fixes PR22492, which is in response to CWG issue #1204. Per the CWG issue 'contexpr' variables are now allowed in for range loops. llvm-svn: 229716
* Port r163224 to C++.Nico Weber2015-02-181-1/+4
| | | | | | | | | | | | | | | | | | | | The motivation is to fix a crash on struct S {} s; Foo S::~S() { s.~S(); } What was happening here was that S::~S() was marked as invalid since its return type is invalid, and as a consequence CheckFunctionDeclaration() wasn't called and S::~S() didn't get merged into S's implicit destructor. This way, the class ended up with two destructors, which confused the overload printer when it suddenly had to print two possible destructors for `s.~S()`. In addition to fixing the crash, this change also seems to improve diagnostics in a few other places, see test changes. Crash found by SLi's bot. llvm-svn: 229639
* Wrap to 80 columns. No behavior change.Nico Weber2015-02-181-2/+4
| | | | llvm-svn: 229637
* Revert r229543.Meador Inge2015-02-171-0/+2
| | | | | | Reverting this while build bot failures are investigated. llvm-svn: 229550
* Sema: Allow 'constexpr' variables in range loopsMeador Inge2015-02-171-2/+0
| | | | | | | | This fixes PR22492, which is in response to CWG issue #1204. Per the CWG issue 'contexpr' variables are now allowed in for range loops. llvm-svn: 229543
* Prefer SmallVector::append/insert over push_back loops. Clang edition.Benjamin Kramer2015-02-171-2/+1
| | | | | | Same functionality, but hoists the vector growth out of the loop. llvm-svn: 229508
* Wrap to 80 columns. No behavior change.Nico Weber2015-02-151-1/+2
| | | | llvm-svn: 229282
* Make a reference const. No behavior change.Nico Weber2015-02-141-1/+1
| | | | llvm-svn: 229242
* Add a warning for direct-list-initialization of a variable with a deduced typeRichard Smith2015-02-111-0/+8
| | | | | | | | (or of a lambda init-capture, which is sort-of such a variable). The semantics of such constructs will change when we implement N3922, so we intend to warn on this in Clang 3.6 then change the semantics in Clang 3.7. llvm-svn: 228792
* Sema: Don't give attribute alias vars with struct type an init exprDavid Majnemer2015-02-081-0/+2
| | | | | | | | | | We'd give the VarDecl a CXXConstructExpr even though it is annotated with an alias attribute. This would make us trip over sanity checking asserts. This fixes PR22493. llvm-svn: 228523
* [MSVC2012] Allow 'mutable' referencesAlexey Bataev2015-02-041-3/+6
| | | | | | | | Some standard header files from MSVC2012 use 'mutable' on references, though it is directly prohibited by the standard. Fix for http://llvm.org/PR22444 Differential Revision: http://reviews.llvm.org/D7370 llvm-svn: 228113
* Weaken an assertion that isn't true for invalid input.Nico Weber2015-01-301-2/+3
| | | | llvm-svn: 227540
* Revert "Sema: err_after_alias is unreachable, remove it"David Majnemer2015-01-211-1/+5
| | | | | | This reverts commit r226626. err_after_alias is, in fact, reachable. llvm-svn: 226633
* Sema: err_after_alias is unreachable, remove itDavid Majnemer2015-01-211-5/+1
| | | | | | | Examples this would have catched are now handled by the attribute verification code. llvm-svn: 226626
* Correct all typos in the initialization arguments, even if one could notKaelyn Takata2015-01-211-3/+4
| | | | | | | | | | be corrected. This fixes PR22250, which exposed the bug where if there's more than one TypoExpr in the arguments, once one failed to be corrected none of the TypoExprs after it would be handled at all thanks to an early return. llvm-svn: 226624
* Fix crashes on missing @interface for categoryBen Langmuir2015-01-201-1/+4
| | | | | | | In a few places we didn't check that Category->getClassInterface() was not null before using it. llvm-svn: 226605
* Add back a check removed in r226436David Majnemer2015-01-191-2/+12
| | | | | | | It shouldn't have been removed, the code which replaced it didn't cover this case. llvm-svn: 226442
* Sema: Variable definitions cannot be __attribute__((alias))David Majnemer2015-01-191-24/+14
| | | | | | | | | | | | | | | | | | | | Things that are OK: extern int var1 __attribute((alias("v1"))); static int var2 __attribute((alias("v2"))); Things that are not OK: int var3 __attribute((alias("v3"))); extern int var4 __attribute((alias("v4"))) = 4; We choose to accpet: struct S { static int var5 __attribute((alias("v5"))); }; This code causes assertion failues in GCC 4.8 and ICC 13.0.1, we have no reason to reject it. This partially fixes PR22217. llvm-svn: 226436
* 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
OpenPOWER on IntegriCloud