aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-04-16Revert "Treat `std::move`, `forward`, and `move_if_noexcept` as builtins."Vitaly Buka1-26/+0
Revert "Extend support for std::move etc to also cover std::as_const and" Revert "Update test to handle opaque pointers flag flip." It crashes on libcxx tests https://lab.llvm.org/buildbot/#/builders/85/builds/8174 This reverts commit fc3090109643af8d2da9822d0f99c84742b9c877. This reverts commit a571f82a50416b767fd3cce0fb5027bb5dfec58c. This reverts commit 64c045e25b8471bbb572bd29159c294a82a86a25.
2022-04-15Extend support for std::move etc to also cover std::as_const andRichard Smith1-4/+18
std::addressof, plus the libstdc++-specific std::__addressof. This brings us to parity with the corresponding GCC behavior. Remove STDBUILTIN macro that ended up not being used.
2022-04-15Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.Richard Smith1-0/+12
We still require these functions to be declared before they can be used, but don't instantiate their definitions unless their addresses are taken. Instead, code generation, constant evaluation, and static analysis are given direct knowledge of their effect. This change aims to reduce various costs associated with these functions -- per-instantiation memory costs, compile time and memory costs due to creating out-of-line copies and inlining them, code size at -O0, and so on -- so that they are not substantially more expensive than a cast. Most of these improvements are very small, but I measured a 3% decrease in -O0 object file size for a simple C++ source file using the standard library after this change. We now automatically infer the `const` and `nothrow` attributes on these now-builtin functions, in particular meaning that we get a warning for an unused call to one of these functions. In C++20 onwards, we disallow taking the addresses of these functions, per the C++20 "addressable function" rule. In earlier language modes, a compatibility warning is produced but the address can still be taken. The same infrastructure is extended to the existing MSVC builtin `__GetExceptionInfo`, which is now only recognized in namespace `std` like it always should have been. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D123345
2022-04-13[Sema] Don't check bounds for function pointerAleksandr Platonov1-0/+2
Currently, clang crashes with i386 target on the following code: ``` void f() { f + 0xdead000000000000UL; } ``` This problem is similar to the problem fixed in D104424, but that fix can't handle function pointer case, because `getTypeSizeInCharsIfKnown()` says that size is known and equal to 0 for function type. This patch prevents bounds checking for function pointer, thus fixes the crash. Fixes https://github.com/llvm/llvm-project/issues/50463 Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D122748
2022-04-05[Clang][PowerPC] Add max/min intrinsics to Clang and PPC backendTing Wang1-0/+27
Add support for builtin_[max|min] which has below prototype: A builtin_max (A1, A2, A3, ...) All arguments must have the same type; they must all be float, double, or long double. Internally use SelectCC to get the result. Reviewed By: qiucf Differential Revision: https://reviews.llvm.org/D122478
2022-03-30[RISCV] Add index check for vset/vgetwangpc1-0/+24
Index of vset/vget must be a constant integer and be located in right range. Reviewed By: kito-cheng Differential Revision: https://reviews.llvm.org/D122629
2022-03-28[attributes] Generalize attribute 'enforce_tcb' to Objective-C methods.Pierre d'Herbemont1-10/+11
Calling an ObjC method from a C function marked with the 'enforce_tcb' attribute did not produce a warning. Now it does, and on top of that Objective-C methods can participate in TCBs themselves. Differential Revision: https://reviews.llvm.org/D122343
2022-03-18Add validation for number of arguments of __builtin_memcpy_inlineRoy Jacobson1-1/+6
__builtin_memcpy_inline doesn't use the usual builtin argument validation code, so it crashed when receiving wrong number of argument. Add the missing validation check. Open issue: https://github.com/llvm/llvm-project/issues/52949 Reviewed By: gchatelet Differential Revision: https://reviews.llvm.org/D121965 Committed by gchatelet on behalf of "Roy Jacobson <roi.jacobson1@gmail.com>"
2022-03-17[Sema] add warning for tautological FP compare with literalSanjay Patel1-5/+33
If we are equality comparing an FP literal with a value cast from a type where the literal can't be represented, that's known true or false and probably a programmer error. Fixes issue #54222. https://github.com/llvm/llvm-project/issues/54222 Note - I added the optimizer change with: 9397bdc67eb2 ...and as discussed in the post-commit comments, that transform might be too dangerous without this warning in place, so it was reverted to allow this change first. Differential Revision: https://reviews.llvm.org/D121306
2022-03-14[Clang][Sema] Avoid crashing for `__builtin_memcpy_inline` with an array ↵Egor Zhdan1-0/+11
argument This change teaches the Sema logic for `__builtin_memcpy_inline` to implicitly convert arrays passed as arguments to pointers, similarly to regular `memcpy`. This code will no longer cause a compiler crash: ``` void f(char *p) { char s[1] = {0}; __builtin_memcpy_inline(p, s, 1); } ``` rdar://88147527 Differential Revision: https://reviews.llvm.org/D121475
2022-03-05[RISCV] Support k-ext clang intrinsicsShao-Ce SUN1-0/+38
Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D112774
2022-02-15[PowerPC] Fix __builtin_pdepd and __builtin_pextd to be 64-bit and P10 only.Amy Kwan1-0/+6
The `__builtin_pdepd` and `__builtin_pextd` are P10 builtins that are meant to be used under 64-bit only. For instance, when the builtins are compiled under 32-bit mode: ``` $ cat t.c unsigned long long foo(unsigned long long a, unsigned long long b) { return __builtin_pextd(a,b); } $ clang -c t.c -mcpu=pwr10 -m32 ExpandIntegerResult #0: t31: i64 = llvm.ppc.pextd TargetConstant:i32<6928>, t28, t29 fatal error: error in backend: Do not know how to expand the result of this operator! ``` This patch adds sema checking for these builtins to compile under 64-bit mode only and on P10. The builtins will emit a diagnostic when they are compiled on non-P10 compilations and on 32-bit mode. Differential Revision: https://reviews.llvm.org/D118753
2022-02-12[clang][sema] Sema::CheckFreeArguments - use cast<> instead of dyn_cast<> to ↵Simon Pilgrim1-1/+1
avoid dereference of nullptr The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-11[OpenCL] Adjust diagnostic for subgroup support.Anton Zabaznov1-2/+8
OpenCL C 3.0 __opencl_c_subgroups feature is slightly different then other equivalent features and extensions (fp64 and 3d image writes): OpenCL C 3.0 device can support the extension but not the feature. cl_khr_subgroups requires subgroup independent forward progress. This patch adjusts the check which is used when translating language builtins to check either the extension or feature is supported. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D118999
2022-02-08[Clang] Add elementwise saturated add/sub builtinsSimon Pilgrim1-0/+22
This patch implements `__builtin_elementwise_add_sat` and `__builtin_elementwise_sub_sat` builtins. These map to the add/sub saturated math intrinsics described here: https://llvm.org/docs/LangRef.html#saturation-arithmetic-intrinsics With this in place we should then be able to replace the x86 SSE adds/subs intrinsics with these generic variants - it looks like other targets should be able to use these as well (arm/aarch64/webassembly all have similar examples in cgbuiltin). Differential Revision: https://reviews.llvm.org/D117898
2022-01-30[clang] Remove redundant string initialization (NFC)Kazu Hirata1-1/+1
Identified with readability-redundant-string-init.
2022-01-24[RISCV] Decouple Zve* extensions and the V extension.jacquesguan1-16/+32
According to the spec, there are some difference between V and Zve64d. For example, the vmulh integer multiply variants that return the high word of the product (vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx) are not included for EEW=64 in Zve64*, but V extension does support these instructions. So we should decouple Zve* extensions and the V extension. Differential Revision: https://reviews.llvm.org/D117854
2022-01-21[Sema] Warn about printf %n on Android and FuchsiaAlex Brachet1-8/+16
The `printf` specifier `%n` is not supported on Android's libc and will soon be removed from Fuchsia's Reviewed By: enh Differential Revision: https://reviews.llvm.org/D117611
2022-01-17[AIX][ZOS] Handle unsupported builtin function CFStringMakeConstantStringJake Egan1-6/+28
This patch emits an error on AIX and z/OS because XCOFF and GOFF does not currently implement builtin function `CFStringMakeConstantString`. Tests that use this builtin were also disabled. Reviewed By: SeanP Differential Revision: https://reviews.llvm.org/D117315
2022-01-14[Clang] Add __builtin_reduce_or and __builtin_reduce_andJun Zhang1-2/+4
This patch implements two builtins specified in D111529. The last __builtin_reduce_add will be seperated into another one. Differential Revision: https://reviews.llvm.org/D116736
2022-01-12[clang][auto-init] Provide __builtin_alloca*_uninitialized variantsMarco Elver1-0/+2
When `-ftrivial-auto-var-init=` is enabled, allocas unconditionally receive auto-initialization since [1]. In certain cases, it turns out, this is causing problems. For example, when using alloca to add a random stack offset, as the Linux kernel does on syscall entry [2]. In this case, none of the alloca'd stack memory is ever used, and initializing it should be controllable; furthermore, it is not always possible to safely call memset (see [2]). Introduce `__builtin_alloca_uninitialized()` (and `__builtin_alloca_with_align_uninitialized`), which never performs initialization when `-ftrivial-auto-var-init=` is enabled. [1] https://reviews.llvm.org/D60548 [2] https://lkml.kernel.org/r/YbHTKUjEejZCLyhX@elver.google.com Reviewed By: glider Differential Revision: https://reviews.llvm.org/D115440
2022-01-07[Clang] Implement the rest of __builtin_elementwise_* functions.Jun Zhang1-2/+5
The patch implement the rest of __builtin_elementwise_* functions specified in D111529, including: * __builtin_elementwise_floor * __builtin_elementwise_roundeven * __builtin_elementwise_trunc Signed-off-by: Jun <jun@junz.org> Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D115429
2022-01-02[clang] Remove redundant member initialization (NFC)Kazu Hirata1-2/+2
Identified with readability-redundant-member-init.
2021-12-22[Clang] Add __builtin_reduce_xorJun Zhan1-11/+31
This patch implements __builtin_reduce_xor as specified in D111529. Reviewed By: fhahn, aaron.ballman Differential Revision: https://reviews.llvm.org/D115231
2021-12-20[Clang] Add __builtin_function_startSami Tolvanen1-0/+27
Control-Flow Integrity (CFI) replaces references to address-taken functions with pointers to the CFI jump table. This is a problem for low-level code, such as operating system kernels, which may need the address of an actual function body without the jump table indirection. This change adds the __builtin_function_start() builtin, which accepts an argument that can be constant-evaluated to a function, and returns the address of the function body. Link: https://github.com/ClangBuiltLinux/linux/issues/1353 Depends on D108478 Reviewed By: pcc, rjmccall Differential Revision: https://reviews.llvm.org/D108479
2021-12-14[clang] diagnose_as_builtin attribute for Fortify diagnosing like builtins.Michael Benfield1-10/+54
Differential Revision: https://reviews.llvm.org/D112024
2021-12-10[PowerPC] Require htm feature for HTM builtinsQiu Chaofan1-5/+34
Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D114569
2021-12-08Add __builtin_elementwise_ceilJun Zhang1-12/+42
This patch implements one of the missing builtin functions specified in https://reviews.llvm.org/D111529.
2021-12-06Introduce _BitInt, deprecate _ExtIntAaron Ballman1-13/+13
WG14 adopted the _ExtInt feature from Clang for C23, but renamed the type to be _BitInt. This patch does the vast majority of the work to rename _ExtInt to _BitInt, which accounts for most of its size. The new type is exposed in older C modes and all C++ modes as a conforming extension. However, there are functional changes worth calling out: * Deprecates _ExtInt with a fix-it to help users migrate to _BitInt. * Updates the mangling for the type. * Updates the documentation and adds a release note to warn users what is going on. * Adds new diagnostics for use of _BitInt to call out when it's used as a Clang extension or as a pre-C23 compatibility concern. * Adds new tests for the new diagnostic behaviors. I want to call out the ABI break specifically. We do not believe that this break will cause a significant imposition for early adopters of the feature, and so this is being done as a full break. If it turns out there are critical uses where recompilation is not an option for some reason, we can consider using ABI tags to ease the transition.
2021-12-01[NFC][Clang] Fix some comments in clangZarko Todorovski1-4/+5
Applying post commit comment suggestions from https://reviews.llvm.org/D114025
2021-11-29[HIP] Add atomic load, atomic store and atomic cmpxchng_weak builtin support ↵Anshil Gandhi1-3/+11
in HIP-clang Introduce `__hip_atomic_load`, `__hip_atomic_store` and `__hip_atomic_compare_exchange_weak` builtins in HIP. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D114553
2021-11-23[HIP] Add HIP scope atomic operationsYaxun (Sam) Liu1-3/+12
Add an AtomicScopeModel for HIP and support for OpenCL builtins that are missing in HIP. Patch by: Michael Liao Revised by: Anshil Ghandi Reviewed by: Yaxun Liu Differential Revision: https://reviews.llvm.org/D113925
2021-11-19[clang][NFC] Inclusive terms: replace some uses of sanity in clangZarko Todorovski1-3/+4
Rewording of comments to avoid using `sanity test, sanity check`. Reviewed By: aaron.ballman, Quuxplusone Differential Revision: https://reviews.llvm.org/D114025
2021-11-17[Format, Sema] Use range-based for loops with llvm::reverse (NFC)Kazu Hirata1-4/+2
2021-11-16[PowerPC] Allow MMA built-ins to accept non-void pointers and arraysAhsan Saghir1-3/+3
Calls to MMA builtins that take pointer to void do not accept other pointers/arrays whereas normal functions with the same parameter do. This patch allows MMA built-ins to accept non-void pointers and arrays. Reviewed By: nemanjai Differential Revision: https://reviews.llvm.org/D113306
2021-11-14[clang] Use isa instead of dyn_cast (NFC)Kazu Hirata1-4/+4
2021-11-08[clang] Fortify warning for scanf calls with field width too big.Michael Benfield1-12/+134
Differential Revision: https://reviews.llvm.org/D111833
2021-11-03[PowerPC] Implement longdouble pack/unpack builtinsQiu Chaofan1-0/+12
Implement two builtins to pack/unpack IBM extended long double float, according to GCC 'Basic PowerPC Builtin Functions Available ISA 2.05'. Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D112055
2021-11-02[Clang] Add min/max reduction builtins.Florian Hahn1-0/+25
This patch implements __builtin_reduce_max and __builtin_reduce_min as specified in D111529. The order of operations does not matter for min or max reductions and they can be directly lowered to the corresponding llvm.vector.reduce.{fmin,fmax,umin,umax,smin,smax} intrinsic calls. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D112001
2021-11-01Revert "[clang] Fortify warning for scanf calls with field width too big."Michael Benfield1-131/+12
This reverts commit 5a8c1736289f2b1df10df38e7a9e4d208a7586a6. The warning needs to correctly handle * specifiers (which are to be ignored).
2021-11-01[clang] Fortify warning for scanf calls with field width too big.Michael Benfield1-12/+131
Differential Revision: https://reviews.llvm.org/D111833
2021-10-29[clang] Make 'align-mismatch' warning work without an associated function ↵Alex Lorenz1-1/+1
declaration This change fixes a crash where a NULL fd was used to emit a diagnostic. Instead of crashing, just avoid printing the declaration name when there's no associated function declaration. Differential Revision: https://reviews.llvm.org/D109402
2021-10-28Revert "[clang] Fortify warning for scanf calls with field width too big."Nico Weber1-120/+12
This reverts commit 15e3d39110fa4449be4f56196af3bc81b623f3ab. See https://reviews.llvm.org/D111833#3093629
2021-10-28[clang] Fortify warning for scanf calls with field width too big.Michael Benfield1-12/+120
Differential Revision: https://reviews.llvm.org/D111833
2021-10-28[clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and ↵Kai Luo1-0/+1
support `__atomic_fetch_nand` libcall Add `__c11_atomic_fetch_nand` builtin to language extensions and support `__atomic_fetch_nand` libcall in compiler-rt. Reviewed By: theraven Differential Revision: https://reviews.llvm.org/D112400
2021-10-27[Sema] Recognize format argument indicated by format attribute inside blocksFélix Cloutier1-3/+3
- `[[format(archetype, fmt-idx, ellipsis)]]` specifies that a function accepts a format string and arguments according to `archetype`. This is how Clang type-checks `printf` arguments based on the format string. - Clang has a `-Wformat-nonliteral` warning that is triggered when a function with the `format` attribute is called with a format string that is not inspectable because it isn't constant. This warning is suppressed if the caller has the `format` attribute itself and the format argument to the callee is the caller's own format parameter. - When using the `format` attribute on a block, Clang wouldn't recognize its format parameter when calling another function with the format attribute. This would cause unsuppressed -Wformat-nonliteral warnings for no supported reason. Reviewed By: ahatanak Differential Revision: https://reviews.llvm.org/D112569 Radar-Id: rdar://84603673
2021-10-27[Clang] Add elementwise abs builtin.Florian Hahn1-0/+29
This patch implements __builtin_elementwise_abs as specified in D111529. Reviewed By: aaron.ballman, scanon Differential Revision: https://reviews.llvm.org/D111986
2021-10-26[Matrix] Replace some err kinds with err_builtin_invalid_arg_type. (NFC)Florian Hahn1-9/+12
Replace some custom matrix diagnostic kinds with the more generic err_builtin_invalid_arg_type introduced in D111985. Reviewed By: aaron.ballman, erichkeane Differential Revision: https://reviews.llvm.org/D112532
2021-10-26[Clang] Add elementwise min/max builtins.Florian Hahn1-0/+48
This patch implements __builtin_elementwise_max and __builtin_elementwise_min, as specified in D111529. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D111985
2021-10-25[RISCV] Reduce the number of RISCV vector builtins by an order of magnitude.Craig Topper1-126/+0
All but 2 of the vector builtins are only used by clang_builtin_alias. When using clang_builtin_alias, the type string of the builtin is never checked. Only the types in the function definition used for the alias are checked. This patch takes advantage of this to share a single builtin for many different types. We already used type overloads on the IR intrinsic so the codegen for the builtins that are being merge were already the same. This extends the type overloading to the builtins. I had to make a few tweaks to make this work. -Floating point vector-vector vmerge now uses the vmerge intrinsic instead of the vfmerge intrinsic. New isel patterns and tests are added to support this. -The SemaChecking for the immediate of vset_v/vget_v has been removed. Determining the valid range is harder now. I've added masking to ManualCodegen to ensure valid IR for invalid input. This reduces the number of builtins from ~25000 to ~1100. Reviewed By: HsiangKai Differential Revision: https://reviews.llvm.org/D112102