aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-09-07[Sema] -Wtautological-compare: handle comparison of unsigned with 0S.Roman Lebedev1-28/+50
Summary: This is a first half(?) of a fix for the following bug: https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits) GCC's -Wtype-limits does warn on comparison of unsigned value with signed zero (as in, with 0), but clang only warns if the zero is unsigned (i.e. 0U). Also, be careful not to double-warn, or falsely warn on comparison of signed/fp variable and signed 0. Yes, all these testcases are needed. Testing: $ ninja check-clang-sema check-clang-semacxx Also, no new warnings for clang stage-2 build. Reviewers: rjmccall, rsmith, aaron.ballman Reviewed By: rjmccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D37565 llvm-svn: 312750
2017-09-05[ms] Implement the __annotation intrinsicReid Kleckner1-0/+26
llvm-svn: 312572
2017-08-15[OpenCL] Support variable memory scope in atomic builtinsYaxun Liu1-26/+11
Differential Revision: https://reviews.llvm.org/D36580 llvm-svn: 310924
2017-08-10[X86] Implement __builtin_cpu_isCraig Topper1-0/+23
This patch adds support for __builtin_cpu_is. I've tried to match the strings supported to the latest version of gcc. Differential Revision: https://reviews.llvm.org/D35449 llvm-svn: 310657
2017-08-09[OpenCL] Minor refactoring to reduce copy/pasted codeJoey Gouly1-8/+5
Set the type of TheCall inside SemaBuiltinReserveRWPipe to reduce duplicated code. llvm-svn: 310477
2017-08-08Sema: disable implicit conversion from _Complex to real types in C++.Tim Northover1-2/+5
Converting a _Complex type to a real one simply discards the imaginary part. This can easily lead to loss of information so for safety (and GCC compatibility) this patch disallows that when the conversion would be implicit. The one exception is bool, which actually compares both real and imaginary parts and so is safe. llvm-svn: 310427
2017-08-04Add OpenCL 2.0 atomic builtin functions as Clang builtinYaxun Liu1-16/+78
OpenCL 2.0 atomic builtin functions have a scope argument which is ideally represented as synchronization scope argument in LLVM atomic instructions. Clang supports translating Clang atomic builtin functions to LLVM atomic instructions. However it currently does not support synchronization scope of LLVM atomic instructions. Without this, users have to use LLVM assembly code to implement OpenCL atomic builtin functions. This patch adds OpenCL 2.0 atomic builtin functions as Clang builtin functions, which supports generating LLVM atomic instructions with synchronization scope operand. Currently only constant memory scope argument is supported. Support of non-constant memory scope argument will be added later. Differential Revision: https://reviews.llvm.org/D28691 llvm-svn: 310082
2017-08-01[OpenCL] Add missing subgroup builtinsJoey Gouly1-0/+32
This adds get_kernel_max_sub_group_size_for_ndrange and get_kernel_sub_group_count_for_ndrange. llvm-svn: 309678
2017-07-31[OpenCL] Add extension Sema check for subgroup builtinsJoey Gouly1-2/+23
Check the subgroup extension is enabled, before doing other Sema checks. llvm-svn: 309567
2017-07-17[AArch64] Add support for __builtin_ms_va_list on aarch64Martin Storsjo1-9/+8
Move builtins from the x86 specific scope into the global scope. Their use is still limited to x86_64 and aarch64 though. This allows wine on aarch64 to properly handle variadic functions. Differential Revision: https://reviews.llvm.org/D34475 llvm-svn: 308218
2017-07-17[SystemZ] Add support for IBM z14 processor (1/3)Ulrich Weigand1-0/+7
This patch series adds support for the IBM z14 processor. This part includes: - Basic support for the new processor and its features. - Support for low-level builtins mapped to new LLVM intrinsics. Support for the -fzvector extension to vector float and the new high-level vector intrinsics is provided by separate patches. llvm-svn: 308197
2017-07-07Fix crash parsing invalid codeOlivier Goffart1-0/+2
The code in the test caused a crash with this backtrace: RecordLayoutBuilder.cpp:2934: const clang::ASTRecordLayout &clang::ASTContext::getASTRecordLayout(const clang::RecordDecl *) const: Assertion `!D->isInvalidDecl() && "Cannot get layout of invalid decl!"' failed. [...] #7 0x00007f63963d845a __assert_fail_base (/usr/lib/libc.so.6+0x2c45a) #8 0x00007f63963d84d2 (/usr/lib/libc.so.6+0x2c4d2) #9 0x00007f63937a0631 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const /home/olivier/prog/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2935:3 #10 0x00007f63937a1ad5 getFieldOffset(clang::ASTContext const&, clang::FieldDecl const*) /home/olivier/prog/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:3057:37 #11 0x00007f6391869f14 clang::Sema::RefersToMemberWithReducedAlignment(clang::Expr*, llvm::function_ref<void (clang::Expr*, clang::RecordDecl*, clang::FieldDecl*, clang::CharUnits)>) /home/olivier/prog/llvm/tools/clang/lib/Sema/SemaChecking.cpp:12139:23 #12 0x00007f639186a2f8 clang::Sema::CheckAddressOfPackedMember(clang::Expr*) /home/olivier/prog/llvm/tools/clang/lib/Sema/SemaChecking.cpp:12190:1 #13 0x00007f6391a7a81c clang::Sema::CheckAddressOfOperand(clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation) /home/olivier/prog/llvm/tools/clang/lib/Sema/SemaExpr.cpp:11111:10 #14 0x00007f6391a7f5d2 clang::Sema::CreateBuiltinUnaryOp(clang::SourceLocation, clang::UnaryOperatorKind, clang::Expr*) /home/olivier/prog/llvm/tools/clang/lib/Sema/SemaExpr.cpp:11932:18 Fixing by bailing out for invalid classes. Differential Revision: https://reviews.llvm.org/D35108 llvm-svn: 307371
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