aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-10-25Ignore implicity casts for zero-as-null-pointer-constant warningErich Keane1-1/+1
The repro in https://bugs.llvm.org/show_bug.cgi?id=34362 caused the left nullptr to be cast to a int* implicitly, which resulted diagnosing this falsely. Differential Revision: https://reviews.llvm.org/D39301 llvm-svn: 316605
2017-10-11[Modules TS] Diagnose missing/duplicate module-declaration.Richard Smith1-0/+11
llvm-svn: 315397
2017-09-20Implement C++ [basic.link]p8.Richard Smith1-21/+58
If a function or variable has a type with no linkage (and is not extern "C"), any use of it requires a definition within the same translation unit; the idea is that it is not possible to define the entity elsewhere, so any such use is necessarily an error. There is an exception, though: some types formally have no linkage but nonetheless can be referenced from other translation units (for example, this happens to anonymous structures defined within inline functions). For entities with those types, we suppress the diagnostic except under -pedantic. llvm-svn: 313729
2017-09-04Implement Itanium name mangling support for C++ Modules TS.Richard Smith1-2/+16
This follows the scheme agreed with Nathan Sidwell, which can be found here: https://gcc.gnu.org/wiki/cxx-modules?action=AttachFile This will be proposed to the itanium-cxx-abi list once we have some experience with how well it works; the ABI for this TS should be considered unstable until it is part of the Itanium C++ ABI. llvm-svn: 312467
2017-08-03Don't emit undefined-internal warnings for CXXDeductionGuideDecls.Richard Smith1-0/+3
Patch by ~paul (cynecx on phabricator)! Some test massaging by me. llvm-svn: 309975
2017-07-28Recommit r308327 3rd time: Add a warning for missingAlex Lorenz1-0/+54
'#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files The second recommit (r309106) was reverted because the "non-default #pragma pack value chages the alignment of struct or union members in the included file" warning proved to be too aggressive for external projects like Chromium (https://bugs.chromium.org/p/chromium/issues/detail?id=749197). This recommit makes the problematic warning a non-default one, and gives it the -Wpragma-pack-suspicious-include warning option. The first recommit (r308441) caused a "non-default #pragma pack value might change the alignment of struct or union members in the included file" warning in LLVM itself. This recommit tweaks the added warning to avoid warnings for #includes that don't have any records that are affected by the non-default alignment. This tweak avoids the previously emitted warning in LLVM. Original message: This commit adds a new -Wpragma-pack warning. It warns in the following cases: - When a translation unit is missing terminating #pragma pack (pop) directives. - When entering an included file if the current alignment value as determined by '#pragma pack' directives is different from the default alignment value. - When leaving an included file that changed the state of the current alignment value. rdar://10184173 Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 309386
2017-07-26Revert r309106 "Recommit r308327 2nd time: Add a warning for missing"Hans Wennborg1-54/+0
The warning fires on non-suspicious code in Chromium. Reverting until a solution is figured out. > Recommit r308327 2nd time: Add a warning for missing > '#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files > > The first recommit (r308441) caused a "non-default #pragma pack value might > change the alignment of struct or union members in the included file" warning > in LLVM itself. This recommit tweaks the added warning to avoid warnings for > #includes that don't have any records that are affected by the non-default > alignment. This tweak avoids the previously emitted warning in LLVM. > > Original message: > > This commit adds a new -Wpragma-pack warning. It warns in the following cases: > > - When a translation unit is missing terminating #pragma pack (pop) directives. > - When entering an included file if the current alignment value as determined > by '#pragma pack' directives is different from the default alignment value. > - When leaving an included file that changed the state of the current alignment > value. > > rdar://10184173 > > Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 309186
2017-07-26Recommit r308327 2nd time: Add a warning for missingAlex Lorenz1-0/+54
'#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files The first recommit (r308441) caused a "non-default #pragma pack value might change the alignment of struct or union members in the included file" warning in LLVM itself. This recommit tweaks the added warning to avoid warnings for #includes that don't have any records that are affected by the non-default alignment. This tweak avoids the previously emitted warning in LLVM. Original message: This commit adds a new -Wpragma-pack warning. It warns in the following cases: - When a translation unit is missing terminating #pragma pack (pop) directives. - When entering an included file if the current alignment value as determined by '#pragma pack' directives is different from the default alignment value. - When leaving an included file that changed the state of the current alignment value. rdar://10184173 Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 309106
2017-07-19Revert r308441 "Recommit r308327: Add a warning for missing '#pragma pack ↵Hans Wennborg1-54/+0
(pop)' and suspicious uses of '#pragma pack' in included files" This seems to have broken the sanitizer-x86_64-linux buildbot. Reverting until it's fixed, especially since this landed just before the 5.0 branch. > This commit adds a new -Wpragma-pack warning. It warns in the following cases: > > - When a translation unit is missing terminating #pragma pack (pop) directives. > - When entering an included file if the current alignment value as determined > by '#pragma pack' directives is different from the default alignment value. > - When leaving an included file that changed the state of the current alignment > value. > > rdar://10184173 > > Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 308455
2017-07-19Recommit r308327: Add a warning for missing '#pragma pack (pop)'Alex Lorenz1-0/+54
and suspicious uses of '#pragma pack' in included files This commit adds a new -Wpragma-pack warning. It warns in the following cases: - When a translation unit is missing terminating #pragma pack (pop) directives. - When entering an included file if the current alignment value as determined by '#pragma pack' directives is different from the default alignment value. - When leaving an included file that changed the state of the current alignment value. rdar://10184173 Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 308441
2017-07-18Don't set TUScope to null when generating a module in incremental processing ↵Raphael Isemann1-1/+2
mode. Summary: When in incremental processing mode, we should never set `TUScope` to a nullptr otherwise any future lookups fail. We already have similar checks in the rest of the code, but we never hit this one because so far we didn't try to generate a module from the AST that Cling generates. Reviewers: rsmith, v.g.vassilev Reviewed By: v.g.vassilev Subscribers: cfe-commits, v.g.vassilev Differential Revision: https://reviews.llvm.org/D35536 llvm-svn: 308333
2017-07-18Revert r308327Alex Lorenz1-54/+0
I forgot to test clang-tools-extra which is now failing. llvm-svn: 308328
2017-07-18Add a warning for missing '#pragma pack (pop)' and suspicious usesAlex Lorenz1-0/+54
of '#pragma pack' in included files This commit adds a new -Wpragma-pack warning. It warns in the following cases: - When a translation unit is missing terminating #pragma pack (pop) directives. - When entering an included file if the current alignment value as determined by '#pragma pack' directives is different from the default alignment value. - When leaving an included file that changed the state of the current alignment value. rdar://10184173 Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 308327
2017-07-05[modules ts] Declarations from a module interface unit are only visible outsideRichard Smith1-0/+12
the module if declared in an export block. llvm-svn: 307115
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-20Prevent devirtualization of calls to un-instantiated functions.Sunil Srivastava1-0/+3
PR 27895 Differential Revision: https://reviews.llvm.org/D22057 llvm-svn: 305862
2017-05-17[modules] When creating a declaration, cache its owning module immediatelyRichard Smith1-5/+4
rather than waiting until it's queried. Currently this is only applied to local submodule visibility mode, as we don't yet allocate storage for the owning module in non-local-visibility modules compilations. This reinstates r302965, reverted in r303037, with a fix for the reported crash, which occurred when reparenting a local declaration to be a child of a hidden imported declaration (specifically during template instantiation). llvm-svn: 303224
2017-05-15Revert r302965 - [modules] When creating a declaration, cache its owningDaniel Jasper1-4/+5
module immediately Also revert dependent r302969. This is leading to crashes. Will provide more details reproduction instructions to Richard. llvm-svn: 303037
2017-05-12[modules] When creating a declaration, cache its owning module immediatelyRichard Smith1-5/+4
rather than waiting until it's queried. Currently this is only applied to local submodule visibility mode, as we don't yet allocate storage for the owning module in non-local-visibility modules compilations. llvm-svn: 302965
2017-05-09Reland "Warn about unused static file scope function template declarations."Vassil Vassilev1-5/+27
This patch reinstates r299930, reverted in r299956, as a separate diagnostic option (-Wunused-template). llvm-svn: 302518
2017-05-05Introduce Wzero-as-null-pointer-constant.Nico Weber1-0/+14
Add an opt-in warning that fires when 0 is used as a null pointer. gcc has this warning, and there's some demand for it. https://reviews.llvm.org/D32914 llvm-svn: 302247
2017-04-26[OPENMP] Fix handling of OpenMP code during template instantiation.Alexey Bataev1-0/+7
If some function template is instantiated during handling of OpenMP code, currently it may cause crash of compiler because of trying of capturing variables in non-capturing function scopes. Patch fixes this bug. llvm-svn: 301416
2017-04-18Add #pragma clang attributeAlex Lorenz1-36/+31
This is a recommit of r300539 that was reverted in r300543 due to test failures. The original commit message is displayed below: The new '#pragma clang attribute' directive can be used to apply attributes to multiple declarations. An attribute must satisfy the following conditions to be supported by the pragma: - It must have a subject list that's defined in the TableGen file. - It must be documented. - It must not be late parsed. - It must have a GNU/C++11 spelling. Differential Revision: https://reviews.llvm.org/D30009 llvm-svn: 300556
2017-04-18Revert r300539 - Add #pragma clang attributeAlex Lorenz1-31/+36
Some tests fail on the Windows buildbots. I will have to investigate more. This commit reverts r300539, r300540 and r300542. llvm-svn: 300543
2017-04-18Add #pragma clang attributeAlex Lorenz1-36/+31
The new '#pragma clang attribute' directive can be used to apply attributes to multiple declarations. An attribute must satisfy the following conditions to be supported by the pragma: - It must have a subject list that's defined in the TableGen file. - It must be documented. - It must not be late parsed. - It must have a GNU/C++11 spelling. Differential Revision: https://reviews.llvm.org/D30009 llvm-svn: 300539
2017-04-11Revert temporarily D29877 "Warn about unused static file scope function ↵Vassil Vassilev1-14/+0
template declarations." We need to address cases (breaking libc++) such as template <class _Up> static int __test(...); template<typename _Tp> auto v = __test<_Tp>(0); llvm-svn: 299956
2017-04-11Warn about unused static file scope function template declarations.Vassil Vassilev1-0/+14
Reviewed by Richard Smith (D29877)! llvm-svn: 299930
2017-04-01[NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped EnumFaisal Vali1-2/+3
- also replace direct equality checks against the ConstantEvaluated enumerator with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17. - update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed. llvm-svn: 299316
2017-03-23Remove all uses of std::mem_fun and std::bind1st removed in C++17.Richard Smith1-1/+3
llvm-svn: 298657
2017-03-01[Sema] Add variable captured by a block to the enclosing lambda'sAkira Hatanaka1-3/+3
potential capture list. Fix Sema::getCurLambda() to return the innermost lambda scope when there is a block enclosed in the lambda. Previously, the method would return a nullptr in such cases, which would prevent a variable captured by the enclosed block to be added to the lambda scope's potential capture list. rdar://problem/28412462 Differential Revision: https://reviews.llvm.org/D25556 llvm-svn: 296584
2017-02-23Rename ActiveTemplateInstantiation to CodeSynthesisContext in preparation forRichard Smith1-2/+2
using it for other kinds of context (where we currently produce context notes in a highly ad-hoc manner). llvm-svn: 295919
2017-02-21Factor out function to determine whether we're performing a templateRichard Smith1-9/+4
instantiation. In preparation for converting the template stack to a more general context stack (so we can include context notes for other kinds of context). llvm-svn: 295686
2017-02-16[OpenCL] Correct ndrange_t implementationAnastasia Stulova1-1/+0
Removed ndrange_t as Clang builtin type and added as a struct type in the OpenCL header. Use type name to do the Sema checking in enqueue_kernel and modify IR generation accordingly. Review: D28058 Patch by Dmitry Borisenkov! llvm-svn: 295311
2016-12-18Recommit r289979 [OpenCL] Allow disabling types and declarations associated ↵Yaxun Liu1-21/+134
with extensions Fixed undefined behavior due to cast integer to bool in initializer list. llvm-svn: 290056
2016-12-16Revert r289979 due to regressionsYaxun Liu1-134/+21
llvm-svn: 289991
2016-12-16[OpenCL] Allow disabling types and declarations associated with extensionsYaxun Liu1-21/+134
Added a map to associate types and declarations with extensions. Refactored existing diagnostic for disabled types associated with extensions and extended it to declarations for generic situation. Fixed some bugs for types associated with extensions. Allow users to use pragma to declare types and functions for supported extensions, e.g. #pragma OPENCL EXTENSION the_new_extension_name : begin // declare types and functions associated with the extension here #pragma OPENCL EXTENSION the_new_extension_name : end Differential Revision: https://reviews.llvm.org/D21698 llvm-svn: 289979
2016-12-05DR1213: element access on an array xvalue or prvalue produces an xvalue. In theRichard Smith1-0/+12
latter case, a temporary array object is materialized, and can be lifetime-extended by binding a reference to the member access. Likewise, in an array-to-pointer decay, an rvalue array is materialized before being converted into a pointer. This caused IR generation to stop treating file-scope array compound literals as having static storage duration in some cases in C++; that has been rectified by modeling such a compound literal as an lvalue. This also improves clang's compatibility with GCC for those cases. llvm-svn: 288654
2016-11-28[MS] Mangle a unique ID into all MS inline asm labelsReid Kleckner1-1/+0
This solves PR23715 in a way that is compatible with LTO. MSVC supports jumping to source-level labels and between inline asm blocks, but we don't. Also revert the old solution, r255201, which was to mark these calls as noduplicate. llvm-svn: 288059
2016-11-11Fix for PR28523: unexpected compilation error.Alexey Bataev1-2/+10
Clang emits error message for the following code: ``` template <class F> void parallel_loop(F &&f) { f(0); } int main() { int x; parallel_loop([&](auto y) { { x = y; }; }); } ``` $ clang++ --std=gnu++14 clang_test.cc -o clang_test clang_test.cc:9:7: error: reference to local variable 'x' declared in enclosing function 'main' x = y; ^ clang_test.cc:2:48: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<int>' requested here template <class F> void parallel_loop(F &&f) { f(0); } ^ clang_test.cc:6:3: note: in instantiation of function template specialization 'parallel_loop<(lambda at clang_test.cc:6:17)>' requested here parallel_loop([&](auto y) { ^ clang_test.cc:5:7: note: 'x' declared here int x; ^ 1 error generated. Patch fixes this issue. llvm-svn: 286584
2016-10-28Sema: do not warn about unused const vars if main file is a headerErik Verbruggen1-2/+5
If we pass a header to libclang, e.g. because it's open in an editor in an IDE, warnings about unused const vars are not useful: other files that include the header might use those constants. So when -x *-header is passed as command-line option, suppress this warning. llvm-svn: 285386
2016-10-17Do not reset TUScope when we are in incremental processing mode.Vassil Vassilev1-2/+4
Patch by Axel Naumann! Reviewed by Richard Smith and me. llvm-svn: 284372
2016-10-10[Sema] Use unique_ptr instead of raw pointers in the late-parsed templates map.Justin Lebar1-1/+0
Summary: This is possible now that MapVector supports move-only values. Depends on D25404. Reviewers: timshen Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25405 llvm-svn: 283766
2016-10-04[coroutines] Switch to using std::experimental namespace per P0057R5Gor Nishanov1-2/+2
Summary: Look for coroutine_traits and friends in std::experimental namespace. Patch (mostly) by EricWF. Reviewers: cfe-commits, EricWF, rsmith Subscribers: majnemer, mehdi_amini Differential Revision: https://reviews.llvm.org/D25068 llvm-svn: 283170
2016-08-12P0217R3: template instantiation support for decomposition declarations.Richard Smith1-2/+1
llvm-svn: 278458
2016-08-11P0217R3: Perform semantic checks and initialization for the bindings in aRichard Smith1-1/+4
decomposition declaration for arrays, aggregate-like structs, tuple-like types, and (as an extension) for complex and vector types. llvm-svn: 278435
2016-07-18[NFC] Header cleanupMehdi Amini1-3/+1
Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
2016-06-25Fix unused variable warning after r273754.James Y Knight1-0/+1
llvm-svn: 273783
2016-06-25Implement C++17 P0386R2, inline variables. (The 'inline' specifier gives aRichard Smith1-5/+12
variable weak discardable linkage and partially-ordered initialization, and is implied for constexpr static data members.) llvm-svn: 273754
2016-06-21Re-commit "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen1-2/+3
MaterializeTemporaryExpr." Since D21243 fixes relative clang-tidy tests. This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed. llvm-svn: 273312
2016-06-09Revert "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen1-3/+2
MaterializeTemporaryExpr." This reverts r272296, since there are clang-tidy failures that appear to be caused by this change. llvm-svn: 272310