aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-06-28[clang][patch][fpenv] Add builtin __arithmetic_fence and option fprotect-parensMelanie Blower1-0/+27
This patch adds a new clang builtin, __arithmetic_fence. The purpose of the builtin is to provide the user fine control, at the expression level, over floating point optimization when -ffast-math (-ffp-model=fast) is enabled. The builtin prevents the optimizer from rearranging floating point expression evaluation. The new option fprotect-parens has the same effect on parenthesized expressions, forcing the optimizer to respect the parentheses. Reviewed By: aaron.ballman, kpn Differential Revision: https://reviews.llvm.org/D100118
2021-06-24[RISCV] Add vget/vset intrinsics for inserting and extracting between ↵Craig Topper1-0/+126
different lmuls. These allow getting a whole register from a larger lmul. Or inserting a whole register into a larger lmul register. Fractional lmuls are not supported as they would require a vslide. Based on this update to the intrinsic doc https://github.com/riscv/rvv-intrinsic-doc/pull/99 Reviewed By: HsiangKai Differential Revision: https://reviews.llvm.org/D104822
2021-06-25[clang] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-6/+6
This is mostly a mechanical change, but a testcase that contains parts of the StringRef class (clang/test/Analysis/llvm-conventions.cpp) isn't touched.
2021-06-22[PowerPC][NFC] Clean up builtin sema checksLei Huang1-22/+32
Cleanup sema checking for 64bit builtins or builtins that require specific feature support. Reviewed By: NeHuang Differential Revision: https://reviews.llvm.org/D104664
2021-06-17[Sema] Fix for PR50741eahcmrh1-3/+8
Fixed crash when doing pointer math on a void pointer. Also, reworked test to use -verify rather than FileCheck. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D104424
2021-06-11[Sema] Address-space sensitive check for unbounded arrays (v2)eahcmrh1-13/+76
Check applied to unbounded (incomplete) arrays and pointers to spot cases where the computed address is beyond the largest possible addressable extent of the array, based on the address space in which the array is delcared, or which the pointer refers to. Check helps to avoid cases of nonsense pointer math and array indexing which could lead to linker failures or runtime exceptions. Of particular interest when building for embedded systems with small address spaces. This is version 2 of this patch -- version 1 had some testing issues due to a sign error in existing code. That error is corrected and lit test for this chagne is extended to verify the fix. Originally reviewed/accepted by: aaron.ballman Original revision: https://reviews.llvm.org/D86796 Reviewed By: aaron.ballman, ebevhan Differential Revision: https://reviews.llvm.org/D88174
2021-06-11Revert "[Sema] Address-space sensitive check for unbounded arrays (v2)"eahcmrh1-76/+13
This reverts commit e42a347b74400b7212ceaaea6d39562a0435df42.
2021-06-11[Sema] Address-space sensitive check for unbounded arrays (v2)eahcmrh1-13/+76
Check applied to unbounded (incomplete) arrays and pointers to spot cases where the computed address is beyond the largest possible addressable extent of the array, based on the address space in which the array is delcared, or which the pointer refers to. Check helps to avoid cases of nonsense pointer math and array indexing which could lead to linker failures or runtime exceptions. Of particular interest when building for embedded systems with small address spaces. This is version 2 of this patch -- version 1 had some testing issues due to a sign error in existing code. That error is corrected and lit test for this chagne is extended to verify the fix. Originally reviewed/accepted by: aaron.ballman Original revision: https://reviews.llvm.org/D86796 Reviewed By: aaron.ballman, ebevhan Differential Revision: https://reviews.llvm.org/D88174
2021-06-11[ADT] Remove APInt/APSInt toString() std::string variantsSimon Pilgrim1-16/+17
<string> is currently the highest impact header in a clang+llvm build: https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html One of the most common places this is being included is the APInt.h header, which needs it for an old toString() implementation that returns std::string - an inefficient method compared to the SmallString versions that it actually wraps. This patch replaces these APInt/APSInt methods with a pair of llvm::toString() helpers inside StringExtras.h, adjusts users accordingly and removes the <string> from APInt.h - I was hoping that more of these users could be converted to use the SmallString methods, but it appears that most end up creating a std::string anyhow. I avoided trying to use the raw_ostream << operators as well as I didn't want to lose having the integer radix explicit in the code. Differential Revision: https://reviews.llvm.org/D103888
2021-06-10[clang] Do not crash when ArgTy is null in CheckArgAlignmentAdam Czachorowski1-2/+6
This can happen around RecoveryExpr. Differential Revision: https://reviews.llvm.org/D103825
2021-06-09[clang] NFC: Rename rvalue to prvalueMatheus Izvekov1-1/+1
This renames the expression value categories from rvalue to prvalue, keeping nomenclature consistent with C++11 onwards. C++ has the most complicated taxonomy here, and every other language only uses a subset of it, so it's less confusing to use the C++ names consistently, and mentally remap to the C names when working on that context (prvalue -> rvalue, no xvalues, etc). Renames: * VK_RValue -> VK_PRValue * Expr::isRValue -> Expr::isPRValue * SK_QualificationConversionRValue -> SK_QualificationConversionPRValue * JSON AST Dumper Expression nodes value category: "rvalue" -> "prvalue" Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D103720
2021-05-19[clang] Fix a crash on CheckArgAlignment.Haojian Wu1-1/+2
We might encounter an undeduced type before calling getTypeAlignInChars. NOTE: this retrieves the fix from 8f80c66bd2982788a8eede4419684ca72f48b9a2, which was removed in Adam's followup fix fbfcfdbf6828b8d36f4ec0ff5f4eac11fb1411a5. We originally thought the crash was caused by recovery-ast, but it turns out it can occur for other cases, e.g. typo-correction. Differential Revision: https://reviews.llvm.org/D102750
2021-05-10[RISCV] Validate the SEW and LMUL operands to __builtin_rvv_vsetvli(max)Craig Topper1-1/+33
These are required to be constants, this patch makes sure they are in the accepted range of values. These are usually created by wrappers in the riscv_vector.h header which should always be correct. This patch protects against a user using the builtin directly. Reviewed By: khchen Differential Revision: https://reviews.llvm.org/D102086
2021-05-07[PowerPC] Provide MMA builtins for compatibilityAhsan Saghir1-1/+1
Vector pair intrinsics and builtins were renamed in https://reviews.llvm.org/D91974 to replace the _mma_ prefix by _vsx_. However, some projects used the _mma_ version, so this patch adds these intrinsics to provide compatibility. Fixes Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=50159 Reviewed By: nemanjai, amyk Differential Revision: https://reviews.llvm.org/D100482
2021-05-06[OpenCL] Remove subgroups pragma in enqueue kernel and pipe builtins.Anastasia Stulova1-2/+1
This patch simplifies the parser and makes the language semantics consistent. There is no extension pragma requirement in the spec for the subgroup functions in enqueue kernel or pipes and all other builtin functions are available without the pragama. Differential Revision: https://reviews.llvm.org/D100984
2021-04-30[clang] Fix assert() crash when checking undeduced arg alignmentAdam Czachorowski1-2/+1
There already was a check for undeduced and incomplete types, but it failed to trigger when outer type (SubstTemplateTypeParm in test) looked fine, but inner type was not. Differential Revision: https://reviews.llvm.org/D100667
2021-04-14[Sema] Move 'char-expression-as-unsigned < 0' into a separate diagnosticAnton Bikineev1-5/+8
This change splits '-Wtautological-unsigned-zero-compare' by reporting char-expressions-interpreted-as-unsigned under a separate diagnostic '-Wtautological-unsigned-char-zero-compare'. This is beneficial for projects that want to enable '-Wtautological-unsigned-zero-compare' but at the same time want to keep code portable for platforms with char being signed or unsigned, such as Chromium. Differential Revision: https://reviews.llvm.org/D99808
2021-04-09[HIP] Workaround ICE compiling SemaChecking.cpp with gcc 5Yaxun (Sam) Liu1-5/+4
Change-Id: I6c6213bc6b90365bfb78636ce7fb0700a58807cf
2021-04-09[AMDGPU] Allow relaxed/consume memory order for atomic inc/decYaxun (Sam) Liu1-7/+15
Reviewed by: Jon Chesterfield Differential Revision: https://reviews.llvm.org/D100144
2021-04-08[RISCV] Prevent __builtin_riscv_orc_b_64 from being compiled RV32 target.Craig Topper1-4/+10
The backend can't handle this and will throw a fatal error from type legalization. It's easy enough to fix that for this intrinsic by just splitting the IR intrinsic since it works on individual bytes. There will be other intrinsics in the future that would be harder to support through splitting, for example grev, gorc, and shfl. Those would require a compare and a select be inserted to check the MSB of their control input. This patch adds support for preventing this in the frontend with a nice diagnostic. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D99984
2021-04-06Let clang atomic builtins fetch add/sub support floating point typesYaxun (Sam) Liu1-9/+26
Recently atomicrmw started to support fadd/fsub: https://reviews.llvm.org/D53965 However clang atomic builtins fetch add/sub still does not support emitting atomicrmw fadd/fsub. This patch adds that. Reviewed by: John McCall, Artem Belevich, Matt Arsenault, JF Bastien, James Y Knight, Louis Dionne, Olivier Giroux Differential Revision: https://reviews.llvm.org/D71726
2021-04-02Revert "[RISCV] Try using toupper instead of std::toupper to make the build ↵Craig Topper1-1/+1
bots happy." This reverts commit 5311abc7a24e4170e5e6d06f1022da87f1413dd7. jrtc27 included the proper header in 1bd4986e7cdc124fecbf4b4527039a9a845e61f5 while I was trying to figure out what llvm/clang usually used.
2021-04-02[RISCV] Try using toupper instead of std::toupper to make the build bots happy.Craig Topper1-1/+1
2021-04-02[Sema] Fix Windows build after b001d574d7d9Jessica Clarke1-0/+1
2021-04-02Recommit "[RISCV] Add IR intrinsic for Zbb extension"Levy Hsu1-1/+1
Forgot to amend the Author. Original commit message: Header files are included in a separate patch in case the name needs to be changed. RV32 / 64: orc.b Differential Revision: https://reviews.llvm.org/D99320
2021-04-02Revert "[RISCV] Add IR intrinsic for Zbb extension"Craig Topper1-1/+1
This reverts commit 1808194590dd2b308bc146406425d5d52e46b7e6. I forgot to change the author.
2021-04-02[RISCV] Add IR intrinsic for Zbb extensionCraig Topper1-1/+1
Header files are included in a separate patch in case the name needs to be changed. RV32 / 64: orc.b
2021-04-02[RISCV] Add IR intrinsic for Zbr extensionLevy Hsu1-5/+19
Implementation for RISC-V Zbr extension intrinsic. Header files are included in separate patch in case the name needs to be changed RV32 / 64: crc32b crc32h crc32w crc32cb crc32ch crc32cw RV64 Only: crc32d crc32cd Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D99009
2021-03-25[CUDA][HIP] add __builtin_get_device_side_mangled_nameYaxun (Sam) Liu1-0/+20
Add builtin function __builtin_get_device_side_mangled_name to get device side manged name for functions and global variables, which can be used to get symbol address of kernels or variables by mangled name in dynamically loaded bundled code objects at run time. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D99301
2021-03-23[clang] Fix a crash when CTAD failsKadir Cetinkaya1-1/+2
Differential Revision: https://reviews.llvm.org/D99145
2021-03-12[OpenCL] Refactor diagnostic for OpenCL extension/featureAnton Zabaznov1-1/+2
There is no need to check for enabled pragma for core or optional core features, thus this check is removed Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D97058
2021-03-09[Sema] Fix diagnostics for one-byte length modifierAnton Bikineev1-2/+5
In case a char-literal of type int (C/ObjectiveC) corresponds to a format specifier with the %hh length modifier, don't treat the literal as of type char for issuing diagnostics, as otherwise this results in: printf("%hhd", 'e'); warning: format specifies type 'char' but the argument has type 'char'. Differential revision: https://reviews.llvm.org/D97951
2021-03-09[clang][sema][NFC] Remove a superfluous semicolonTimm Bäder1-1/+1
Silences a GCC warning: clang/lib/Sema/SemaChecking.cpp:4506:2: warning: extra ‘;’ [-Wpedantic] }; ^
2021-03-09[Clang][Sema] Warn when function argument is less aligned than parameterTomas Matheson1-2/+82
See https://bugs.llvm.org/show_bug.cgi?id=42154. GCC's __attribute__((align)) can reduce the alignment of a type when applied to a typedef. However, functions which take a pointer or reference to the original type are compiled assuming the original alignment. Therefore when any such function is passed an object of the new, less-aligned type, an alignment fault can occur. In particular, this applies to the constructor, which is defined for the original type and called for the less-aligned object. This change adds a warning whenever an pointer or reference to an object is passed to a function that was defined for a more-aligned type. The calls to ASTContext::getTypeAlignInChars seem change the order in which record layouts are evaluated, which caused changes to the output of -fdump-record-layouts. As such some tests needed to be updated: * Use CHECK-LABEL rather than counting the number of "Dumping AST Record Layout" headers. * Check for end of line in labels, so that struct B1 doesn't match struct B etc. * Add --strict-whitespace, since the whitespace shows meaningful structure. * The order in which record layouts are printed has changed in some cases. * clang-format for regions changed Differential Revision: https://reviews.llvm.org/D97187
2021-03-04[clang] removes check against integral-to-pointer conversion...Christopher Di Bella1-3/+10
... unless it's a literal D94640 was a bit too aggressive in its analysis, considering integers representing valid addresses as invalid. This change rolls back some of the check, so that only the most obvious case is still flagged. Before: ```cpp free((void*)1000); // literal converted to `void*`: warning good free((void*)an_int); // `int` object converted to `void*`: warning might // be a false positive ``` After ```cpp free((void*)1000); // literal converted to `void*`: warning good free((void*)an_int); // doesn't warn ``` Differential Revision: https://reviews.llvm.org/D97512
2021-03-03[RISCV] Make use of the required features in BuiltinInfo to store that V ↵Craig Topper1-10/+7
extension builtins require 'experimental-v'. Use that to print the diagnostic in SemaChecking instead of listing all of the builtins in a switch. With the required features, IR generation will also be able to error on this. Checking this here allows us to have a RISCV focused error message. Reviewed By: HsiangKai Differential Revision: https://reviews.llvm.org/D97826
2021-03-03[RISCV] Use RISCVV_BUILTIN for vector intrinsic checking.Hsiangkai Wang1-1/+1
There may be other BUILTINs for other extensions. Use RISCVV_BUILTIN for vector builtin checking. Differential Revision: https://reviews.llvm.org/D97825
2021-03-01BPF: fix enum value 0 issue for __builtin_preserve_enum_value()Yonghong Song1-1/+4
Lorenz Bauer reported that the following code will have compilation error for bpf target: enum e { TWO }; bpf_core_enum_value_exists(enum e, TWO); The clang emitted the following error message: __builtin_preserve_enum_value argument 1 invalid In SemaChecking, an expression like "*(enum NAME)1" will have cast kind CK_IntegralToPointer, but "*(enum NAME)0" will have cast kind CK_NullToPointer. Current implementation only permits CK_IntegralToPointer, missing enum value 0 case. This patch permits CK_NullToPointer cast kind and the above test case can pass now. Differential Revision: https://reviews.llvm.org/D97659
2021-02-26[Sema] Fix MSVC "attribute is not recognized" warning (NFC)Yang Fan1-1/+1
MSVC warning: ``` \llvm-project\clang\lib\Sema\SemaChecking.cpp(10323): warning C5030: attribute 'clang::fallthrough' is not recognized ```
2021-02-25adds more checks to -Wfree-nonheap-objectChristopher Di Bella1-30/+74
This commit adds checks for the following: * labels * block expressions * random integers cast to `void*` * function pointers cast to `void*` Differential Revision: https://reviews.llvm.org/D94640
2021-02-24[RISCV] Add vadd with mask and without mask builtin.Hsiangkai Wang1-0/+20
Demonstrate how to add RISC-V V builtins and lower them to IR intrinsics for V extension. Authored-by: Roger Ferrer Ibanez <rofirrim@gmail.com> Co-Authored-by: Hsiangkai Wang <kai.wang@sifive.com> Differential Revision: https://reviews.llvm.org/D93446
2021-02-23[clang][SVE] Don't warn on vector to sizeless builtin implicit conversionJoe Ellis1-1/+10
This commit prevents warnings from -Wconversion when a clang vector type is implicitly converted to a sizeless builtin type -- for example, when implicitly converting a fixed-predicate to a scalable predicate. The code below: 1 #include <arm_sve.h> 2 3 #define N __ARM_FEATURE_SVE_BITS 4 #define FIXED_ATTR __attribute__((arm_sve_vector_bits (N))) 5 typedef svbool_t fixed_svbool_t FIXED_ATTR; 6 7 inline fixed_svbool_t foo(fixed_svbool_t p) { 8 return svnot_z(svptrue_b64(), p); 9 } would previously raise this warning: warning: implicit conversion turns vector to scalar: \ 'fixed_svbool_t' (vector of 8 'unsigned char' values) to 'svbool_t' \ (aka '__SVBool_t') [-Wconversion] Note that many cases of these implicit conversions were already permitted because many functions inside arm_sve.h are spawned via preprocessor macros, and the call to isInSystemMacro would cover us in this case. This commit fixes the remaining cases. Differential Revision: https://reviews.llvm.org/D97053
2021-02-08Revert "[Sema] Fix -Warray-bounds false negative when casting an ↵einvbri1-56/+55
out-of-bounds array item" This reverts commit e48f444751cf781c42934b242b81f549da77bad0. thakis noticed false reports, so reverting this change for now until those can be sorted out. See https://reviews.llvm.org/D71714
2021-02-03[Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array ↵Ilya Mirsky1-55/+56
item Patch by Ilya Mirsky! Fixes: http://llvm.org/PR44343 Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D71714
2021-01-12Fix for crash in __builtin_return_address in template context.Sunil Srivastava1-1/+2
The check for argument value needs to be guarded by !isValueDependent(). Differential Revision: https://reviews.llvm.org/D94438
2021-01-11[attributes] Add a facility for enforcing a Trusted Computing Base.Sean Dooher1-0/+38
Introduce a function attribute 'enforce_tcb' that prevents the function from calling other functions without the same attribute. This allows isolating code that's considered to be somehow privileged so that it could not use its privileges to exhibit arbitrary behavior. Introduce an on-by-default warning '-Wtcb-enforcement' that warns about violations of the above rule. Introduce a function attribute 'enforce_tcb_leaf' that suppresses the new warning within the function it is attached to. Such leaf functions may implement common functionality between the trusted and the untrusted code but they require extra careful audit with respect to their capabilities. Fixes after a revert in 419ef38a50293c58078f830517f5e305068dbee6: Fix a test. Add workaround for GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67274). Attribute the patch appropriately! Differential Revision: https://reviews.llvm.org/D91898
2021-01-11Revert "[attributes] Add a facility for enforcing a Trusted Computing Base."Nico Weber1-37/+0
This reverts commit c163aae45ef6b7f3bd99601195d3ce4aad5850c6. Doesn't compile on some bots (http://lab.llvm.org:8011/#/builders/98/builds/3387/steps/9/logs/stdio), breaks tests on bots where it does compile (http://45.33.8.238/linux/36843/step_7.txt).
2021-01-11[attributes] Add a facility for enforcing a Trusted Computing Base.Artem Dergachev1-0/+37
Introduce a function attribute 'enforce_tcb' that prevents the function from calling other functions without the same attribute. This allows isolating code that's considered to be somehow privileged so that it could not use its privileges to exhibit arbitrary behavior. Introduce an on-by-default warning '-Wtcb-enforcement' that warns about violations of the above rule. Introduce a function attribute 'enforce_tcb_leaf' that suppresses the new warning within the function it is attached to. Such leaf functions may implement common functionality between the trusted and the untrusted code but they require extra careful audit with respect to their capabilities. Differential Revision: https://reviews.llvm.org/D91898
2021-01-04Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped ↵Thorsten Schütt1-3/+4
enum (II)" This reverts commit efc82c4ad2bcb256a4f4c20238d08cd3afba4d2d.
2021-01-04[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)Thorsten Schütt1-4/+3
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D93765