aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2016-10-24Revert "Add support for __builtin_os_log_format[_buffer_size]"Mehdi Amini1-225/+60
This reverts commit r284990, two opencl test are broken llvm-svn: 285007
2016-10-24Add support for __builtin_os_log_format[_buffer_size]Mehdi Amini1-60/+225
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: 284990
2016-10-24[Sema] Formatting warnings should see through Objective-C message sendsAlex Lorenz1-0/+14
This commit improves the '-Wformat' warnings by ensuring that the formatting checker can see through Objective-C message sends when we are calling an Objective-C method with an appropriate format_arg attribute. rdar://23622446 Differential Revision: https://reviews.llvm.org/D25820 llvm-svn: 284961
2016-10-22[AVX-512] Remove masked 128/256-bit palignr builtins. We can just use a ↵Craig Topper1-2/+0
select in the header file with the older unmasked versions instead. llvm-svn: 284920
2016-10-19[mips][msa] Range check MSA intrinsics with immediatesSimon Dardis1-4/+194
This patch teaches clang to range check immediates for MIPS MSA instrinsics. This checking is done strictly in comparison to some existing GCC implementations. E.g. msa_andvi_b(var, 257) does not result in andvi $wX, 1. Similarily msa_ldi_b takes a range of -128 to 127. As part of this effort, correct the existing MSA test as it has both illegal types and immediates. Reviewers: vkalintiris Differential Revision: https://reviews.llvm.org/D25017 llvm-svn: 284620
2016-10-12Move x86-64 builtins from SemaChecking.cpp to BuiltinsX86_64.defAlbert Gutowski1-58/+0
Summary: Follow-up to https://reviews.llvm.org/D24598 (separating builtins for x84-64 and i386). Reviewers: hans, thakis, rnk Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25494 llvm-svn: 284026
2016-10-11Revert "Change Builtins name to be stored as StringRef instead of raw ↵Mehdi Amini1-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
2016-10-10Change Builtins name to be stored as StringRef instead of raw pointers (NFC)Mehdi Amini1-3/+3
llvm-svn: 283802
2016-10-05[Sema] Packed member warning: Use the typedef name for anonymous structuresAlex Lorenz1-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
2016-10-01[AVX-512] Check rounding mode for builtins that take one. Rounding mode ↵Craig Topper1-0/+93
should be either _MM_FROUND_CUR_DIRECTION or a 2-bit rounding mode ORed with _MM_FROUND_NO_EXC. llvm-svn: 283054
2016-09-30Move UTF functions into namespace llvm.Justin Lebar1-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
2016-09-23[AVX-512] Add initial support for checking rounding mode arguments of builtins.Craig Topper1-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
2016-09-23[X86] Split up the single switch statement in ↵Craig Topper1-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
2016-09-22Fix Wbitfield-constant-conversion false positivesDaniel Marjamaki1-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
2016-09-22[Sema] Fix PR30481: crash on checking printf args.George Burgess IV1-2/+2
We were falling through from one case to another in a switch statement. Oops. llvm-svn: 282124
2016-09-16Fix unused result from sign extending an Offset.Stephen Hines1-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
2016-09-16Do not warn about format strings that are indexed string literals.Stephen Hines1-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
2016-09-15Reapply: Silence false positive diagnostics regarding passing an object of ↵Aaron Ballman1-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
2016-09-15Reverting r281609; it caused some build bots to break.Aaron Ballman1-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
2016-09-15Silence false positive diagnostics regarding passing an object of ↵Aaron Ballman1-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
2016-09-14Revert "Do not warn about format strings that are indexed string literals."Stephen Hines1-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
2016-09-14Do not warn about format strings that are indexed string literals.Stephen Hines1-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
2016-09-07[OpenCL] Fix pipe built-in functions return type.Alexey Bader1-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
2016-08-12This patch implements PR#22821.Roger Ferrer Ibanez1-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
2016-08-11[Sema] Add more strict check for sizeof diagnostics for bzeroBruno Cardoso Lopes1-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
2016-08-10Reapply [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes1-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
2016-08-05Fix two false positives in -Wreturn-stack-addressRichard Trieu1-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
2016-08-05Fix false positive in -Wunsequenced and templates.Richard Trieu1-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
2016-08-05Revert "[Sema] Add sizeof diagnostics for bzero"Bruno Cardoso Lopes1-5/+3
This reverts commit r277787, which caused PR28870. llvm-svn: 277830
2016-08-05Allow -1 to assign max value to unsigned bitfields.Richard Trieu1-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
2016-08-04[Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes1-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