summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [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
* Skip NonNull sema checks in unevaluated contexts.Eric Fiselier2015-10-091-1/+2
| | | | | | | | | | | | | | Summary: Currently when a function annotated with __attribute__((nonnull)) is called in an unevaluated context with a null argument a -Wnonnull warning is emitted. This warning seems like a false positive unless the call expression is potentially evaluated. Change this behavior so that the non-null warnings use DiagRuntimeBehavior so they wont emit when they won't be evaluated. Reviewers: majnemer, rsmith Subscribers: mclow.lists, cfe-commits Differential Revision: http://reviews.llvm.org/D13408 llvm-svn: 249787
* Diagnose const atomics in __atomic builtins.Eric Fiselier2015-10-041-3/+10
| | | | | | | | | | | Diagnose when a pointer to const T is used as the first argument in at atomic builtin unless that builtin is a load operation. This is already checked for C11 atomics builtins but not for __atomic ones. This patch was given the LGTM by rsmith when it was part of a larger review. (See http://reviews.llvm.org/D10407) llvm-svn: 249252
* [CUDA] Add appropriate host/device attribute to builtins.Artem Belevich2015-09-221-1/+1
| | | | | | | | | The changes are part of attribute-based CUDA function overloading (D12453) and as such are only enabled when it's in effect (-fcuda-target-overloads). Differential Revision: http://reviews.llvm.org/D12122 llvm-svn: 248296
* Support __builtin_ms_va_list.Charles Davis2015-09-171-3/+48
| | | | | | | | | | | | | | | | | | Summary: This change adds support for `__builtin_ms_va_list`, a GCC extension for variadic `ms_abi` functions. The existing `__builtin_va_list` support is inadequate for this because `va_list` is defined differently in the Win64 ABI vs. the System V/AMD64 ABI. Depends on D1622. Reviewers: rsmith, rnk, rjmccall CC: cfe-commits Differential Revision: http://reviews.llvm.org/D1623 llvm-svn: 247941
* Introduce __builtin_nontemporal_store and __builtin_nontemporal_load.Michael Zolotukhin2015-09-081-0/+75
| | | | | | | | | | | | | Summary: Currently clang provides no general way to generate nontemporal loads/stores. There are some architecture specific builtins for doing so (e.g. in x86), but there is no way to generate non-temporal store on, e.g. AArch64. This patch adds generic builtins which are expanded to a simple store with '!nontemporal' attribute in IR. Differential Revision: http://reviews.llvm.org/D12313 llvm-svn: 247104
* [OPENMP 4.0] Initial support for array sections.Alexey Bataev2015-08-251-0/+13
| | | | | | | | Adds parsing/sema analysis/serialization/deserialization for array sections in OpenMP constructs (introduced in OpenMP 4.0). Currently it is allowed to use array sections only in OpenMP clauses that accepts list of expressions. Differential Revision: http://reviews.llvm.org/D10732 llvm-svn: 245937
* Revert r245496 "[CUDA] Add appropriate host/device attribute to builtins."Artem Belevich2015-08-201-1/+1
| | | | | | It's breaking internal test. llvm-svn: 245592
* [CUDA] Add appropriate host/device attribute to builtins.Artem Belevich2015-08-191-1/+1
| | | | | | Differential Revision: http://reviews.llvm.org/D12122 llvm-svn: 245496
* [ObjC] Circular containers: add support of subclassesAlex Denisov2015-08-061-114/+51
| | | | llvm-svn: 244193
* Rename the non-coding style conformant functions in namespace BuiltinsEric Christopher2015-08-061-3/+3
| | | | | | to match the rest of their brethren and reformat the bits that need it. llvm-svn: 244186
* Warn when an Objective-C collection literal element is converted to an ↵Douglas Gregor2015-07-071-0/+102
| | | | | | | | | | | | incompatible type. Objective-C collection literals produce unspecialized NSArray/NSDictionary objects that can then be implicitly converted to specialized versions of these types. In such cases, check that the elements in the collection are suitable for the specialized collection. Part of rdar://problem/6294649. llvm-svn: 241546
* Switch users of the 'for (StmtRange range = stmt->children(); range; ↵Benjamin Kramer2015-07-021-2/+2
| | | | | | | | | ++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. llvm-svn: 241300
* Parse 'technical term' format specifier.Ted Kremenek2015-07-021-1/+46
| | | | | | | | | | | | | | | | | | | | | | | Objective-C format strings now support modifier flags that can be attached to a '@' conversion. Currently the only one supported, as of iOS 9 and OS X 10.11, is the new "technical term", denoted by the flag "tt", for example: %[tt]@ instead of just: %@ The 'tt' stands for "technical term", which is used by the string-localization facilities on Darwin to add the appropriate spacing or quotation depending the language locale. Implements <rdar://problem/20374720>. llvm-svn: 241243
* Add support for the x86 builtin __builtin_cpu_supports.Eric Christopher2015-06-291-0/+22
| | | | | | | | | | | | | | | | | | | | This matches the implementation of the gcc support for the same feature, including checking the values set up by libgcc at runtime. The structure looks like this: unsigned int __cpu_vendor; unsigned int __cpu_type; unsigned int __cpu_subtype; unsigned int __cpu_features[1]; with a set of enums to match various fields that are field out after parsing the output of the cpuid instruction. This also adds a set of errors checking for valid input (and cpu). compiler-rt support for this and the other builtins in this family (__builtin_cpu_init and __builtin_cpu_is) are forthcoming. llvm-svn: 240994
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-7/+7
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-7/+7
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* Diagnose unsafe uses of nil and __nonnull pointers.Douglas Gregor2015-06-191-55/+124
| | | | | | | | | | | | | | | | | | | This generalizes the checking of null arguments to also work with values of pointer-to-function, reference-to-function, and block pointer type, using the nullability information within the underling function prototype to extend non-null checking, and diagnoses returns of 'nil' within a function with a __nonnull return type. Note that we don't warn about nil returns from Objective-C methods, because it's common for Objective-C methods to mimic the nil-swallowing behavior of the receiver by checking ostensibly non-null parameters and returning nil from otherwise non-null methods in that case. It also diagnoses (via a separate flag) conversions from nullable to nonnull pointers. It's a separate flag because this warning can be noisy. llvm-svn: 240153
* This patch implements clang support for the ACLE special register intrinsicsLuke Cheeseman2015-06-151-0/+121
| | | | | | | | | | | | | in section 10.1, __arm_{w,r}sr{,p,64}. This includes arm_acle.h definitions with builtins and codegen to support these, the intrinsics are implemented by generating read/write_register calls which get appropriately lowered in the backend based on the register string provided. SemaChecking is also implemented to fault invalid parameters. Differential Revision: http://reviews.llvm.org/D9697 llvm-svn: 239737
* [Sema] Make the atomic builtins more efficient by reducing volatilityDavid Majnemer2015-06-031-0/+4
| | | | | | | | The parameter types and return type do not need to be volatile just because the pointer type's pointee type is volatile qualified. This is an unnecessary pessimization. llvm-svn: 238892
* [Sema] Don't use dyn_cast to detect an AtomicTypeDavid Majnemer2015-05-231-1/+1
| | | | | | | | | | An AtomicType might be hidden behind arbitrary levels of typedefs. getAs<> will reliably walk through the sugar to get the underlying AtomicType. This fixes PR23638. llvm-svn: 238083
* [AArch64 ACLE] Allow to define poly64_t as 'unsigned long long' on LLP64 system.Kevin Qin2015-05-141-1/+4
| | | | | | This fixes PR23414 as well. llvm-svn: 237348
* [SystemZ] Add support for z13 low-level vector builtinsUlrich Weigand2015-05-051-1/+43
| | | | | | | | | | | | | | | | | | | | | | | | | This adds low-level builtins to allow access to all of the z13 vector instructions. Note that instructions whose semantics can be described by standard C (including clang extensions) do not get any builtins. For each instructions whose semantics *cannot* (fully) be described, we define a builtin named __builtin_s390_<insn> that directly maps to this instruction. These are intended to be compatible with GCC. For instructions that also set the condition code, the builtin will take an extra argument of type "int *" at the end. The integer pointed to by this argument will be set to the post-instruction CC value. For many instructions, the low-level builtin is mapped to the corresponding LLVM IR intrinsic. However, a number of instructions can be represented in standard LLVM IR without requiring use of a target intrinsic. Some instructions require immediate integer operands within a certain range. Those are verified at the Sema level. Based on a patch by Richard Sandiford. llvm-svn: 236532
* Extend format specifier checking to include field function pointers in ↵Aaron Ballman2015-04-231-3/+6
| | | | | | addition to variable function pointers. Addresses PR21082. llvm-svn: 235606
* Add Clang support for remaining integer divide and permute instructions from ↵Nemanja Ivanovic2015-04-091-0/+22
| | | | | | | | | | | ISA 2.06 This patch corresponds to review: http://reviews.llvm.org/D8398 It adds some builtin functions to access the extended divide and bit permute instructions. llvm-svn: 234547
OpenPOWER on IntegriCloud