summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [X86] Add immediate range checks for many of the builtins.Craig Topper2016-05-151-32/+234
| | | | llvm-svn: 269619
* Improve diagnostic checking for va_start to also warn on other instances of ↵Aaron Ballman2016-04-241-3/+10
| | | | | | | | undefined behavior, such as a parameter declared with the register keyword in C, or a parameter of a type that undergoes default argument promotion. This helps cover some more of the CERT secure coding rule EXP58-CPP. Pass an object of the correct type to va_start (https://www.securecoding.cert.org/confluence/display/cplusplus/EXP58-CPP.+Pass+an+object+of+the+correct+type+to+va_start). llvm-svn: 267338
* Revert the bool portion of r267054Richard Trieu2016-04-221-12/+4
| | | | | | | Remove the floating point to bool conversion warnings. Some of these conversions will be caught by -Wliteral-conversion and -Wfloat-conversion llvm-svn: 267234
* Split interesting warnings off from -Wfloat-conversionRichard Trieu2016-04-211-27/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Restructure the implict floating point to integer conversions so that interesting sub-groups are under different flags. Breakdown of warnings: No warning: Exact conversions from floating point to integer: int x = 10.0; int x = 1e10; -Wliteral-conversion - Floating point literal to integer with rounding: int x = 5.5; int x = -3.4; -Wfloat-conversion - All conversions not covered by the above two: int x = GetFloat(); int x = 5.5 + 3.5; -Wfloat-zero-conversion - The expression converted has a non-zero floating point value that gets converted to a zero integer value, excluded the cases falling under -Wliteral-conversion. Subset of -Wfloat-conversion. int x = 1.0 / 2.0; -Wfloat-overflow-conversion - The floating point value is outside the range of the integer type, exluding cases from -Wliteral conversion. Subset of -Wfloat-conversion. char x = 500; char x = -1000; -Wfloat-bool-conversion - Any conversion of a floating point type to bool. Subset of -Wfloat-conversion. if (GetFloat()) {} bool x = 5.0; -Wfloat-bool-constant-conversion - Conversion of a compile time evaluatable floating point value to bool. Subset of -Wfloat-bool-conversion. bool x = 1.0; bool x = 4.0 / 20.0; Also add EvaluateAsFloat to Sema, which is similar to EvaluateAsInt, but for floating point values. llvm-svn: 267054
* Clarifying the wording of this diagnostic; it confused parameter and argument.Aaron Ballman2016-04-181-1/+1
| | | | llvm-svn: 266644
* NFC: unify clang / LLVM atomic orderingJF Bastien2016-04-181-7/+7
| | | | | | | | | | | | | This makes the C11 / C++11 *ABI* atomic ordering accessible from LLVM, as discussed in http://reviews.llvm.org/D18200#inline-151433 This re-applies r266574 which I had reverted in r266575. Depends on http://reviews.llvm.org/D18875 Original review: http://reviews.llvm.org/D18876 llvm-svn: 266641
* Revert "NFC: unify clang / LLVM atomic ordering"JF Bastien2016-04-171-7/+7
| | | | | | | | This reverts commit b0495df9eae2824bee830cc4c94f5441f0d4cbc9. Same as for the corresponding LLVM revert, an assert seems to fire. llvm-svn: 266575
* NFC: unify clang / LLVM atomic orderingJF Bastien2016-04-171-7/+7
| | | | | | | | | | | | | | | Summary: Depends on http://reviews.llvm.org/D18875 This makes the C11 / C++11 *ABI* atomic ordering accessible from LLVM, as discussed in http://reviews.llvm.org/D18200#inline-151433 Reviewers: jyknight, reames Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18876 llvm-svn: 266574
* AArch64: allow 64-bit access to sysregs.Tim Northover2016-04-131-1/+1
| | | | | | | | Although all the registers are actually 32-bits, I think we have to assume the high 32-bits could be RES0 (the ARM ARM is unclear). If so, reading as a 32-bit register can require extra zero extension operations. llvm-svn: 266212
* Fix -Wdynamic-class-memaccess to skip invalid classes.Richard Trieu2016-03-311-1/+1
| | | | | | | | | This warning sometimes will infinitely recurse on CXXRecordDecl's from ill-formed recursive classes that have fields of themselves. Skip processing these classes to prevent this from happening. Fixes https://llvm.org/bugs/show_bug.cgi?id=27142 llvm-svn: 264991
* Fix deduction of __atomic_load's parameter types.Eric Fiselier2016-03-301-10/+13
| | | | | | | | | | | | | | Summary: __atomic_load's allows it's first argument to be a pointer to a const type. However the second argument is an output parameter and must be a pointer to non-const. This patch fixes the signature of __atomic_load generated by clang so that it respects the above requirements. Reviewers: rsmith, majnemer Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13420 llvm-svn: 264967
* [OpenCL] Fix pipe builtin bugsXiuli Pan2016-03-301-6/+8
| | | | | | | | | | | | | | | Summary: 1. Diag should be output if types are not the same. 2. Should compare using canonical type. 3. Refine the diag to be more clear. Reviewers: yaxunl, Anastasia Subscribers: MatsPetersson, pekka.jaaskelainen, cfe-commits Differential Revision: http://reviews.llvm.org/D17955 llvm-svn: 264825
* [Sema] Handle UTF-8 invalid format string specifiersBruno Cardoso Lopes2016-03-291-6/+37
| | | | | | | | | | | | | | | | | Improve invalid format string specifier handling by printing out invalid specifiers characters with \x, \u and \U. Previously clang would print gargabe whenever the character is unprintable. Example, before: NSLog(@"%\u25B9"); => warning: invalid conversion specifier ' [-Wformat-invalid-specifier] after: NSLog(@"%\u25B9"); => warning: invalid conversion specifier '\u25b9' [-Wformat-invalid-specifier] Differential Revision: http://reviews.llvm.org/D18296 rdar://problem/24672159 llvm-svn: 264752
* Move the fixit for -Wformat-security to a note.Bob Wilson2016-03-151-5/+6
| | | | | | | | r263299 added a fixit for the -Wformat-security warning, but that runs into complications with our guideline that error recovery should be done as-if the fixit had been applied. Putting the fixit on a note avoids that. llvm-svn: 263584
* Add fix-it for format-security warnings.Bob Wilson2016-03-111-9/+21
| | | | llvm-svn: 263299
* [OpenCL] Refine pipe builtin supportXiuli Pan2016-03-041-44/+52
| | | | | | | | | | | | | | Summary: Refine the type builtin support as the request with http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160201/148637.html Reviewers: pekka.jaaskelainen, Anastasia, yaxunl Subscribers: rsmith, cfe-commits Differential Revision: http://reviews.llvm.org/D16876 llvm-svn: 262692
* Reduce false positives in printf/scanf format checkerAndy Gibbs2016-02-261-34/+145
| | | | | | | | | | | | | | | Summary: The printf/scanf format checker is a little over-zealous in handling the conditional operator. This patch reduces work by not checking code-paths that are never used and reduces false positives regarding uncovered arguments, for example in the code fragment: printf(minimal ? "%i\n" : "%i: %s\n", code, msg); Reviewers: rtrieu Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15636 llvm-svn: 262025
* [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttrXiuli Pan2016-02-261-6/+4
| | | | | | | | | | | | | | | Summary: OpenCL access qualifiers are now not only used for image types, refine it to avoid misleading, Add semacheck for OpenCL access qualifier as well as test caees. Reviewers: pekka.jaaskelainen, Anastasia, aaron.ballman Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D16040 llvm-svn: 261961
* Make Sema::CheckFormatString a static function inside SemaChecking.cppAndy Gibbs2016-02-221-31/+46
| | | | | | | No functionality change. Change at the request of Richard Trieu, see http://reviews.llvm.org/D15636#357858. llvm-svn: 261522
* Remove use of builtin comma operator.Richard Trieu2016-02-181-9/+42
| | | | | | Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
* Sema: prevent assertion on stack return checkingSaleem Abdulrasool2016-02-151-2/+4
| | | | | | | | | | | | | | In the case that the array indexing itself is within a type dependent context, bail out of the evaluation. We would previously try to symbolically evaluate the expression which would then try to evaluate a non-address expression as an address, triggering an assertion in Asserts builds. We only need to consider the array subscript expression itself as in the case that the base itself being type dependent is handled appropriately in EvalAddr. Resolves PR26599. llvm-svn: 260867
* Sema: constify EvalAddr, EvalValSaleem Abdulrasool2016-02-151-139/+146
| | | | | | | Propagate const throughout these methods as they are non-mutating analyzers of state. NFC. llvm-svn: 260864
* Make -Wnull-conversion more useful.Richard Trieu2016-02-131-7/+14
| | | | | | | | | | When a null constant is used in a macro, walk through the macro stack to determine where the null constant is written and where the context is located. Only warn if both locations are within the same macro expansion. This helps function-like macros which involve pointers be treated as if they were functions. llvm-svn: 260776
* Fix remaining Clang-tidy readability-redundant-control-flow warnings; other ↵Eugene Zelenko2016-02-121-92/+62
| | | | | | | | minor fixes. Differential revision: http://reviews.llvm.org/D17218 llvm-svn: 260757
* [Sema] Issue a warning for integer overflow in nested struct initializerAkira Hatanaka2016-02-101-6/+14
| | | | | | | | | | | | | | | | | | | | | | | r257357 fixed clang to warn on integer overflow in struct initializers. However, it didn't warn when a struct had a nested initializer. This commit makes changes in Sema::CheckForIntOverflow to handle nested initializers. For example: struct s { struct t { unsigned x; } t; } s = { { .x = 4 * 1024 * 1024 * 1024 } }; rdar://problem/23526454 llvm-svn: 260360
* Exempt char array initializers from -Wconstant-converion.Richard Trieu2016-02-051-24/+39
| | | | | | | | Sometimes, char arrays are used as bit storage, with no difference made between signed and unsigned char. Thus, it is reasonable to use 0 to 255 instead of -128 to 127 and not trigger this warning. llvm-svn: 259947
* Improve -Wconstant-conversionRichard Trieu2016-01-291-1/+37
| | | | | | | | | | | | | | Switch the evaluation from isIntegerConstantExpr to EvaluateAsInt. EvaluateAsInt will evaluate more types of expressions than isIntegerConstantExpr. Move one case from -Wsign-conversion to -Wconstant-conversion. The case is: 1) Source and target types are signed 2) Source type is wider than the target type 3) The source constant value is positive 4) The conversion will store the value as negative in the target. llvm-svn: 259271
* Recommit: R258773 [OpenCL] Pipe builtin functionsXiuli Pan2016-01-261-0/+220
| | | | | | | | | | | | | | | | | Fix arc patch fuzz error. Summary: Support for the pipe built-in functions for OpenCL 2.0. The pipe builtin functions may have infinite kinds of element types, one approach would be to just generate calls that would always use generic types such as void*. This patch is based on bader's opencl support patch on SPIR-V branch. Reviewers: Anastasia, pekka.jaaskelainen Subscribers: keryell, bader, cfe-commits Differential Revision: http://reviews.llvm.org/D15914 llvm-svn: 258782
* Fix -Wnull-conversion for long macros.Richard Trieu2016-01-261-2/+2
| | | | | | | | | Move the function to get a macro name from DiagnosticRenderer.cpp to Lexer.cpp so that other files can use it. Lexer now has two functions to get the immediate macro name, the newly added one is better for diagnostic purposes. Make -Wnull-conversion use this function for better NULL macro detection. llvm-svn: 258778
* Revert "[OpenCL] Pipe builtin functions"David Majnemer2016-01-261-220/+0
| | | | | | | This reverts commit r258773, it broke the build bots: http://bb.pgr.jp/builders/cmake-clang-x86_64-linux/builds/43853 llvm-svn: 258775
* [OpenCL] Pipe builtin functionsXiuli Pan2016-01-261-0/+220
| | | | | | | | | | | | | | | | Summary: Support for the pipe built-in functions for OpenCL 2.0. The pipe builtin functions may have infinite kinds of element types, one approach would be to just generate calls that would always use generic types such as void*. This patch is based on bader's opencl support patch on SPIR-V branch. Reviewers: Anastasia, pekka.jaaskelainen Subscribers: keryell, bader, cfe-commits Differential Revision: http://reviews.llvm.org/D15914 llvm-svn: 258773
* [Sema] Improve constnessDaniel Marjamaki2016-01-251-9/+9
| | | | llvm-svn: 258673
* [Bugfix] Fix ICE on constexpr vector splat.George Burgess IV2016-01-131-1/+2
| | | | | | | | | | | | | In {CG,}ExprConstant.cpp, we weren't treating vector splats properly. This patch makes us treat splats more properly. Additionally, this patch adds a new cast kind which allows a bool->int cast to result in -1 or 0, instead of 1 or 0 (for true and false, respectively), so we can sanely model OpenCL bool->int casts in the AST. Differential Revision: http://reviews.llvm.org/D14877 llvm-svn: 257559
* [Sema] Issue a warning for integer overflow in struct initializerAkira Hatanaka2016-01-111-0/+4
| | | | | | | | | | | | | | | | Clang wasn't issuing a warning when compiling the following code: struct s { unsigned x; } s = { .x = 4 * 1024 * 1024 * 1024 }; rdar://problem/23399683 Differential Revision: http://reviews.llvm.org/D15097 llvm-svn: 257357
* Only take NULL macros instead of all macros into account for -Wnull-conversion.Richard Trieu2016-01-091-2/+6
| | | | llvm-svn: 257240
* Exclude function calls for functions which have return type nullptr_t fromRichard Trieu2016-01-081-0/+4
| | | | | | | | | -Wnull-conversion warning. These functions are basically equivalent to other pointer returning fuctions which are already excluded by -Wnull-conversion. llvm-svn: 257231
* When performing an implicit from float to bool, the floating point value ↵Aaron Ballman2015-12-301-1/+1
| | | | | | | | must be *exactly* zero in order for the conversion to result in 0. This does not involve a conversion through an integer value, and so truncation of the value is not performed. This patch address PR25876. llvm-svn: 256643
* Clean up this code, NFC.Richard Smith2015-12-301-8/+12
| | | | llvm-svn: 256607
* [Sema] Make an enum local to the only method that uses it. NFCCraig Topper2015-12-231-7/+5
| | | | llvm-svn: 256319
* [OpenCL] Fix atomic Builtins check for address spaces of non-atomic pointerAnastasia Stulova2015-12-221-2/+11
| | | | | | | | | | | If there are two pointers passed to an atomic Builtin, Clang doesn't allow the second (non-atomic) one to be qualified with an address space. Remove this restriction by recording the address space of passed pointers in atomics type diagnostics. llvm-svn: 256243
* [Sema] Add warning when comparing nonnull and nullGeorge Burgess IV2015-12-081-28/+45
| | | | | | | | | | | | | | | | | | Currently, we emit warnings in some cases where nonnull function parameters are compared against null. This patch extends this support to warn when comparing the result of `returns_nonnull` functions against null. More specifically, we will now warn cases like: int *foo() __attribute__((returns_nonnull)); int main() { if (foo() == NULL) {} // warning: will always evaluate to false } Differential Revision: http://reviews.llvm.org/D15324 llvm-svn: 255058
* PR17381: Treat undefined behavior during expression evaluation as an unmodeledRichard Smith2015-12-031-1/+1
| | | | | | | | | | | | | | | | | | | | | side-effect, so that we don't allow speculative evaluation of such expressions during code generation. This caused a diagnostic quality regression, so fix constant expression diagnostics to prefer either the first "can't be constant folded" diagnostic or the first "not a constant expression" diagnostic depending on the kind of evaluation we're doing. This was always the intent, but didn't quite work correctly before. This results in certain initializers that used to be constant initializers to no longer be; in particular, things like: float f = 1e100; are no longer accepted in C. This seems appropriate, as such constructs would lead to code being executed if sanitizers are enabled. llvm-svn: 254574
* Add the `pass_object_size` attribute to clang.George Burgess IV2015-12-021-1/+9
| | | | | | | | | | | | | `pass_object_size` is our way of enabling `__builtin_object_size` to produce high quality results without requiring inlining to happen everywhere. A link to the design doc for this attribute is available at the Differential review link below. Differential Revision: http://reviews.llvm.org/D13263 llvm-svn: 254554
* [coroutines] Factor out co_await representation into common base class for ↵Richard Smith2015-11-221-11/+9
| | | | | | co_await and co_yield, and use it to hold await_* calls. llvm-svn: 253811
* [Sema] Combine similar diagnostics using %select. NFCCraig Topper2015-11-171-5/+3
| | | | llvm-svn: 253315
* [Sema] Don't crash trying to diagnose abs called on a pointer typeDavid Majnemer2015-11-151-0/+13
| | | | | | | | | | | | | | | | | Clang tries to figure out if a call to abs is suspicious by looking through implicit casts to look at the underlying, implicitly converted type. Interestingly, C has implicit conversions from pointer-ish types like function to less exciting types like int. This trips up our 'abs' checker because it doesn't know which variant of 'abs' is appropriate. Instead, diagnose 'abs' called on function types upfront. This sort of thing is highly suspicious and is likely indicative of a missing pointer dereference/function call/array index operation. This fixes PR25532. llvm-svn: 253156
* Make SemaBuiltinCpuSupports a static function. NFC.Craig Topper2015-11-071-21/+21
| | | | llvm-svn: 252399
* Fix indentation. NFCCraig Topper2015-11-071-3/+3
| | | | llvm-svn: 252397
* Add support for __builtin_{add,sub,mul}_overflow.John McCall2015-10-291-0/+39
| | | | | | Patch by David Grayson! llvm-svn: 251651
* [Sema] Implement -Wdouble-promotion for clang.George Burgess IV2015-10-291-0/+8
| | | | | | | | | | | | | | | GCC has a warning called -Wdouble-promotion, which warns you when an implicit conversion increases the width of a floating point type. This is useful when writing code for architectures that can perform hardware FP ops on floats, but must fall back to software emulation for larger types (i.e. double, long double). This fixes PR15109 <https://llvm.org/bugs/show_bug.cgi?id=15109>. Thanks to Carl Norum for the patch! llvm-svn: 251588
OpenPOWER on IntegriCloud