summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Minor fixes to for-loop warning.Richard Trieu2017-06-021-29/+22
| | | | | | | | | | | | | The warning for unchanged loop variables outputted a diagnostic that was dependent on iteration order from a pointer set, which is not always deterministic. Switch to a set vector, which allows fast querying and preserves ordering. Also make other minor changes in this area. Use more range-based for-loops. Remove limitation on SourceRanges that no logner exists. llvm-svn: 304519
* Fix PR32933: crash on lambda capture of VLAFaisal Vali2017-05-151-3/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://bugs.llvm.org/show_bug.cgi?id=32933 Turns out clang wasn't really handling vla's (*) in C++11's for-range entirely correctly. For e.g. This would lead to generation of buggy IR: void foo(int b) { int vla[b]; b = -1; // This store would affect the '__end = vla + b' for (int &c : vla) c = 0; } Additionally, code-gen would get confused when VLA's were reference-captured by lambdas, and then used in a for-range, which would result in an attempt to generate IR for '__end = vla + b' within the lambda's body - without any capture of 'b' - hence the assertion. This patch modifies clang, so that for VLA's it translates the end pointer approximately into: __end = __begin + sizeof(vla)/sizeof(vla->getElementType()) As opposed to the __end = __begin + b; I considered passing a magic value into codegen - or having codegen special case the '__end' variable when it referred to a variably-modified type, but I decided against that approach, because it smelled like I would be increasing a complicated form of coupling, that I think would be even harder to maintain than the above approach (which can easily be optimized (-O1) to refer to the run-time bound that was calculated upon array's creation or copied into the lambda's closure object). (*) why oh why gcc would you enable this by default?! ;) llvm-svn: 303026
* ANSIfy. No behavior change.Nico Weber2017-05-051-1/+1
| | | | llvm-svn: 302258
* [Sema][ObjC] Disallow jumping into ObjC fast enumeration loops.Akira Hatanaka2017-04-191-0/+1
| | | | | | | | rdar://problem/31635406 Differential Revision: https://reviews.llvm.org/D32187 llvm-svn: 300722
* [NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped EnumFaisal Vali2017-04-011-5/+10
| | | | | | | | - 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
* Look through CXXBindTemporaryExprs when checking CXXFunctionCastExprsDaniel Jasper2017-03-271-2/+8
| | | | | | | | | | | | for unused values. This fixes a regression caused by r298676, where constructor calls to classes with non-trivial dtor were marked as unused if the first argument is an initializer list. This is inconsistent (as the test shows) and also warns on a reasonbly common code pattern where people just call constructors to create and immediately destroy an object. llvm-svn: 298853
* Add support for attribute enum_extensibility.Akira Hatanaka2017-03-211-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for a new attribute that will be used to distinguish between extensible and inextensible enums. There are three main purposes of this attribute: 1. Give better control over when enum-related warnings are issued. For example, in the code below, clang will not issue a -Wassign-enum warning if the enum is marked "open": enum __attribute__((enum_extensibility(closed))) EnumClosed { B0 = 1, B1 = 10 }; enum __attribute__((enum_extensibility(open))) EnumOpen { C0 = 1, C1 = 10 }; enum EnumClosed ec = 100; // warning issued enum EnumOpen eo = 100; // no warning 2. Enable code-completion and debugging tools to offer better suggestions. 3. Make it easier for swift's clang importer to determine which swift type an enum should be mapped to. For more details, see the discussion I started on cfe-dev: http://lists.llvm.org/pipermail/cfe-dev/2017-February/052748.html rdar://problem/12764379 rdar://problem/23145650 Differential Revision: https://reviews.llvm.org/D30766 llvm-svn: 298332
* Factor out function to determine whether we're performing a templateRichard Smith2017-02-211-1/+1
| | | | | | | | | 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
* [Sema] Disallow returning a __block variable via a move.Akira Hatanaka2017-02-151-3/+5
| | | | | | | | | | | | | | | r274291 made changes to prefer calling a move constructor to calling a copy constructor when returning from a function. This caused programs to crash when a __block variable in the heap was moved out and used later. This commit fixes the bug by disallowing moving out of __block variables implicitly. rdar://problem/28181080 Differential Revision: https://reviews.llvm.org/D29908 llvm-svn: 295150
* Remove redundant passing around of a "ContainsAutoType" flag.Richard Smith2017-01-121-6/+3
| | | | | | | | | | | | This flag serves no purpose other than to prevent us walking through a type to check whether it contains an 'auto' specifier; this duplication of information is error-prone, does not appear to provide any performance benefit, and will become less practical once we support C++1z deduced class template types and eventually constrained types from the Concepts TS. No functionality change intended. llvm-svn: 291737
* [Sema] Avoid "case value not in enumerated type" warning for C++11 opaque enumsAlex Lorenz2016-12-081-1/+2
| | | | | | | | | | | | This commit ensures that the switch warning "case value not in enumerated type" isn't shown for opaque enums. We don't know the actual list of values in opaque enums, so that warning is incorrect. rdar://29230764 Differential Revision: https://reviews.llvm.org/D27299 llvm-svn: 289055
* Mass-rename the handful of error_* diagnostics to err_*.Richard Smith2016-12-021-5/+5
| | | | llvm-svn: 288545
* Add a warning for 'main' returning 'true' or 'false'.Richard Smith2016-11-291-0/+4
| | | | | | Patch by Joshua Hurwitz! llvm-svn: 288097
* [CUDA] Add Sema::CUDADiagBuilder and Sema::CUDADiagIf{Device,Host}Code().Justin Lebar2016-10-131-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Together these let you easily create diagnostics that - are never emitted for host code - are always emitted for __device__ and __global__ functions, and - are emitted for __host__ __device__ functions iff these functions are codegen'ed. At the moment there are only three diagnostics that need this treatment, but I have more to add, and it's not sustainable to write code for emitting every such diagnostic twice, and from a special wrapper in SemaCUDA.cpp. While we're at it, don't emit the function name in err_cuda_device_exceptions: It's not necessary to print it, and making this work in the new framework in the face of a null value for dyn_cast<FunctionDecl>(CurContext) isn't worth the effort. Reviewers: rnk Subscribers: cfe-commits, tra Differential Revision: https://reviews.llvm.org/D25139 llvm-svn: 284143
* PR25890: Fix incoherent error handling in PerformImplicitConversion andRichard Smith2016-10-061-0/+2
| | | | | | | | | | | | CheckSingleAssignmentConstraints. These no longer produce ExprError() when they have not emitted an error, and reliably inform the caller when they *have* emitted an error. This fixes some serious issues where we would fail to emit any diagnostic for invalid code and then attempt to emit code for an invalid AST, and conversely some issues where we would emit two diagnostics for the same problem. llvm-svn: 283508
* [CUDA] Disallow exceptions in device code.Justin Lebar2016-09-281-0/+4
| | | | | | | | | | Reviewers: tra Subscribers: cfe-commits, jhen Differential Revision: https://reviews.llvm.org/D25036 llvm-svn: 282646
* [ObjC] Warn on unguarded use of partial declarationErik Pilkington2016-08-161-1/+1
| | | | | | | | | | | | | | This commit adds a traversal of the AST after Sema of a function that diagnoses unguarded references to declarations that are partially available (based on availability attributes). This traversal is only done when we would otherwise emit -Wpartial-availability. This commit is part of a feature I proposed here: http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html Differential revision: https://reviews.llvm.org/D23003 llvm-svn: 278826
* P0305R0: Semantic analysis and code generation for C++17 init-statement for ↵Richard Smith2016-07-141-13/+10
| | | | | | | | | | 'if' and 'switch': if (stmt; condition) { ... } Patch by Anton Bikineev! Some minor formatting and comment tweets by me. llvm-svn: 275350
* [Sema] Implement C++14's DR1579: Prefer returning by converting move constructorErik Pilkington2016-06-301-40/+51
| | | | | | | | Fixes PR28096. Differential Revision: http://reviews.llvm.org/D21619 llvm-svn: 274291
* P0305R1: Parsing support for init-statements in 'if' and 'switch' statements.Richard Smith2016-06-291-3/+10
| | | | | | | | | | | | | | | | | | No semantic analysis yet. This is a pain to disambiguate correctly, because the parsing rules for the declaration form of a condition and of an init-statement are quite different -- for a token sequence that looks like a declaration, we frequently need to disambiguate all the way to the ')' or ';'. We could do better here in some cases by stopping disambiguation once we've decided whether we've got an expression or not (rather than keeping going until we know whether it's an init-statement declaration or a condition declaration), by unifying our parsing code for the two types of declaration and moving the syntactic checks into Sema; if this has a measurable impact on parsing performance, I'll look into that. llvm-svn: 274169
* Implement p0292r2 (constexpr if), a likely C++1z feature.Richard Smith2016-06-231-20/+57
| | | | llvm-svn: 273602
* Re-commit r273548, reverted in r273589, with a fix to not produceRichard Smith2016-06-231-98/+59
| | | | | | | | | | | | | | | | -Wfor-loop-analysis warnings for a for-loop with a condition variable. In such a case, the loop condition variable is modified on each iteration of the loop by definition. Original commit message: Rearrange condition handling so that semantic checks on a condition variable are performed before the other substatements of the construct are parsed, rather than deferring them until the end. This allows better error recovery from semantic errors in the condition, improves diagnostic order, and is a prerequisite for C++17 constexpr if. llvm-svn: 273600
* Revert r273548, "Rearrange condition handling so that semantic checks on a ↵Peter Collingbourne2016-06-231-58/+98
| | | | | | | | condition variable" as it caused a regression in -Wfor-loop-analysis. llvm-svn: 273589
* Rearrange condition handling so that semantic checks on a condition variableRichard Smith2016-06-231-98/+58
| | | | | | | | | are performed before the other substatements of the construct are parsed, rather than deferring them until the end. This allows better error recovery from semantic errors in the condition, improves diagnostic order, and is a prerequisite for C++17 constexpr if. llvm-svn: 273548
* Re-commit "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen2016-06-211-0/+8
| | | | | | | | | | MaterializeTemporaryExpr." Since D21243 fixes relative clang-tidy tests. This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed. llvm-svn: 273312
* Revert accidential "[MSVC] Late parsing of in-class defined member functions ↵Alexey Bataev2016-06-151-27/+0
| | | | | | | | in template" This reverts commit 0253605771b8bd9d414aba74fe2742c730d6fd1a. llvm-svn: 272776
* [MSVC] Late parsing of in-class defined member functions in templateAlexey Bataev2016-06-151-0/+27
| | | | | | | | | | | | | | | | | | | classes. MSVC actively uses unqualified lookup in dependent bases, lookup at the instantiation point (non-dependent names may be resolved on things declared later) etc. and all this stuff is the main cause of incompatibility between clang and MSVC. Clang tries to emulate MSVC behavior but it may fail in many cases. clang could store lexed tokens for member functions definitions within ClassTemplateDecl for later parsing during template instantiation. It will allow resolving many possible issues with lookup in dependent base classes and removing many already existing MSVC-specific hacks/workarounds from the clang code. llvm-svn: 272774
* Revert "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen2016-06-091-8/+0
| | | | | | | | | MaterializeTemporaryExpr." This reverts r272296, since there are clang-tidy failures that appear to be caused by this change. llvm-svn: 272310
* [Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.Tim Shen2016-06-091-0/+8
| | | | | | | | | | | These ExprWithCleanups are added for holding a RunCleanupsScope not for destructor calls; rather, they are for lifetime marks. This requires ExprWithCleanups to keep a bit to indicate whether it have cleanups with side effects (e.g. dtor calls). Differential Revision: http://reviews.llvm.org/D20498 llvm-svn: 272296
* [OPENMP] Pass scalar firstprivate vars by value.Alexey Bataev2016-05-171-3/+3
| | | | | | | | For better performance and to unify code with offloading part we pass scalar firstprivate values by value, instead of by reference. It will remove some extra copying operations. llvm-svn: 269751
* Test commitErik Pilkington2016-04-261-0/+1
| | | | llvm-svn: 267604
* P0184R0: Allow types of 'begin' and 'end' expressions in range-based for ↵Richard Smith2016-03-201-15/+19
| | | | | | loops to differ. llvm-svn: 263895
* Fix false positives for for-loop-analysis warningSteven Wu2016-03-101-0/+12
| | | | | | | | | | | | | | | Summary: For PseudoObjectExpr, the DeclMatcher need to search only all the semantics but also need to search pass OpaqueValueExpr for all potential uses for the Decl. Reviewers: thakis, rtrieu, rjmccall, doug.gregor Subscribers: xazax.hun, rjmccall, doug.gregor, cfe-commits Differential Revision: http://reviews.llvm.org/D17627 llvm-svn: 263087
* Implement support for [[nodiscard]] in C++1z that is based off existing ↵Aaron Ballman2016-03-071-6/+6
| | | | | | support for warn_unused_result, and treat it as an extension pre-C++1z. This also means extending the existing warn_unused_result attribute so that it can be placed on an enum as well as a class. llvm-svn: 262872
* Add -Wcomma warning to Clang.Richard Trieu2016-02-181-0/+28
| | | | | | | | | | | -Wcomma will detect and warn on most uses of the builtin comma operator. It currently whitelists the first and third statements of the for-loop. For other cases, the warning can be silenced by casting the first operand of the comma operator to void. Differential Revision: http://reviews.llvm.org/D3976 llvm-svn: 261278
* Remove use of builtin comma operator.Richard Trieu2016-02-181-1/+2
| | | | | | Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
* Don't copy a DenseMap just to do lookup in it.Benjamin Kramer2016-02-131-6/+1
| | | | | | | Also remove the now unused isPodLike specialization. DenseMap only uses it for copies. llvm-svn: 260822
* Fix a crash when there is a typo in the return statement.Manman Ren2016-02-041-0/+5
| | | | | | | | | | | | | | If the typo happens after a successful deduction for an earlier return statement, we should check if the deduced type is null before using it. The typo correction happens after we try to deduce the return type and we ignore the deduction from the typo and continue to typo correction. rdar://24342247 llvm-svn: 259820
* [SemaCXX] Fix crash-on-invalid while trying to deduce return type of a lambda.Argyrios Kyrtzidis2016-01-301-4/+5
| | | | | | rdar://22032373 llvm-svn: 259287
* Split RequireCompleteType into a function that actually requires that the typeRichard Smith2015-12-181-5/+4
| | | | | | | | | | | | | | | | | | | is complete (with an error produced if not) and a function that merely queries whether the type is complete. Either way we'll trigger instantiation if necessary, but only the former will diagnose and recover from missing module imports. The intent of this change is to prevent a class of bugs where code would call RequireCompleteType(..., 0) and then ignore the result. With modules, we must check the return value and use it to determine whether the definition of the type is visible. This also fixes a debug info quality issue: calls to isCompleteType do not trigger the emission of debug information for a type in limited-debug-info mode. This allows us to avoid emitting debug information for type definitions in more cases where we believe it is safe to do so. llvm-svn: 256049
* [OpenMP] Update target directive codegen to use 4.5 implicit data mappings.Samuel Antao2015-12-021-4/+3
| | | | | | | | | | | | | | | Summary: This patch implements the 4.5 specification for the implicit data maps. OpenMP 4.5 specification changes the default way data is captured into a target region. All the non-aggregate kinds are passed by value by default. This required activating the capturing by value during SEMA for the target region. All the non-aggregate values that can be encoded in the size of a pointer are properly casted and forwarded to the runtime library. On top of fixing the previous weird behavior for mapping pointers in nested data regions (an explicit map was always required), this also improves performance as the number of allocations/transactions to the device per non-aggregate map are reduced from two to only one - instead of passing a reference and the value, only the value passed. Explicit maps will be added later on once firstprivate, private, and map clauses' SEMA and parsing are available. Reviewers: hfinkel, rjmccall, ABataev Subscribers: cfe-commits, carlo.bertolli Differential Revision: http://reviews.llvm.org/D14940 llvm-svn: 254521
* [Sema] Minor formatting fixes. NFCCraig Topper2015-11-171-1/+1
| | | | llvm-svn: 253314
* Tweak how -Wunused-value interacts with macrosNico Weber2015-10-271-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Make the warning more strict in C mode. r172696 added code to suppress warnings from macro expansions in system headers, which checks `SourceMgr.isMacroBodyExpansion(E->IgnoreParens()->getExprLoc())`. Consider this snippet: #define FOO(x) (x) void f(int a) { FOO(a); } In C, the line `FOO(a)` is an `ImplicitCastExpr(ParenExpr(DeclRefExpr))`, while it's just a `ParenExpr(DeclRefExpr)` in C++. So in C++, `E->IgnoreParens()` returns the `DeclRefExpr` and the check tests the SourceLoc of `a`. In C, the `ImplicitCastExpr` has the effect of checking the SourceLoc of `FOO`, which is a macro body expansion, which causes the diagnostic to be skipped. It looks unintentional that clang does different things for C and C++ here, so use `IgnoreParenImpCasts` instead of `IgnoreParens` here. This has the effect of the warning firing more often than previously in C code – it now fires as often as it fires in C++ code. 2. Suppress the warning if it would warn on `UNREFERENCED_PARAMETER`. `UNREFERENCED_PARAMETER` is a commonly used macro on Windows and it happens to uselessly trigger -Wunused-value. As discussed in the thread "rfc: winnt.h's UNREFERENCED_PARAMETER() vs clang's -Wunused-value" on cfe-dev, fix this by special-casing this specific macro. (This costs a string comparison and some fast-path lexing per warning, but the warning is emitted rarely. It fires once in Windows.h itself, so this code runs at least once per TU including Windows.h, but it doesn't run hundreds of times.) http://reviews.llvm.org/D13969 llvm-svn: 251441
* [coroutines] Creation of promise object, lookup of operator co_await, buildingRichard Smith2015-10-271-28/+55
| | | | | | of await_* calls, and AST representation for same. llvm-svn: 251387
* [coroutines] Initial stub Sema functionality for handling coroutine await / ↵Richard Smith2015-10-221-6/+20
| | | | | | yield / return. llvm-svn: 250993
* Keep the IfStmt node even if the condition is invalidOlivier Goffart2015-10-111-17/+11
| | | | | | | This is important to keep the information in IDE or other tools even if the code contains a few errors llvm-svn: 249982
* Perform Objective-C lifetime adjustments before comparing deduced lambda ↵Douglas Gregor2015-10-011-2/+5
| | | | | | | | | | result types. Objective-C ARC lifetime qualifiers are dropped when canonicalizing function types. Perform the same adjustment before comparing the deduced result types of lambdas. Fixes rdar://problem/22344904. llvm-svn: 249065
* Simplify Sema::DeduceFunctionTypeFromReturnExpr and eliminae a redundant check.Douglas Gregor2015-10-011-7/+2
| | | | | | NFC llvm-svn: 249060
* Fix a potential APInt memory leak when using __attribute__((flag_enum)), andRichard Smith2015-09-041-3/+1
| | | | | | simplify the implementation a bit. llvm-svn: 246830
* fix typo; NFCSanjay Patel2015-08-281-1/+1
| | | | llvm-svn: 246303
OpenPOWER on IntegriCloud