aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema
AgeCommit message (Collapse)AuthorFilesLines
2017-07-07[ObjC] Avoid the -Wunguarded-availability warnings for protocolAlex Lorenz2-4/+12
requirements in protocol/class/category declarations The unguarded availability warnings in the protocol requirements of a protocol /class/category declaration can be avoided. This matches the behaviour of Swift's diagnostics. The warnings for deprecated/unavailable protocols are preserved. rdar://33156429 Differential Revision: https://reviews.llvm.org/D35061 llvm-svn: 307368
2017-07-05Fix test case in pre-C++11 mode; address Aaron Ballman's code review.Douglas Gregor1-2/+2
llvm-svn: 307202
2017-07-05Cope with Range-v3's CONCEPT_REQUIRES idiomDouglas Gregor1-0/+34
llvm-svn: 307197
2017-07-05Customize the SFINAE diagnostics for enable_if to provide the failed condition.Douglas Gregor2-7/+140
When enable_if disables a particular overload resolution candidate, rummage through the enable_if condition to find the specific condition that caused the failure. For example, if we have something like: template< typename Iter, typename = std::enable_if_t<Random_access_iterator<Iter> && Comparable<Iterator_value_type<Iter>>>> void mysort(Iter first, Iter last) {} and we call "mysort" with "std::list<int>" iterators, we'll get a diagnostic saying that the "Random_access_iterator<Iter>" requirement failed. If we call "mysort" with "std::vector<something_not_comparable>", we'll get a diagnostic saying that the "Comparable<...>" requirement failed. llvm-svn: 307196
2017-07-05[Sema] Don't allow -Wunguarded-availability to be silenced with redeclsErik Pilkington3-104/+114
Differential revision: https://reviews.llvm.org/D33816 llvm-svn: 307175
2017-07-05Address comments that escaped D33333Erich Keane1-7/+12
Patch By: Jen Yu Differential Revision:https://reviews.llvm.org/D34671 llvm-svn: 307172
2017-07-05[modules ts] Improve merging of module-private declarations.Richard Smith1-32/+60
These cases occur frequently for declarations in the global module (above the module-declaration) in a Modules TS module interface. When we merge a definition from another module into such a module-private definition, ensure that we transitively make everything lexically within that definition visible to that translation unit. llvm-svn: 307129
2017-07-05fix trivial typos in comments; NFCHiroshi Inoue1-1/+1
llvm-svn: 307123
2017-07-05[modules ts] Declarations from a module interface unit are only visible outsideRichard Smith3-18/+57
the module if declared in an export block. llvm-svn: 307115
2017-07-04[OpenCL] Rename err_opencl_enqueue_kernel_expected_typeJoey Gouly1-15/+18
Rename err_opencl_enqueue_kernel_expected_type so that other builtins can use the same diagnostic. https://reviews.llvm.org/D34948 llvm-svn: 307067
2017-07-04[Sema] Make BreakContinueFinder handle nested loops.Eli Friedman1-6/+61
We don't care about break or continue statements that aren't associated with the current loop, so make sure the visitor doesn't find them. Fixes https://bugs.llvm.org/show_bug.cgi?id=32648 . Differential Revision: https://reviews.llvm.org/D34568 llvm-svn: 307051
2017-07-03[clang] Implement -Wcast-qual for C++Roman Lebedev1-24/+70
Summary: This way, the behavior of that warning flag more closely resembles that of GCC. Do note that there is at least one false-negative (see FIXME in tests). Fixes PR4802. Testing: ``` ninja check-clang-sema check-clang-semacxx ``` Reviewers: dblaikie, majnemer, rnk Reviewed By: dblaikie, rnk Subscribers: mclow.lists, cfe-commits, alexfh, rnk Differential Revision: https://reviews.llvm.org/D33102 llvm-svn: 307045
2017-07-03Add a fixit for -Wobjc-protocol-property-synthesisAlex Lorenz1-4/+10
rdar://32132756 Differential Revision: https://reviews.llvm.org/D34886 llvm-svn: 307014
2017-07-01[modules] Teach clang how to merge typedef over anonymous structs in C mode.Vassil Vassilev1-3/+2
In C mode clang fails to merge the textually included definition with the one imported from a module. The C lookup rules fail to find the imported definition because its linkage is internal in non C++ mode. This patch reinstates some of the ODR merging rules for typedefs of anonymous tags for languages other than C++. Patch by Raphael Isemann and me (D34510). llvm-svn: 306964
2017-07-01[OpenMP] Fix mapping of scalars for combined directivesJonas Hahnfeld1-3/+26
Combined directives like 'target parallel' have two captured statements. Sema has to check the right one from the right direction. Previously, Sema::IsOpenMPCapturedByRef would return false for mapped scalars on combined directives. This results in a wrong signature of the outlined function which triggers an assertion: void llvm::CallInst::init(llvm::FunctionType *, llvm::Value *, ArrayRef<llvm::Value *>, ArrayRef<OperandBundleDef>, const llvm::Twine &): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed. Fixes PR30975 (and PR31985). New function was taken from clang-ykt. Differential Revision: https://reviews.llvm.org/D34888 llvm-svn: 306956
2017-07-01fix trivial typos; NFCHiroshi Inoue1-1/+1
llvm-svn: 306954
2017-07-01[Modules] Implement ODR-like semantics for tag types in C/ObjCBruno Cardoso Lopes2-6/+92
Allow ODR for ObjC/C in the sense that we won't keep more that one definition around (merge them). However, ensure the decl pass the structural compatibility check in C11 6.2.7/1, for that, reuse the structural equivalence checks used by the ASTImporter. Few other considerations: - Create error diagnostics for tag types mismatches and thread them into the structural equivalence checks. - Note that by doing this we only support redefinition between types that are considered "compatible types" by C. This is mixed approach of the suggestions discussed in http://lists.llvm.org/pipermail/cfe-dev/2017-March/053257.html Differential Revision: https://reviews.llvm.org/D31778 rdar://problem/31909368 llvm-svn: 306918
2017-06-30[OpenCL] Add function name to extension diagnosticJoey Gouly1-2/+3
Slightly improve the diagnostic by including the function name. llvm-svn: 306827
2017-06-30fix trivial typos, NFCHiroshi Inoue1-1/+1
llvm-svn: 306789
2017-06-29[Sema] Issue diagnostics if a new/delete expression generates a call toAkira Hatanaka1-0/+26
a c++17 aligned allocation/deallocation function that is unavailable in the standard library on Apple platforms. The aligned functions are implemented only in the following versions or later versions of the OSes, so clang issues diagnostics if the deployment target being targeted is older than these: macosx: 10.13 ios: 11.0 tvos: 11.0 watchos: 4.0 The diagnostics are issued whenever the aligned functions are selected except when the selected function has a definition in the same file. If there is a user-defined function available somewhere else, option -Wno-aligned-allocation-unavailable can be used to silence the diagnostics. rdar://problem/32664169 Differential Revision: https://reviews.llvm.org/D34574 llvm-svn: 306722
2017-06-29Fixed -Wexceptions derived-to-base false positivesStephan Bergmann1-1/+5
...as introduced with recent <https://reviews.llvm.org/D33333> "Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier". (The equivalent of the goodReference case hit when building LibreOffice.) (These warnings are apparently only emitted when no errors have yet been encountered, so it didn't work to add the test code to the end of the existing clang/test/SemaCXX/exceptions.cpp.) llvm-svn: 306715
2017-06-29Revert r306653, "[OpenCL] Allow function declaration with empty argument list."NAKAMURA Takumi1-1/+1
It broke bots. llvm-svn: 306660
2017-06-29[OpenCL] Allow function declaration with empty argument list.Alexey Bader1-1/+1
Summary: does it make sense to enable K&R function declaration style for OpenCL? clang throws following error message for the declaration w/o arguments: ``` int my_func(); error: function with no prototype cannot use the spir_function calling convention ``` Current way to fix this issue is to specify that parameter list is empty by using 'void': ``` int my_func(void); ``` Let me know what do you think about this patch. Reviewers: Anastasia, yaxunl Reviewed By: Anastasia Subscribers: cfe-commits, echuraev Differential Revision: https://reviews.llvm.org/D33681 llvm-svn: 306653
2017-06-28Fix crash in clang while handling __has_trivial_destructor.Karthik Bhat1-9/+11
Fix crash in clang when an array of unknown bounds of an incomplete type is passed to __has_trivial_destructor. Patch by Puneetha https://reviews.llvm.org/D34198 llvm-svn: 306519
2017-06-27[Sema] Allow unmarked overloadable functions.George Burgess IV1-24/+69
This patch extends the `overloadable` attribute to allow for one function with a given name to not be marked with the `overloadable` attribute. The overload without the `overloadable` attribute will not have its name mangled. So, the following code is now legal: void foo(void) __attribute__((overloadable)); void foo(int); void foo(float) __attribute__((overloadable)); In addition, this patch fixes a bug where we'd accept code with `__attribute__((overloadable))` inconsistently applied. In other words, we used to accept: void foo(void); void foo(void) __attribute__((overloadable)); But we will do this no longer, since it defeats the original purpose of requiring `__attribute__((overloadable))` on all redeclarations of a function. This breakage seems to not be an issue in practice, since the only code I could find that had this pattern often looked like: void foo(void); void foo(void) __attribute__((overloadable)) __asm__("foo"); void foo(int) __attribute__((overloadable)); ...Which can now be simplified by simply removing the asm label and overloadable attribute from the redeclaration of `void foo(void);` Differential Revision: https://reviews.llvm.org/D32332 llvm-svn: 306467
2017-06-27Recommit r306103: PR26195: Set correct NestedNameSpecifierLoc for theAlex Lorenz1-0/+9
dependent initializer This commit fixes incorrect source positions of dependent c'tor initializers like in the following code: template<typename MyBase> struct Derived: MyBase::InnerIterator { Derived() : MyBase::InnerIterator() {} /// This line is problematic: all positions point to InnerIterator and nothing points to MyBase }; Patch by Serge Preis! Differential Revision: https://reviews.llvm.org/D32439 llvm-svn: 306392
2017-06-26Revert r301742, which caused us to try to evaluate all full-expressions.Richard Smith1-1/+23
Also add testcases for a bunch of expression forms that cause our evaluator to crash. See PR33140 and PR32864 for crashes that this was causing. This reverts r305287, which reverted r305239, which reverted r301742. The previous revert claimed that buildbots were broken, but did not add any testcases and the buildbots have lost all memory of what was wrong here. Changes to test/OpenMP are not reverted; another change has triggered those tests to change their output in the same way that r301742 did. llvm-svn: 306346
2017-06-26[clang] Enable printf check for CFIndexAlexander Shaposhnikov1-0/+1
According to https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html CFIndex and NSInteger should be treated the same way (see the section Platform Dependencies). This diff changes the function shouldNotPrintDirectly in SemaChecking.cpp accordingly and adds tests for the "fixit" and the warning. Differential revision: https://reviews.llvm.org/D34496 Test plan: make check-all llvm-svn: 306343
2017-06-26Check that the initializer of a non-dependent constexpr variable is constant ↵Richard Smith1-3/+1
even within templates. llvm-svn: 306327
2017-06-26[Sema] Fix a crash-on-invalid when a template parameter list has a classAkira Hatanaka3-6/+10
definition or non-reference class type. The crash occurs when there is a template parameter list in a class that is missing the closing angle bracket followed by a definition of a struct. For example: class C0 { public: template<typename T, typename T1 = T // missing closing angle bracket struct S0 {}; C0() : m(new S0<int>) {} S0<int> *m; }; This happens because the parsed struct is added to the scope of the enclosing class without having its access specifier set, which results in an assertion failure in SemaAccess.cpp later. This commit fixes the crash by adding the parsed struct to the enclosing file scope and marking structs as invalid if they are defined in template parameter lists. rdar://problem/31783961 rdar://problem/19570630 Differential Revision: https://reviews.llvm.org/D33606 llvm-svn: 306317
2017-06-23Emit warning when throw exception in destruct or dealloc functions which has a Erich Keane1-0/+150
(possible implicit) noexcept specifier Throwing in the destructor is not good (C++11 change try to not allow see below). But in reality, those codes are exist. C++11 [class.dtor]p3: A declaration of a destructor that does not have an exception-specification is implicitly considered to have the same exception specification as an implicit declaration. With this change, the application worked before may now run into runtime termination. My goal here is to emit a warning to provide only possible info to where the code may need to be changed. First there is no way, in compile time to identify the “throw” really throw out of the function. Things like the call which throw out… To keep this simple, when “throw” is seen, checking its enclosing function(only destructor and dealloc functions) with noexcept(true) specifier emit warning. Here is implementation detail: A new member function CheckCXXThrowInNonThrowingFunc is added for class Sema in Sema.h. It is used in the call to both BuildCXXThrow and TransformCXXThrowExpr. The function basic check if the enclosing function with non-throwing noexcept specifer, if so emit warning for it. The example of warning message like: k1.cpp:18:3: warning: ''~dependent_warn'' has a (possible implicit) non-throwing noexcept specifier. Throwing exception may cause termination. [-Wthrow-in-dtor] throw 1; ^ k1.cpp:43:30: note: in instantiation of member function 'dependent_warn<noexcept_fun>::~dependent_warn' requested here dependent_warn<noexcept_fun> f; // cause warning Differential Revision: https://reviews.llvm.org/D33333 llvm-svn: 306149
2017-06-23Revert r306103: "PR26195: Set correct NestedNameSpecifierLoc for theAlex Lorenz1-9/+0
dependent initializer" It caused buildbot failures such as this one: http://bb.pgr.jp/builders/test-clang-msc-x64-on-i686-linux-RA/builds/3777/steps/test_clang/logs/Clang%20%3A%3A%20Index__ctor-init-source-loc.cpp llvm-svn: 306111
2017-06-23PR26195: Set correct NestedNameSpecifierLoc for the dependent initializerAlex Lorenz1-0/+9
This commit fixes incorrect source positions of dependent c'tor initializers like in the following code: template<typename MyBase> struct Derived: MyBase::InnerIterator { Derived() : MyBase::InnerIterator() {} /// This line is problematic: all positions point to InnerIterator and nothing points to MyBase }; Patch by Serge Preis! Differential Revision: https://reviews.llvm.org/D32439 llvm-svn: 306103
2017-06-23PR33552: Distinguish between declarations that are owned by no module andRichard Smith5-10/+14
declarations that are owned but unconditionally visible. This allows us to set declarations as visible even if they have a local owning module, without losing information. In turn, that means that our Objective-C support can keep on incorrectly assuming the "hidden" bit on the declaration is the whole story with regard to name visibility. This will also be useful once we support the C++ Modules TS export semantics. Objective-C name visibility is still incorrect in any case where the "hidden" bit is not the complete story: for instance, in Objective-C++ the set of visible categories will be wrong during template instantiation, and with local submodule visibility enabled it will be wrong when building modules. Fixing that will require a major overhaul of how visibility is handled for Objective-C (and particularly for categories). llvm-svn: 306075
2017-06-22PR33002: When we instantiate the definition of a static data member, we mightRichard Smith1-4/+0
have attached an initializer to the in-class declaration. If so, include the initializer in the update record for the instantiation. llvm-svn: 306065
2017-06-22[Sema] Add -Wunguarded-availability-newAlex Lorenz1-5/+55
The new compiler warning -Wunguarded-availability-new is a subset of -Wunguarded-availability. It is on by default. It only warns about uses of APIs that have been introduced in macOS >= 10.13, iOS >= 11, watchOS >= 4 and tvOS >= 11. We decided to use this kind of solution as we didn't want to turn on -Wunguarded-availability by default, because we didn't want our users to get warnings about uses of old APIs in their existing projects. rdar://31054725 Differential Revision: https://reviews.llvm.org/D34264 llvm-svn: 306033
2017-06-21Function with unparsed body is a definitionSerge Pavlov4-6/+7
While a function body is being parsed, the function declaration is not considered as a definition because it does not have a body yet. In some cases it leads to incorrect interpretation, the case is presented in https://bugs.llvm.org/show_bug.cgi?id=14785: ``` template<typename T> struct Somewhat { void internal() const {} friend void operator+(int const &, Somewhat<T> const &) {} }; void operator+(int const &, Somewhat<char> const &x) { x.internal(); } ``` When statement `x.internal()` in the body of global `operator+` is parsed, the type of `x` must be completed, so the instantiation of `Somewhat<char>` is started. It instantiates the declaration of `operator+` defined inline, and makes a check for redefinition. The check does not detect another definition because the declaration of `operator+` is still not defining as does not have a body yet. To solves this problem the function `isThisDeclarationADefinition` considers a function declaration as a definition if it has flag `WillHaveBody` set. This change fixes PR14785. Differential Revision: https://reviews.llvm.org/D30375 This is a recommit of 305379, reverted in 305381, with small changes. llvm-svn: 305903
2017-06-20Prevent devirtualization of calls to un-instantiated functions.Sunil Srivastava3-0/+8
PR 27895 Differential Revision: https://reviews.llvm.org/D22057 llvm-svn: 305862
2017-06-20Fix for Bug 33471: Preventing operator auto from resolving to a template ↵Erich Keane1-0/+10
operator. As the bug report says, struct A { template<typename T> operator T(); }; void foo() { A().operator auto(); } causes: "undeduced type in IR-generation UNREACHABLE executed at llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:208!" The problem is that in this case, "T" is being deduced as "auto", which I believe is incorrect. The 'operator auto' implementation in Clang is standards compliant, however there is a defect report against core (1670). Differential Revision: https://reviews.llvm.org/D34370 llvm-svn: 305812
2017-06-20[OpenCL] Diagnose scoped address-space qualified variablesAnastasia Stulova1-2/+16
Produce an error if variables qualified with a local or a constant address space are not declared in the outermost scope of a kernel. Patch by Simon Perretta. Differential Revision: https://reviews.llvm.org/D34024 llvm-svn: 305798
2017-06-16[XRay][clang] Support capturing the implicit `this` argument to C++ class ↵Dean Michael Berris1-6/+8
member functions Summary: Before this change, we couldn't capture the `this` pointer that's implicitly the first argument of class member functions. There are some interesting things we can do with capturing even just this single argument for zero-argument member functions. Reviewers: rnk, pelikan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34052 llvm-svn: 305544
2017-06-15[Completion] Code complete the members for a dependent type after a '::'Alex Lorenz1-3/+7
This commit is a follow up to r302797 which added support for dependent completions after the '.' and '->' operators. This commit adds support for dependent completions after the '::' operator. Differential Revision: https://reviews.llvm.org/D34173 llvm-svn: 305511
2017-06-15[coroutines] Remove pass-through operator co_await; Replace it with the ↵Eric Fiselier1-1/+7
input expression Reviewers: GorNishanov, rsmith Reviewed By: GorNishanov Differential Revision: https://reviews.llvm.org/D34216 llvm-svn: 305498
2017-06-14Reverted 305379 (Function with unparsed body is a definition)Serge Pavlov4-10/+7
It broke clang-x86_64-linux-selfhost-modules-2 and some other buildbots. llvm-svn: 305381
2017-06-14Function with unparsed body is a definitionSerge Pavlov4-7/+10
While a function body is being parsed, the function declaration is not considered as a definition because it does not have a body yet. In some cases it leads to incorrect interpretation, the case is presented in https://bugs.llvm.org/show_bug.cgi?id=14785: ``` template<typename T> struct Somewhat { void internal() const {} friend void operator+(int const &, Somewhat<T> const &) {} }; void operator+(int const &, Somewhat<char> const &x) { x.internal(); } ``` When statement `x.internal()` in the body of global `operator+` is parsed, the type of `x` must be completed, so the instantiation of `Somewhat<char>` is started. It instantiates the declaration of `operator+` defined inline, and makes a check for redefinition. The check does not detect another definition because the declaration of `operator+` is still not defining as does not have a body yet. To solves this problem the function `isThisDeclarationADefinition` considers a function declaration as a definition if it has flag `WillHaveBody` set. This change fixes PR14785. Differential Revision: https://reviews.llvm.org/D30375 llvm-svn: 305379
2017-06-14[coroutines] Fix co_await for range statementEric Fiselier2-37/+50
Summary: Currently we build the co_await expressions on the wrong implicit statements of the implicit ranged for; Specifically we build the co_await expression wrapping the range declaration, but it should wrap the begin expression. This patch fixes co_await on range for. Reviewers: rsmith, GorNishanov Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34021 llvm-svn: 305363
2017-06-13Fix spurious Wunused-lambda-capture warningYi Kong1-5/+11
Summary: Clang emits unused-lambda-capture warning for captures in generic lambdas even though they are actually used. Fixes PR31815. Reviewers: malcolm.parsons, aaron.ballman, rsmith Reviewed By: malcolm.parsons Subscribers: ahatanak, cfe-commits Differential Revision: https://reviews.llvm.org/D33526 llvm-svn: 305315
2017-06-13Revert "Revert r301742 which made ExprConstant checking apply to all ↵Diana Picus1-23/+1
full-exprs." This reverts commit r305239 because it broke the buildbots (the diag-flags.cpp test is failing). llvm-svn: 305287
2017-06-12Revert r301742 which made ExprConstant checking apply to all full-exprs.Nick Lewycky1-1/+23
This patch also exposed pre-existing bugs in clang, see PR32864 and PR33140#c3 . llvm-svn: 305239
2017-06-12[Sema][C++1z] Ensure binding in dependent range for have non-null typeErik Pilkington1-1/+5
Fixes PR32172 Differential revision: https://reviews.llvm.org/D34096 llvm-svn: 305195