aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-01-04[LoongArch] Add intrinsics for MOVFCSR2GR and MOVGR2FCSR instructionsXiaodong Liu1-0/+3
Instruction formats: `movgr2fcsr fcsr, rj` `movfcsr2gr rd, fcsr` MOVGR2FCSR modifies the value of the software writable field corresponding to the FCSR (floating-point control and status register) `fcsr` according to the value of the lower 32 bits of the GR (general purpose register) `rj`. MOVFCSR2GR sign extends the 32-bit value of the FCSR `fcsr` and writes it into the GR `rd`. Add "i32 @llvm.loongarch.movfcsr2gr(i32)" intrinsic for MOVFCSR2GR instruction. The argument is FCSR register number. The return value is the value in the FCSR. Add "void @llvm.loongarch.movgr2fcsr(i32, i32)" intrinsic for MOVGR2FCSR instruction. The first argument is the FCSR number, the second argument is the value in GR. Reviewed By: SixWeining, xen0n Differential Revision: https://reviews.llvm.org/D140685
2022-12-27[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-3/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This a recommit of e953ae5bbc313fd0cc980ce021d487e5b5199ea4 and the subsequent fixes caa713559bd38f337d7d35de35686775e8fb5175 and 06b90e2e9c991e211fecc97948e533320a825470. The above patchset caused some version of GCC to take eons to compile clang/lib/Basic/Targets/AArch64.cpp, as spotted in aa171833ab0017d9732e82b8682c9848ab25ff9e. The fix is to make BuiltinInfo tables a compilation unit static variable, instead of a private static variable. Differential Revision: https://reviews.llvm.org/D139881
2022-12-25Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵Vitaly Buka1-3/+3
builtin and call information" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4 (part 2)" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4" GCC build hangs on this bot https://lab.llvm.org/buildbot/#/builders/37/builds/19104 compiling CMakeFiles/obj.clangBasic.dir/Targets/AArch64.cpp.d The bot uses GNU 11.3.0, but I can reproduce locally with gcc (Debian 12.2.0-3) 12.2.0. This reverts commit caa713559bd38f337d7d35de35686775e8fb5175. This reverts commit 06b90e2e9c991e211fecc97948e533320a825470. This reverts commit e953ae5bbc313fd0cc980ce021d487e5b5199ea4.
2022-12-24[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-3/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 that into account a GGC issue (probably https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92181) when dealing with intiailizer_list and constant expressions. Workaround this by avoiding initializer list, at the expense of a temporary plain old array. Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-3/+3
builtin and call information" There are still remaining issues with GCC 12, see for instance https://lab.llvm.org/buildbot/#/builders/93/builds/12669 This reverts commit 5ce4e92264102de21760c94db9166afe8f71fcf6.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-3/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 with a change to llvm/utils/TableGen/OptParserEmitter.cpp to cope with GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-3/+3
builtin and call information" Failing builds: https://lab.llvm.org/buildbot#builders/9/builds/19030 This is GCC specific and has been reported upstream: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 This reverts commit 719d98dfa841c522d8d452f0685e503538415a53.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-3/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139881
2022-12-22[Clang][LoongArch] Add intrinsic for asrtle, asrtgt, lddir, ldpte and cpucfggonglingqin1-0/+9
`__cpucfg` is required by Linux [1]. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/asm/loongarch.h#n59 Differential Revision: https://reviews.llvm.org/D139915
2022-12-21clang: Add __builtin_elementwise canonicalize and copysignMatt Arsenault1-1/+3
Just copy paste from the other functions. I also need fma, but the current code seems to assume 1 or 2 arguments.
2022-12-17llvm::Optional::value => operator*/operator->Fangrui Song1-2/+2
std::optional::value() has undesired exception checking semantics and is unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The call sites block std::optional migration. This makes `ninja clang` work in the absence of llvm::Optional::value.
2022-12-16[AArch64] Support SLC in ACLE prefetch intrinsicsArchibald Elliott1-3/+3
This change: - Modifies the ACLE code to allow the new SLC value (3) for the prefetch target. - Introduces a new intrinsic, @llvm.aarch64.prefetch which matches the PRFM family instructions much more closely, and can represent all values for the PRFM immediate. The target-independent @llvm.prefetch intrinsic does not have enough information for us to be able to lower to it from the ACLE intrinsics correctly. - Lowers the acle calls to the new intrinsic on aarch64 (the ARM lowering is unchanged). - Implements code generation for the new intrinsic in both SelectionDAG and GlobalISel. We specifically choose to continue to support lowering the target-independent @llvm.prefetch intrinsic so that other frontends can continue to use it. Differential Revision: https://reviews.llvm.org/D139443
2022-12-16[clang][dataflow] Remove unused argument in getNullabilityDani Ferreira Franco Moura1-8/+6
This change will allow users to call getNullability() without providing an ASTContext. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D140104
2022-12-10Don't include None.h (NFC)Kazu Hirata1-1/+0
I've converted all known uses of None to std::nullopt, so we no longer need to include None.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10[Clang][LoongArch] Add intrinsic for iocsrrd and iocsrwrgonglingqin1-0/+2
These intrinsics are required by Linux [1]. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/asm/loongarch.h#n240 Differential Revision: https://reviews.llvm.org/D139612
2022-12-08[C2x] Relaxing requirements for va_startAaron Ballman1-2/+10
This implements WG14 N2975 relaxing requirements for va_start (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf), which does two things: 1) Allows the declaration of a variadic function without any named arguments. e.g., void f(...) is now valid, as in C++. 2) Modified the signature of the va_start macro to be a variadic macro that accepts one or more arguments; the second (and later) arguments are not expanded or evaluated. I followed the GCC implementation in terms of not modifying the behavior of `__builtin_va_start` (it still requires exactly two arguments), but this approach has led to several QoI issues that I've documented with FIXME comments in the test. Specifically, the requirement that we do not evaluate *or expand* the second and later arguments means it's no longer possible to issue diagnostics for compatibility with older C versions and C++. I am reaching out to folks in WG14 to see if we can get an NB comment to address these concerns (the US comment period has already closed, so I cannot file the comment myself), so the diagnostic behavior may change in the future. I took this opportunity to add some documentation for all the related builtins in this area, since there was no documentation for them yet. Differential Revision: https://reviews.llvm.org/D139436
2022-12-08[Clang][LoongArch] Add intrinsic for csrrd, csrwr and csrxchggonglingqin1-0/+24
These intrinsics are required by Linux [1]. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/asm/loongarch.h?h=v6.0&id=4fe89d07dcc2804c8b562f6c7896a45643d34b2f#n232 Differential Revision: https://reviews.llvm.org/D139288
2022-12-07[PowerPC] Support test data class intrinsic of 128-bit floatQiu Chaofan1-2/+3
We've exploited test data class instructions introduced in ISA 3.0. This change unifies the scalar intrinsics into ppc_test_data_class and add support for 128-bit precision float values using xststdcqp. Vector versions of the intrinsic can't be unified because they return vector int instead of int. Reviewed By: shchenz Differential Revision: https://reviews.llvm.org/D138105
2022-12-03[Sema] Use std::nullopt instead of None (NFC)Kazu Hirata1-27/+27
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02Use CTAD on llvm::SaveAndRestoreJan Svoboda1-2/+2
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D139229
2022-12-01[LoongArch] Add remaining intrinsics for CRC check instructionsgonglingqin1-0/+7
After D137316 implements the intrinsics of the first crc check instruction and related diagnosis, this patch implements the intrinsics of all remaining crc check instructions. Differential Revision: https://reviews.llvm.org/D138418
2022-11-30[clang][TargetInfo] Use LangAS for getPointer{Width,Align}()Alex Richardson1-3/+2
Mixing LLVM and Clang address spaces can result in subtle bugs, and there is no need for this hook to use the LLVM IR level address spaces. Most of this change is just replacing zero with LangAS::Default, but it also allows us to remove a few calls to getTargetAddressSpace(). This also removes a stale comment+workaround in CGDebugInfo::CreatePointerLikeType(): ASTContext::getTypeSize() does return the expected size for ReferenceType (and handles address spaces). Differential Revision: https://reviews.llvm.org/D138295
2022-11-23[Sema] check InitListExpr format strings like {"foo"}Yingchi Long1-0/+9
Adds InitListExpr case in format string checks. e.g. int sprintf(char *__restrict, const char * __restrict, ...); int foo() { char data[100]; constexpr const char* fmt2{"%d"}; // no-warning sprintf(data, fmt2, 123); } Fixes: https://github.com/llvm/llvm-project/issues/58900 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D137839
2022-11-21[LoongArch] Add intrinsics for ibar, break and syscallgonglingqin1-0/+3
Diagnostics for intrinsic input parameters have also been added. Differential Revision: https://reviews.llvm.org/D138094
2022-11-18[Hexagon] Add checks for immediate arguments for remaining builtinsKrzysztof Parzyszek1-0/+25
Checks for builtins for the following instructions were aded: V6_v6mpyhubs10 V6_v6mpyhubs10_vxx V6_v6mpyvubs10 V6_v6mpyvubs10_vxx V6_vlutvvbi V6_vlutvvb_oracci V6_vlutvwhi V6_vlutvwh_oracci
2022-11-16[LoongArch] Add immediate operand validity check for __builtin_loongarch_dbargonglingqin1-0/+3
Differential Revision: https://reviews.llvm.org/D137809
2022-11-15[Clang] Extend the number of case Sema::CheckForIntOverflow coversShafik Yaghmour1-0/+11
Currently Sema::CheckForIntOverflow misses several case that other compilers diagnose for overflow in integral constant expressions. This includes the arguments of a CXXConstructExpr as well as the expressions used in an ArraySubscriptExpr, CXXNewExpr and CompoundLiteralExpr. This fixes https://github.com/llvm/llvm-project/issues/58944 Differential Revision: https://reviews.llvm.org/D137897
2022-11-10Add builtin_elementwise_sin and builtin_elementwise_cosJoshua Batista1-0/+2
Add codegen for llvm cos and sin elementwise builtins The sin and cos elementwise builtins are necessary for HLSL codegen. Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types. The new builtins are restricted to floating point types only. Reviewed By: craig.topper, fhahn Differential Revision: https://reviews.llvm.org/D135011
2022-11-11[Clang][LoongArch] Implement __builtin_loongarch_crc_w_d_w builtin and add ↵gonglingqin1-0/+20
diagnostics This patch adds support to prevent __builtin_loongarch_crc_w_d_w from compiling on loongarch32 in the front end and adds diagnostics accordingly. Reference: https://github.com/gcc-mirror/gcc/blob/master/gcc/config/loongarch/larchintrin.h#L175-L184 Depends on D136906 Differential Revision: https://reviews.llvm.org/D137316
2022-11-08Fix duplicate word typos; NFCRageking81-2/+2
This revision fixes typos where there are 2 consecutive words which are duplicated. There should be no code changes in this revision (only changes to comments and docs). Do let me know if there are any undesirable changes in this revision. Thanks.
2022-10-25[X86] Add CMPCCXADD instructions.Freddy Ye1-0/+4
For more details about these instructions, please refer to the latest ISE document: https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html Reviewed By: pengfei, skan Differential Revision: https://reviews.llvm.org/D135933
2022-10-24Fix caret position to be on the non null parameterArthur Grillo1-1/+1
When checking for non null arguments the wrong SourceLocation was given, this fix to pass the proper argument's location. Fixes #58273 Differential Revision: https://reviews.llvm.org/D136355
2022-10-22[X86] Add AMX-FP16 instructions.Xiang1 Zhang1-0/+1
Differential Revision: https://reviews.llvm.org/D135941
2022-10-20[HLSL] Disable integer promotion to avoid int16_t being promoted to int for ↵Xiang Li1-2/+2
HLSL. short will be promoted to int in UsualUnaryConversions. Disable it for HLSL to keep int16_t as 16bit. Reviewed By: aaron.ballman, rjmccall Differential Revision: https://reviews.llvm.org/D133668
2022-10-20[clang][Sema] Use correct array size for diagnosticBill Wendling1-5/+6
The diagnostic was confusing and reporting that an array contains far more elements than it is defined to have, due to casting. For example, this code: double foo[4096]; ((char*)foo)[sizeof(foo)]; warns that the "index 32768 is past the end of the array (which contains 32768 elements)." Reviewed By: serge-sans-paille, aaron.ballman Differential Revision: https://reviews.llvm.org/D135920
2022-10-18[Clang] Fix crash when checking misaligned member with dependent typeJun Zhang1-3/+3
If the type is dependent, we should just discard it and not checking its alignment as it doesn't exisit yet. Fixes https://github.com/llvm/llvm-project/issues/58370 Differential Revision: https://reviews.llvm.org/D136018
2022-10-14[clang][Sema] Use size of char in bits for void typesBill Wendling1-5/+11
The extension that allows for pointer arithmetic on 'void' types treats the 'void' as a 'char'. We should use the 'char' size in bits instead of 1 (the number of bytes) to allow warning when pointer arithmetic would go out of bounds. Differential Revision: https://reviews.llvm.org/D135989
2022-10-06[clang][NFC] Use enum for -fstrict-flex-arraysBill Wendling1-1/+2
Use enums for the strict flex arrays flag so that it's more readable. Differential Revision: https://reviews.llvm.org/D135107
2022-10-04[clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExprserge-sans-paille1-92/+19
Turn it into a single Expr::isFlexibleArrayMemberLike method, as discussed in https://discourse.llvm.org/t/rfc-harmonize-flexible-array-members-handling Keep different behavior with respect to macro / template substitution, and harmonize sharp edges: ObjC interface now behave as C struct wrt. FAM and -fstrict-flex-arrays. This does not impact __builtin_object_size interactions with FAM. Differential Revision: https://reviews.llvm.org/D134791
2022-09-29[Clang] P1169R4: static operator()Roy Jacobson1-4/+4
Implements 'P1169R4: static operator()' from C++2b. Reviewed By: #clang-language-wg, aaron.ballman Differential Revision: https://reviews.llvm.org/D133659
2022-09-22[clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExprserge-sans-paille1-26/+25
This fixes a bunch of FIXME within IsTailPaddedMemberArray related code. As a side effect, this now also triggers a warning when trying to access a "struct hack" member with an index above address space index range. Differential Revision: https://reviews.llvm.org/D133108
2022-09-20Fix __builtin_assume_aligned incorrect type descriptor and C++ object ↵yronglin1-4/+11
polymorphic address Fix __builtin_assume_aligned incorrect type descriptor example from @rsmith struct A { int n; }; struct B { int n; }; struct C : A, B {}; void *f(C *c) { // Incorrectly returns `c` rather than the address of the B base class. return __builtin_assume_aligned((B*)c, 8); } Differential Revision: https://reviews.llvm.org/D133583
2022-09-15[clang][RecoveryExpr] Don't perform alignment check if parameter type is ↵Aleksandr Platonov1-3/+3
dependent This patch fixes a crash which appears because of getTypeAlignInChars() call with depentent type. Reviewed By: hokein Differential Revision: https://reviews.llvm.org/D133886
2022-09-14[RISCV] Update error message to not call 'RV32' and 'RV64' an extension.Craig Topper1-2/+10
I used RV32 so I didn't have to write RV32I and RV32E. Ideally these builtins will be wrapped in a header someday so long term I don't expect users to see these errors. Reviewed By: asb Differential Revision: https://reviews.llvm.org/D133444
2022-09-07Avoid __builtin_assume_aligned crash when the 1st arg is array typeyronglin1-14/+48
Avoid __builtin_assume_aligned crash when the 1st arg is array type (or string literal). Fixes Issue #57169 Differential Revision: https://reviews.llvm.org/D133202
2022-09-06[RISCV] Use llvm::none_of to replace a loop. NFCCraig Topper1-8/+2
2022-09-06[RISCV] Add '32bit' feature to rv32 only builtins.Craig Topper1-27/+2
The backend now has a 32bit feature as part of the recent mtune patch. We can now use that make our rv32-only builtin error checking work the same way as rv64-only errors. Reviewed By: kito-cheng Differential Revision: https://reviews.llvm.org/D132192
2022-09-05[clang] Fix crash when parsing scanf format string with missing argumentsserge-sans-paille1-0/+3
When parsing a format string with less argument than specified, one should check argument access because there may be no such argument. This fixes #57517 Differential Revision: https://reviews.llvm.org/D133197
2022-09-03Revert "[Clang][CodeGen] Avoid __builtin_assume_aligned crash when the 1st ↵Vitaly Buka1-57/+14
arg is array type" Breakes windows bot. This reverts commit 3ad2fe913ae08ca062105731ad2da2eae825c731.
2022-09-03[Clang][CodeGen] Avoid __builtin_assume_aligned crash when the 1st arg is ↵yronglin1-14/+57
array type Avoid __builtin_assume_aligned crash when the 1st arg is array type(or string literal). Open issue: https://github.com/llvm/llvm-project/issues/57169 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D133202