aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
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-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-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-05-24[PowerPC] Implement vec_xxsldwi builtin.Tony Jiang1-0/+1
The vec_xxsldwi builtin is missing from altivec.h. This has been requested by developers working on libvpx for VP9 support for Google. The patch fixes PR: https://bugs.llvm.org/show_bug.cgi?id=32653 Differential Revision: https://reviews.llvm.org/D33236 llvm-svn: 303766
2017-05-24[PowerPC] Implement vec_xxpermdi builtin.Tony Jiang1-0/+61
The vec_xxpermdi builtin is missing from altivec.h. This has been requested by developers working on libvpx for VP9 support for Google. The patch fixes PR: https://bugs.llvm.org/show_bug.cgi?id=32653 Differential Revision: https://reviews.llvm.org/D33053 llvm-svn: 303760
2017-05-24Generalize two diagnostic messages to take function name as parameter.Tony Jiang1-3/+6
llvm-svn: 303753
2017-05-04Fix bugs checking va_start in lambdas and erroneous contextsReid Kleckner1-7/+14
Summary: First, getCurFunction looks through blocks and lambdas, which is wrong. Inside a lambda, va_start should refer to the lambda call operator prototype. This fixes PR32737. Second, we shouldn't use any of the getCur* methods, because they look through contexts that we don't want to look through (EnumDecl, CapturedStmtDecl). We can use CurContext directly as the calling context. Finally, this code assumed that CallExprs would never appear outside of code contexts (block, function, obj-c method), which is wrong. Struct member initializers are an easy way to create and parse exprs in a non-code context. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D32761 llvm-svn: 302188
2017-05-02Simplify some va_start checking logicReid Kleckner1-85/+82
Combine the logic doing the ms_abi/sysv_abi checks into one function so that each check and its logical opposite are near each other. Now we don't need two Sema entry points for MS va_start and regular va_start. Refactor the code that checks if the va_start caller is a function, block, or obj-c method. We do this in three places, and they are all buggy for variadic lambdas (PR32737). After this change, I have one place to apply the functional fix. NFC llvm-svn: 301968
2017-04-29Remove Sema::CheckForIntOverflow, and instead check all full-expressions.Nick Lewycky1-23/+1
CheckForIntOverflow used to implement a whitelist of top-level expressions to send to the constant expression evaluator, which handled many more expressions than the CheckForIntOverflow whitelist did. llvm-svn: 301742
2017-04-29ObjCBoxedExpr can't be evaluated by the constant expression evaluator.Nick Lewycky1-0/+3
A boxed expression evaluates its subexpr and then calls an objc method to transform it into another value with pointer type. The objc method can never be constexpr and therefore this expression can never be evaluated. Fixes a miscompile boxing expressions with side-effects. Also make ObjCBoxedExpr handling a normal part of the expression evaluator instead of being the only case besides full-expression where we check for integer overflow. llvm-svn: 301721
2017-04-21[OpenCL] Fix semantic check of ndrange_t for device_side_enqueue.Anastasia Stulova1-1/+1
Check unqualified type for ndrange argument in device_side_enqueue so device_side_enqueue accept const and volatile qualified ndranges. Differential Revision: https://reviews.llvm.org/D31458 Patch by Dmitry Borisenkov! llvm-svn: 300988
2017-04-18Remove unused varibleReid Kleckner1-4/+0
The Result variable is unused both in Sema::CheckARMBuiltinFunctionCall and Sema::CheckAArch64BuiltinFunctionCall, remove it. Patch by Wei-Ren Chen! Reviewers: craig.topper, rnk Reviewed By: rnk Subscribers: aemerson, cfe-commits, rengolin Differential Revision: https://reviews.llvm.org/D32014 llvm-svn: 300572
2017-03-31[Sema][X86] Update immediate check for gather/scatter prefetch instructions ↵Craig Topper1-1/+1
to match the _MM_HINT_T0/T1 constant definitions Our _MM_HINT_T0/T1 constant values are 3/2 which matches gcc, but not icc or Intel documentation. Interestingly gcc had this same bug on their implementation of the gather/scatter builtins at one point too. Fixes PR32411. llvm-svn: 299233
2017-03-31[mips][msa] Range adjustment for ldi_b builtin function operandPetar Jovanovic1-1/+1
Reasoning behind this change was allowing the function to accept all values from range [-128, 255] since all of them can be encoded in an 8bit wide value. This differs from the prior state where only range [-128, 127] was accepted, where values were assumed to be signed, whereas now the actual interpretation of the immediate is deferred to the consumer as required. Patch by Stefan Maksimovic. Differential Revision: https://reviews.llvm.org/D31082 llvm-svn: 299229
2017-03-31Spelling mistakes in comments. NFCI.Simon Pilgrim1-1/+1
llvm-svn: 299198
2017-03-30Spelling mistakes in comments. NFCI. (PR27635)Simon Pilgrim1-1/+1
llvm-svn: 299083
2017-03-14Warn on enum assignment to bitfields that can't fit all valuesReid Kleckner1-2/+55
This adds -Wbitfield-enum-conversion, which warns on implicit conversions that happen on bitfield assignment that change the value of some enumerators. Values of enum type typically take on a very small range of values, so they are frequently stored in bitfields. Unfortunately, there is no convenient way to calculate the minimum number of bits necessary to store all possible values at compile time, so users usually hard code a bitwidth that works today and widen it as necessary to pass basic testing and validation. This is very error-prone, and leads to stale widths as enums grow. This warning aims to catch such bugs. This would have found two real bugs in clang and two instances of questionable code. See r297680 and r297654 for the full description of the issues. This warning is currently disabled by default while we investigate its usefulness outside of LLVM. The major cause of false positives with this warning is this kind of enum: enum E { W, X, Y, Z, SENTINEL_LAST }; The last enumerator is an invalid value used to validate inputs or size an array. Depending on the prevalance of this style of enum across a codebase, this warning may be more or less feasible to deploy. It also has trouble on sentinel values such as ~0U. Reviewers: rsmith, rtrieu, thakis Reviewed By: thakis Subscribers: hfinkel, voskresensky.vladimir, sashab, cfe-commits Differential Revision: https://reviews.llvm.org/D30923 llvm-svn: 297761
2017-03-13[X86] Add checking of the scale argument to scatter/gather builtinsCraig Topper1-0/+107
The only valid values for scale immediate of scatter/gather builtins are 1, 2, 4, or 8. This patch enforces this in the frontend otherwise we generate invalid instruction encodings in the backend. Differential Revision: https://reviews.llvm.org/D30875 llvm-svn: 297642
2017-03-13When diagnosing taking address of packed members skip __unaligned-qualified ↵Roger Ferrer Ibanez1-0/+4
expressions Given that we have already explicitly stated in the qualifier that the expression is __unaligned, it makes little sense to diagnose that the address of the packed member may not be aligned. Differential Revision: https://reviews.llvm.org/D30884 llvm-svn: 297620
2017-03-12[AVX-512] Add range check for locality hint immediate on scatter/gather ↵Craig Topper1-0/+10
prefetch builtins. llvm-svn: 297590
2017-03-10[mips][msa] Remove range checks for non-immediate sld.[bhwd] instructionsPetar Jovanovic1-4/+0
Removes immediate range checks for these instructions, since they have GPR rt as their input operand. Patch by Stefan Maksimovic. Differential Revision: https://reviews.llvm.org/D30693 llvm-svn: 297485
2017-02-28[Sema] Detect more array index out of bounds when C++ overloaded operators ↵Daniel Marjamaki1-0/+6
are used Differential Revision: https://reviews.llvm.org/D30192 llvm-svn: 296477
2017-02-21Factor out function to determine whether we're performing a templateRichard Smith1-6/+6
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-2/+2
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
2017-01-28Change how we handle diagnose_if attributes.George Burgess IV1-12/+22
This patch changes how we handle argument-dependent `diagnose_if` attributes. In particular, we now check them in the same place that we check for things like passing NULL to Nonnull args, etc. This is basically better in every way than how we were handling them before. :) This fixes PR31638, PR31639, and PR31640. Differential Revision: https://reviews.llvm.org/D28889 llvm-svn: 293360
2017-01-09Use the same ABI logic for AArch64 Big Endian as in other placesJoerg Sonnenberger1-1/+2
covering polys. llvm-svn: 291437
2016-12-19Fix completely bogus types for some builtins:Richard Smith1-1/+3
* In C++, never create a FunctionNoProtoType for a builtin (fixes C++1z crasher from r289754). * Fix type of __sync_synchronize to be a no-parameter function rather than a varargs function. This matches GCC. * Fix type of vfprintf to match its actual type. We gave it a wrong type due to PR4290 (apparently autoconf generates invalid code and expects compilers to choke it down or it miscompiles the program; the relevant error in clang was downgraded to a warning in r122744 to fix other occurrences of this autoconf brokenness, so we don't need this workaround any more). * Turn off vararg argument checking for __noop, since it's not *really* a varargs function. Alternatively we could add custom type checking for it and synthesize parameter types matching the actual arguments in each call, but that seemed like overkill. llvm-svn: 290146
2016-12-14Fixing cast condition for removing casts from builtin FPClassification.Neil Hickey1-7/+10
The function SemaBuiltinFPClassification removed superfluous float to double casts, this was changed to also remove float to float casts but this isn't valid in all cases, for example when doing an rvaluetolvalue cast. Added a check to only remove if this was a conventional floating cast. Added additional tests into SemaOpenCL/extensions to cover these cases llvm-svn: 289650
2016-12-13Improve handling of floating point literals in OpenCL to only use double ↵Neil Hickey1-3/+4
precision if the target supports fp64. This change makes sure single-precision floating point types are used if the cl_fp64 extension is not supported by the target. Also removed the check to see whether the OpenCL version is >= 1.2, as this has been incorporated into the extension setting code. Differential Revision: https://reviews.llvm.org/D24235 llvm-svn: 289544
2016-12-12Use function_ref to avoid allocation in std::function. NFC.Benjamin Kramer1-1/+2
llvm-svn: 289433
2016-12-06Clean up some Sema checking code. NFCRichard Trieu1-44/+12
- Rename CheckMinZero to CheckMaxUnsignedZero to reflect its actual purpose. - Remove unused parameters from CheckAbsoluteValueFunction and CheckMaxUnsignedZero functions. - Refactor the function name check so both functions can use the same one. llvm-svn: 288756
2016-12-05Warn on unsigned zero in call to std::maxRichard Trieu1-0/+87
New default warning that triggers when an unsigned zero is used in a call to std::max. For unsigned values, zero is the minimum value, so any call to std::max is always equal to the other value. A common pattern was to take the max of zero and the difference of two unsigned values, not taking into account that unsigned values wrap around below zero. This warning also emits a note with a fixit hint to remove the zero and call to std::max. llvm-svn: 288732
2016-11-30[Sema] Teach -Wcast-align to look at the aligned attribute of theAkira Hatanaka1-0/+22
declared variables. Teach Sema to check the aligned attribute attached to variable declarations so that it doesn't issue spurious warnings. rdar://problem/26517471 Differential revision: https://reviews.llvm.org/D21099 llvm-svn: 288267
2016-11-23[Sema][Atomics] Treat expected pointer in compare exchange atomics as _NonnullAlex Lorenz1-0/+3
This commit teaches clang that is has to emit a warning when NULL is passed as the 'expected' pointer parameter into an atomic compare exchange call. rdar://18926650 Differential Revision: https://reviews.llvm.org/D26978 llvm-svn: 287776
2016-11-23[X86] Replace valignd/q builtins with appropriate __builtin_shufflevector.Craig Topper1-6/+0
llvm-svn: 287733
2016-11-18[ARM] Fix sema check of ARM special register namesOleg Ranevskyy1-1/+1
Summary: This is a simple sema check patch for arguments of `__builtin_arm_rsr` and the related builtins, which currently do not allow special registers with indexes >7. Some of the possible register name formats these builtins accept are: ``` {c}p<coprocessor>:<op1>:c<CRn>:c<CRm>:<op2> ``` ``` o0:op1:CRn:CRm:op2 ``` where `op1` / `op2` are integers in the range [0, 7] and `CRn` / `CRm` are integers in the range [0, 15]. The current sema check does not allow `CRn` > 7 and accepts `op2` up to 15. Reviewers: LukeCheeseman, rengolin Subscribers: asl, aemerson, rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D26464 llvm-svn: 287378
2016-11-16Add warning when assigning enums to bitfields without an explicit unsigned ↵Reid Kleckner1-1/+19
underlying type Summary: Add a warning when assigning enums to bitfields without an explicit unsigned underlying type. This is to prevent problems with MSVC compatibility, since the Microsoft ABI defaults to storing enums with a signed type, causing inconsistencies with saving to/reading from bitfields. Also disabled the warning in the dr0xx.cpp test which throws the error, and added a test for the warning. The warning can be disabled with -Wno-signed-enum-bitfield. Patch by Sasha Bermeister! Reviewers: rnk, aaron.ballman Subscribers: mehdi_amini, aaron.ballman, cfe-commits, thakis, dcheng Differential Revision: https://reviews.llvm.org/D24289 llvm-svn: 287177
2016-11-14[OpenCL] Fix for integer parameters of enqueue_kernelAnastasia Stulova1-19/+23
Make handling integer parameters more flexible: - For the number of events argument allow to pass larger integers than 32 bits as soon as compiler can prove that the range fits in 32 bits. If not, the diagnostic will be given. - Change type of the arguments specifying the sizes of the corresponding block arguments to be size_t. Review: https://reviews.llvm.org/D26509 llvm-svn: 286849
2016-11-14[OpenCL] Change to clk_event parameter in enqueue_kernel.Anastasia Stulova1-4/+8
- Accept NULL pointer as a valid parameter value for clk_event. - Generate clk_event_t arguments of internal __enqueue_kernel_XXX function as pointers in generic address space. Review: https://reviews.llvm.org/D26507 llvm-svn: 286836
2016-11-14Remove some false positives when taking the address of packed membersRoger Ferrer Ibanez1-15/+93
Differential Revision: https://reviews.llvm.org/D23657 llvm-svn: 286798
2016-11-12[AVX-512] Convert the rest of the masked shift by immediate and by single ↵Craig Topper1-11/+0
element builtins over to the newly added unmasked builtins and a select. This should also fix PR30691 since the new builtins are handled like the legacy builtins in the backend. llvm-svn: 286714
2016-11-07[AVX-512][Sema] Add more intrinsics to the checks for valid immediates for ↵Craig Topper1-0/+17
embedded rounding control arguments. llvm-svn: 286097
2016-11-01[AVX-512] Remove masked vector insert builtins and replace with native ↵Craig Topper1-14/+0
shufflevectors and selects. Unfortunately, the backend currently doesn't fold masks into the instructions correctly when they come from these shufflevectors. I'll work on that in a future commit. llvm-svn: 285667
2016-10-31[Sema] Warn when alignof is used with __builtin_alloca_with_alignDavid Majnemer1-1/+7
The second argument to __builtin_alloca_with_align is supposed to be in bits, not bytes. Using alignof there would be indicative of a bug. llvm-svn: 285609
2016-10-31Add support for __builtin_alloca_with_alignDavid Majnemer1-0/+34
__builtin_alloca always uses __BIGGEST_ALIGNMENT__ for the alignment of the allocation. __builtin_alloca_with_align allows the programmer to specify the alignment of the allocation. This fixes PR30658. llvm-svn: 285544
2016-10-31[AVX-512] Remove masked vector extract builtins and replace with native ↵Craig Topper1-14/+0
shufflevectors and selects. Unfortunately, the backend currently doesn't fold masks into the instructions correctly when they come from these shufflevectors. I'll work on that in a future commit. llvm-svn: 285540
2016-10-31[AVX-512] Remove many of the masked 128/256-bit shift builtins and replace ↵Craig Topper1-16/+0
them with unmasked builtins and selects. llvm-svn: 285539
2016-10-24Add support for __builtin_os_log_format[_buffer_size]Mehdi Amini1-60/+226
This reverts commit r285007 and reapply r284990, with a fix for the opencl test that I broke. Original commit message follows: These new builtins support a mechanism for logging OS events, using a printf-like format string to specify the layout of data in a buffer. The _buffer_size version of the builtin can be used to determine the size of the buffer to allocate to hold the data, and then __builtin_os_log_format can write data into that buffer. This implements format checking to report mismatches between the format string and the data arguments. Most of this code was written by Chris Willmore. Differential Revision: https://reviews.llvm.org/D25888 llvm-svn: 285019