summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Change Builtins name to be stored as StringRef instead of raw ↵Mehdi Amini2016-10-111-3/+3
| | | | | | | | | | | | | | pointers (NFC)" This reverts commit r283802. It introduces temporarily static initializers, because StringRef ctor isn't (yet) constexpr for string literals. I plan to get there this week, but apparently GCC is so terrible with these static initializer right now (10 min+ extra codegen time was reported) that I'll hold on to this patch till the constexpr one is ready, and land these at the same time. llvm-svn: 283920
* Change Builtins name to be stored as StringRef instead of raw pointers (NFC)Mehdi Amini2016-10-101-3/+3
| | | | llvm-svn: 283802
* [Sema] Packed member warning: Use the typedef name for anonymous structuresAlex Lorenz2016-10-051-1/+6
| | | | | | | | | | | This commit improves the packed member warning by showing the name of the anonymous structure/union when it was defined within a typedef declaration. rdar://28498901 Differential Revision: https://reviews.llvm.org/D25106 llvm-svn: 283304
* [AVX-512] Check rounding mode for builtins that take one. Rounding mode ↵Craig Topper2016-10-011-0/+93
| | | | | | should be either _MM_FROUND_CUR_DIRECTION or a 2-bit rounding mode ORed with _MM_FROUND_NO_EXC. llvm-svn: 283054
* Move UTF functions into namespace llvm.Justin Lebar2016-09-301-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This lets people link against LLVM and their own version of the UTF library. I determined this only affects llvm, clang, lld, and lldb by running $ git grep -wl 'UTF[0-9]\+\|\bConvertUTF\bisLegalUTF\|getNumBytesFor' | cut -f 1 -d '/' | sort | uniq clang lld lldb llvm Tested with ninja lldb ninja check-clang check-llvm check-lld (ninja check-lldb doesn't complete for me with or without this patch.) Reviewers: rnk Subscribers: klimek, beanz, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D24996 llvm-svn: 282822
* [AVX-512] Add initial support for checking rounding mode arguments of builtins.Craig Topper2016-09-231-0/+100
| | | | | | | | The backend can't encode all possible values of the argument and will fail isel. Checking in the frontend presents a friendlier experience to the user. I started with builtins that can only take _MM_CUR_DIRECTION or _MM_NO_EXC. More builtins coming in the future. llvm-svn: 282228
* [X86] Split up the single switch statement in ↵Craig Topper2016-09-231-15/+27
| | | | | | | | Sema::CheckX86BuiltinFunctionCall into different switches or ifs for each type of check. This in preparation for a new check that will check some of the builtins that already had the immediate range check. llvm-svn: 282227
* Fix Wbitfield-constant-conversion false positivesDaniel Marjamaki2016-09-221-4/+3
| | | | | | | | | Summary: The diagnostic did not handle ~ well. An expression such as ~0 is often used when 'all ones' is needed. Differential Revision: https://reviews.llvm.org/D24232 llvm-svn: 282156
* [Sema] Fix PR30481: crash on checking printf args.George Burgess IV2016-09-221-2/+2
| | | | | | | We were falling through from one case to another in a switch statement. Oops. llvm-svn: 282124
* Fix unused result from sign extending an Offset.Stephen Hines2016-09-161-1/+1
| | | | | | | | | | | | | | Summary: Offset was doubled in size, but the assignment was missing. We just need to reassign to the original variable in this case to fix it. Reviewers: cfe-commits, echristo Subscribers: meikeb Differential Revision: https://reviews.llvm.org/D24648 llvm-svn: 281706
* Do not warn about format strings that are indexed string literals.Stephen Hines2016-09-161-18/+166
| | | | | | | | | | | | | | | | | | | | | Summary: The warning for a format string not being a string literal and therefore being potentially insecure is overly strict for indices into string literals. This fix checks if the index into the string literal is precomputable. If that's the case it will check if the suffix of that string literal is a valid format string string literal. It will still issue the aforementioned warning for out of range indices into the string literal. Patch by Meike Baumgärtner (meikeb) Reviewers: rsmith Subscribers: srhines, cfe-commits Differential Revision: https://reviews.llvm.org/D24584 llvm-svn: 281686
* Reapply: Silence false positive diagnostics regarding passing an object of ↵Aaron Ballman2016-09-151-2/+11
| | | | | | | | | | enumeration type to va_start(). The underlying type for an enumeration in C is either char, signed int, or unsigned int. In the case the underlying type is chosen to be char (such as when passing -fshort-enums or using __attribute__((packed)) on the enum declaration), the enumeration can result in undefined behavior. However, when the underlying type is signed int or unsigned int (or long long as an extension), there is no undefined behavior because the types are compatible. This patch silences diagnostics for the latter while retaining the diagnostics for the former. This patch addresses PR29140. llvm-svn: 281632
* Reverting r281609; it caused some build bots to break.Aaron Ballman2016-09-151-11/+2
| | | | | | http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/20061/steps/test/logs/stdio llvm-svn: 281612
* Silence false positive diagnostics regarding passing an object of ↵Aaron Ballman2016-09-151-2/+11
| | | | | | | | enumeration type to va_start(). The underlying type for an enumeration in C is either char, signed int, or unsigned int. In the case the underlying type is chosen to be char (such as when passing -fshort-enums or using __attribute__((packed)) on the enum declaration), the enumeration can result in undefined behavior. However, when the underlying type is signed int or unsigned int (or long long as an extension), there is no undefined behavior because the types are compatible. This patch silences diagnostics for the latter while retaining the diagnostics for the former. This patch addresses PR29140. llvm-svn: 281609
* Revert "Do not warn about format strings that are indexed string literals."Stephen Hines2016-09-141-166/+18
| | | | | | | | | | | | Summary: This reverts r281527 because I messed up the attribution. Reviewers: srhines Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24579 llvm-svn: 281530
* Do not warn about format strings that are indexed string literals.Stephen Hines2016-09-141-18/+166
| | | | | | | | | | | | | | | | | | | Summary: The warning for a format string not being a sting literal and therefore being potentially insecure is overly strict for indecies into sting literals. This fix checks if the index into the string literal is precomputable. If thats the case it will check if the suffix of that sting literal is a valid format string string literal. It will still issue the aforementioned warning for out of range indecies into the string literal. Reviewers: rsmith Subscribers: srhines, cfe-commits Differential Revision: https://reviews.llvm.org/D23820 llvm-svn: 281527
* [OpenCL] Fix pipe built-in functions return type.Alexey Bader2016-09-071-0/+2
| | | | | | | | | | | | | | | By default return type of call expressions calling built-in functions is set to bool. Fixes https://llvm.org/bugs/show_bug.cgi?id=30219. Reviewers: Anastasia Subscribers: dmitry, cfe-commits, yaxunl Differential Revision: https://reviews.llvm.org/D24136 llvm-svn: 280800
* This patch implements PR#22821.Roger Ferrer Ibanez2016-08-121-0/+67
| | | | | | | | | | | | | | | | | | Taking the address of a packed member is dangerous since the reduced alignment of the pointee is lost. This can lead to memory alignment faults in some architectures if the pointer value is dereferenced. This change adds a new warning to clang emitted when taking the address of a packed member. A packed member is either a field/data member declared as attribute((packed)) or belonging to a struct/class declared as such. The associated flag is -Waddress-of-packed-member. Conversions (either implicit or via a valid casting) to pointer types with lower or equal alignment requirements (e.g. void* or char*) will silence the warning. Differential Revision: https://reviews.llvm.org/D20561 llvm-svn: 278483
* [Sema] Add more strict check for sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-111-0/+7
| | | | | | | | | | Follow-up from r278264 after Joerg's feedback. Since bzero is not standard, be more strict: also check if the first argument is a pointer, which harden the check for when it does not come originally from a builtin. llvm-svn: 278379
* Reapply [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-101-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | Reapply r277787. For memset (and others) we can get diagnostics like: struct stat { int x; }; void foo(struct stat *stamps) { bzero(stamps, sizeof(stamps)); memset(stamps, 0, sizeof(stamps)); } t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess] memset(stamps, 0, sizeof(stamps)); ~~~~~~ ^~~~~~ t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(stamps, 0, sizeof(stamps)); ^~~~~~ This patch implements the same class of warnings for bzero. Differential Revision: https://reviews.llvm.org/D22525 rdar://problem/18963514 llvm-svn: 278264
* Fix two false positives in -Wreturn-stack-addressRichard Trieu2016-08-051-0/+13
| | | | | | | | | | | If the return type is a pointer and the function returns the reference to a pointer, don't warn since only the value is returned, not the reference. If a reference function parameter appears in the reference chain, don't warn since binding happens at the caller scope, so addresses returned are not to local stack. This includes default arguments as well. llvm-svn: 277889
* Fix false positive in -Wunsequenced and templates.Richard Trieu2016-08-051-1/+2
| | | | | | | | | | | | | | For builtin logical operators, there is a well-defined ordering of argument evaluation. For overloaded operator of the same type, there is no argument evaluation order, similar to other function calls. When both are present, uninstantiated templates with an operator&& is treated as an unresolved function call. Unresolved function calls are treated as normal function calls, and may result in false positives when the builtin logical operator is used. Have the unsequenced checker ignore dependent expressions to avoid this false positive. The check also happens in template instantiations to catch when the overloaded operator is used. llvm-svn: 277866
* Revert "[Sema] Add sizeof diagnostics for bzero"Bruno Cardoso Lopes2016-08-051-5/+3
| | | | | | This reverts commit r277787, which caused PR28870. llvm-svn: 277830
* Allow -1 to assign max value to unsigned bitfields.Richard Trieu2016-08-051-0/+6
| | | | | | | | Silence the -Wbitfield-constant-conversion warning for when -1 or other negative values are assigned to unsigned bitfields, provided that the bitfield is wider than the minimum number of bits needed to encode the negative value. llvm-svn: 277796
* [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-041-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | For memset (and others) we can get diagnostics like: struct stat { int x; }; void foo(struct stat *stamps) { bzero(stamps, sizeof(stamps)); memset(stamps, 0, sizeof(stamps)); } t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess] memset(stamps, 0, sizeof(stamps)); ~~~~~~ ^~~~~~ t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(stamps, 0, sizeof(stamps)); ^~~~~~ This patch implements the same class of warnings for bzero. Differential Revision: https://reviews.llvm.org/D22525 rdar://problem/18963514 llvm-svn: 277787
* [X86] Block pbroadcastq instructions on 32-bit targets instead of pbroadcastb.Craig Topper2016-07-241-3/+3
| | | | | | Thanks to Simon Pilgrim for catching the mistake. llvm-svn: 276564
* [Sema,X86] Add explicit check to ensure that builtins that require x86-64 ↵Craig Topper2016-07-211-0/+50
| | | | | | | | | | target throw an error if used on 32-bit target. If these builtins are allowed to go through on a 32-bit target they will fire assertions in the backend. Fixes PR28635. llvm-svn: 276250
* [Sema] Fix PR28623.George Burgess IV2016-07-211-1/+5
| | | | | | | | | | | | | | | In atomic builtins, we assumed that the LValue conversion on the first argument would succeed. So, we would crash given code like: ``` void ovl(char); void ovl(int); __atomic_store_n(ovl, 0, 0); ``` This patch makes us not assume that said conversion is successful. :) llvm-svn: 276232
* [NFC] Header cleanupMehdi Amini2016-07-181-3/+2
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
* Reverting 275417Roger Ferrer Ibanez2016-07-141-67/+0
| | | | | | This change has triggered unexpected failures. llvm-svn: 275462
* Diagnose taking address and reference binding of packed membersRoger Ferrer Ibanez2016-07-141-0/+67
| | | | | | | | | | | | | | | | | | | | | | | This patch implements PR#22821. Taking the address of a packed member is dangerous since the reduced alignment of the pointee is lost. This can lead to memory alignment faults in some architectures if the pointer value is dereferenced. This change adds a new warning to clang emitted when taking the address of a packed member. A packed member is either a field/data member declared as attribute((packed)) or belonging to a struct/class declared as such. The associated flag is -Waddress-of-packed-member. Conversions (either implicit or via a valid casting) to pointer types with lower or equal alignment requirements (e.g. void* or char*) silence the warning. This change also adds a new error diagnostic when the user attempts to bind a reference to a packed member, regardless of the alignment. Differential Revision: https://reviews.llvm.org/D20561 llvm-svn: 275417
* [AVX512] Remove masked shufps/shudpd builtins. These are all handled with ↵Craig Topper2016-07-101-6/+0
| | | | | | __builtin_shufflevector. llvm-svn: 275018
* [X86] Remove dead builtins that don't exist in the backend intrinsic file ↵Craig Topper2016-07-081-1/+0
| | | | | | and don't have custom handling in CGBuiltins.cpp either. llvm-svn: 274825
* Ensuring the bit-fields have the same type; MSVC will place the fields in ↵Aaron Ballman2016-07-061-1/+1
| | | | | | different allocation units otherwise. llvm-svn: 274654
* [OpenCL] An implementation of device side enqueue (DSE) from OpenCL v2.0 ↵Anastasia Stulova2016-07-051-11/+253
| | | | | | | | | | | | | | | | | s6.13.17. - Added new Builtins: enqueue_kernel, get_kernel_work_group_size and get_kernel_preferred_work_group_size_multiple. These Builtins use custom check to diagnose parameters of the passed Blocks i. e. variable number of 'local void*' type params, and check different overloads specified in Table 6.31 of OpenCL v2.0. - IR is generated as an internal library call for each OpenCL Builtin, reusing ObjC Block implementation. Review: http://reviews.llvm.org/D20249 llvm-svn: 274540
* [AVX512] Remove VPERMD/VPERMQ/VPERMILPS/VPERMILPD builtins. These were made ↵Craig Topper2016-07-041-6/+0
| | | | | | unused in r274492 and r274502. llvm-svn: 274516
* [OpenCL] Make OpenCL Builtins added according to the right version.Anastasia Stulova2016-07-041-8/+2
| | | | | | | | | | Currently we only have OpenCL 2.0 Builtins i.e. pipes or address space conversions. They have to be added only in the version 2.0 compilation mode to make the identifiers available for use in the other versions. Review: http://reviews.llvm.org/D20249 llvm-svn: 274509
* [X86] Replace 128-bit and 256 masked vpermilps/vpermilpd builtins with ↵Craig Topper2016-07-021-4/+0
| | | | | | native IR. llvm-svn: 274425
* [AVX512][BUILTIN][vpermilps][intrinsics] Fixing two incorrect IMM check.Michael Zuckerman2016-06-301-3/+3
| | | | | | Differential Revision: http://reviews.llvm.org/D21836 llvm-svn: 274224
* Use even more ArrayRefsDavid Majnemer2016-06-241-4/+4
| | | | | | No functional change is intended, just a small refactoring. llvm-svn: 273650
* Use more ArrayRefsDavid Majnemer2016-06-241-5/+2
| | | | | | No functional change is intended, just a small refactoring. llvm-svn: 273647
* Use ranges to concisely express iterationDavid Majnemer2016-06-231-5/+4
| | | | | | | No functional change is intended, this should just clean things up a little. llvm-svn: 273522
* Apply some suggestions from clang-tidy's performance-unnecessary-value-param.Benjamin Kramer2016-06-151-19/+14
| | | | | | No functionality change intended. llvm-svn: 272789
* Add a "declared 'nonnull' here" note to warnings where an expression is ↵Nick Lewycky2016-06-151-7/+9
| | | | | | checked against null. llvm-svn: 272755
* [AVX512] Implement masked and 512-bit pshufd intrinsics directly with ↵Craig Topper2016-06-111-3/+0
| | | | | | __builtin_shufflevector and __builtin_ia32_select. llvm-svn: 272467
* [AVX512] Implement 512-bit and masked shufflelo and shufflehi intrinsics ↵Craig Topper2016-06-111-6/+0
| | | | | | directly with __builtin_shufflevector and __builtin_ia32_select. Also improve the formatting of the AVX2 version. llvm-svn: 272452
* [OpenCL] Add to_{global|local|private} builtin functions.Yaxun Liu2016-05-201-0/+52
| | | | | | | | | | | | | | | | | | OpenCL builtin functions to_{global|local|private} accepts argument of pointer type to arbitrary pointee type, and return a pointer to the same pointee type in different addr space, i.e. global gentype *to_global(gentype *p); It is not desirable to declare it as global void *to_global(void *); in opencl header file since it misses diagnostics. This patch implements these builtin functions as Clang builtin functions. In the builtin def file they are defined to have signature void*(void*). When handling call expressions, their declarations are re-written to have correct parameter type and return type corresponding to the call argument. In codegen call to addr void *to_addr(void*) is generated with addrcasts or bitcasts to facilitate implementation in builtin library. Differential Revision: http://reviews.llvm.org/D19932 llvm-svn: 270261
* [Sema,CodeGen] Remove comment from SemaChecking about a ↵Craig Topper2016-05-181-2/+1
| | | | | | | | builtin_shufflevector form that it doesn't support. Remove CodeGen support for the same form since it could never have been used due to the missing support in Sema. I couldn't find any documentation that this form existed either. Nor is there documentation for one of the remaining two forms, but there is a testcase that uses it. llvm-svn: 269879
* [X86] Add immediate range checks for many of the builtins.Craig Topper2016-05-181-33/+241
| | | | | | This time allow -128 to 255 for builtins that use a char type immediate." llvm-svn: 269878
* Revert "[X86] Add immediate range checks for many of the builtins."Filipe Cabecinhas2016-05-171-234/+32
| | | | | | This reverts commit r269619. llvm-svn: 269765
OpenPOWER on IntegriCloud