summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
AgeCommit message (Collapse)Author
2021-12-15[CodeGen] Avoid some pointer element type accessesNikita Popov
2021-12-15[CodeGen] Pass element type to EmitCheckedInBoundsGEP()Nikita Popov
Same as for other GEP creation methods.
2021-12-15[CodeGen] Avoid some deprecated Address constructorsNikita Popov
Some of these are on the critical path towards making something minimal work with opaque pointers.
2021-12-15[CodeGen] Avoid some pointer element type accessesNikita Popov
2021-12-15[CodeGen] Store ElementType in AddressNikita Popov
Explicitly track the pointer element type in Address, rather than deriving it from the pointer type, which will no longer be possible with opaque pointers. This just adds the basic facility, for now everything is still going through the deprecated constructors. I had to adjust one place in the LValue implementation to satisfy the new assertions: Global registers are represented as a MetadataAsValue, which does not have a pointer type. We should avoid using Address in this case. This implements a part of D103465. Differential Revision: https://reviews.llvm.org/D115725
2021-11-10[CFE][Codegen] Make sure to maintain the contiguity of all the static allocashsmahesha
at the start of the entry block, which in turn would aid better code transformation/optimization. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D110257
2021-11-07[clang] Use llvm::reverse. NFCI.Benjamin Kramer
2021-10-12[clang] p0388 conversion to incomplete arrayNathan Sidwell
This implements the new implicit conversion sequence to an incomplete (unbounded) array type. It is mostly Richard Smith's work, updated to trunk, testcases added and a few bugs fixed found in such testing. It is not a complete implementation of p0388. Differential Revision: https://reviews.llvm.org/D102645
2021-10-12[CFE][Codegen] Remove CodeGenFunction::InitTempAlloca()hsmahesha
Sequel patch to https://reviews.llvm.org/D111316 Finally, remove the defintion of CodeGenFunction::InitTempAlloca(). Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D111324
2021-10-04Update inline builtin handling to honor gnu inline attributeserge-sans-paille
Per the GCC info page: If the function is declared 'extern', then this definition of the function is used only for inlining. In no case is the function compiled as a standalone function, not even if you take its address explicitly. Such an address becomes an external reference, as if you had only declared the function, and had not defined it. Respect that behavior for inline builtins: keep the original definition, and generate a copy of the declaration suffixed by '.inline' that's only referenced in direct call. This fixes holes in c3717b6858d32d64514a187ede1a77be8ba4e542. Differential Revision: https://reviews.llvm.org/D111009
2021-10-03Fixed warnings in LLVM produced by -Wbitwise-instead-of-logicalDávid Bolvanský
2021-09-28DebugInfo: Use sugared function type when emitting function declarations for ↵David Blaikie
call sites Otherwise we're losing type information for these functions.
2021-09-22[Matrix] Emit assumption that matrix indices are valid.Florian Hahn
The matrix extension requires the indices for matrix subscript expression to be valid and it is UB otherwise. extract/insertelement produce poison if the index is invalid, which limits the optimizer to not be bale to scalarize load/extract pairs for example, which causes very suboptimal code to be generated when using matrix subscript expressions with variable indices for large matrixes. This patch updates IRGen to emit assumes to for index expression to convey the information that the index must be valid. This also adjusts the order in which operations are emitted slightly, so indices & assumes are added before the load of the matrix value. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D102478
2021-09-09[APInt] Normalize naming on keep constructors / predicate methods.Chris Lattner
This renames the primary methods for creating a zero value to `getZero` instead of `getNullValue` and renames predicates like `isAllOnesValue` to simply `isAllOnes`. This achieves two things: 1) This starts standardizing predicates across the LLVM codebase, following (in this case) ConstantInt. The word "Value" doesn't convey anything of merit, and is missing in some of the other things. 2) Calling an integer "null" doesn't make any sense. The original sin here is mine and I've regretted it for years. This moves us to calling it "zero" instead, which is correct! APInt is widely used and I don't think anyone is keen to take massive source breakage on anything so core, at least not all in one go. As such, this doesn't actually delete any entrypoints, it "soft deprecates" them with a comment. Included in this patch are changes to a bunch of the codebase, but there are more. We should normalize SelectionDAG and other APIs as well, which would make the API change more mechanical. Differential Revision: https://reviews.llvm.org/D109483
2021-08-23[clang][CodeGen] GetDefaultAlignTempAlloca uses preferred alignmentAndy Wingo
This function was defaulting to use the ABI alignment for the LLVM type. Here we change to use the preferred alignment. This will allow unification with GetTempAlloca, which if alignment isn't specified, uses the preferred alignment. Differential Revision: https://reviews.llvm.org/D108450
2021-08-17[NFC] More get/removeAttribute() cleanupArthur Eubanks
2021-06-09[clang] NFC: Rename rvalue to prvalueMatheus Izvekov
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-13[Clang][Codegen] Do not annotate thunk's this/return types with ↵Roman Lebedev
align/deref/nonnull attrs As it was discovered in post-commit feedback for 0aa0458f1429372038ca6a4edc7e94c96cd9a753, we handle thunks incorrectly, and end up annotating their this/return with attributes that are valid for their callees, not for thunks themselves. While it would be good to fix this properly, and keep annotating them on thunks, i've tried doing that in https://reviews.llvm.org/D100388 with little success, and the patch is stuck for a month now. So for now, as a stopgap measure, subj.
2021-05-07[SEH] Fix regression with SEH in noexpect functionsOlivier Goffart
Commit 5baea0560160a693b19022c5d0ba637b6b46b2d8 set the CurCodeDecl because it was needed to pass the assert in CodeGenFunction::EmitLValueForLambdaField, But this was not right to do as CodeGenFunction::FinishFunction passes it to EmitEndEHSpec and cause corruption of the EHStack. Revert the part of the commit that changes the CurCodeDecl, and instead adjust the assert to check for a null CurCodeDecl. Differential Revision: https://reviews.llvm.org/D102027
2021-04-26BPF: emit debuginfo for Function of DeclRefExpr if requestedYonghong Song
Commit e3d8ee35e4ad ("reland "[DebugInfo] Support to emit debugInfo for extern variables"") added support to emit debugInfo for extern variables if requested by the target. Currently, only BPF target enables this feature by default. As BPF ecosystem grows, callback function started to get support, e.g., recently bpf_for_each_map_elem() is introduced (https://lwn.net/Articles/846504/) with a callback function as an argument. In the future we may have something like below as a demonstration of use case : extern int do_work(int); long bpf_helper(void *callback_fn, void *callback_ctx, ...); long prog_main() { struct { ... } ctx = { ... }; return bpf_helper(&do_work, &ctx, ...); } Basically bpf helper may have a callback function and the callback function is defined in another file or in the kernel. In this case, we would like to know the debuginfo types for do_work(), so the verifier can proper verify the safety of bpf_helper() call. For the following example, extern int do_work(int); long bpf_helper(void *callback_fn); long prog() { return bpf_helper(&do_work); } Currently, there is no debuginfo generated for extern function do_work(). In the IR, we have, ... define dso_local i64 @prog() local_unnamed_addr #0 !dbg !7 { entry: %call = tail call i64 @bpf_helper(i8* bitcast (i32 (i32)* @do_work to i8*)) #2, !dbg !11 ret i64 %call, !dbg !12 } ... declare dso_local i32 @do_work(i32) #1 ... This patch added support for the above callback function use case, and the generated IR looks like below: ... declare !dbg !17 dso_local i32 @do_work(i32) #1 ... !17 = !DISubprogram(name: "do_work", scope: !1, file: !1, line: 1, type: !18, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) !18 = !DISubroutineType(types: !19) !19 = !{!20, !20} !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) The TargetInfo.allowDebugInfoForExternalVar is renamed to TargetInfo.allowDebugInfoForExternalRef as now it guards both extern variable and extern function debuginfo generation. Differential Revision: https://reviews.llvm.org/D100567
2021-04-26[SYCL] Implement SYCL address space attributes handlingAlexey Bader
Default address space (applies when no explicit address space was specified) maps to generic (4) address space. Added SYCL named address spaces `sycl_global`, `sycl_local` and `sycl_private` defined as sub-sets of the default address space. Static variables without address space now reside in global address space when compile for SPIR target, unless they have an explicit address space qualifier in source code. Differential Revision: https://reviews.llvm.org/D89909
2021-04-15Implemented [[clang::musttail]] attribute for guaranteed tail calls.Joshua Haberman
This is a Clang-only change and depends on the existing "musttail" support already implemented in LLVM. The [[clang::musttail]] attribute goes on a return statement, not a function definition. There are several constraints that the user must follow when using [[clang::musttail]], and these constraints are verified by Sema. Tail calls are supported on regular function calls, calls through a function pointer, member function calls, and even pointer to member. Future work would be to throw a warning if a users tries to pass a pointer or reference to a local variable through a musttail call. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D99517
2021-04-10[Matrix] Implement C-style explicit type conversions for matrix types.Saurabh Jha
This implements C-style type conversions for matrix types, as specified in clang/docs/MatrixTypes.rst. Fixes PR47141. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D99037
2021-03-12[OpaquePtrs] Remove some uses of type-less CreateGEP() (NFC)Nikita Popov
This removes some (but not all) uses of type-less CreateGEP() and CreateInBoundsGEP() APIs, which are incompatible with opaque pointers. There are a still a number of tricky uses left, as well as many more variation APIs for CreateGEP.
2021-03-11[CGBuilder] Remove type-less CreateAlignedLoad() APIs (NFC)Nikita Popov
These are incompatible with opaque pointers. This is in preparation of dropping this API on the IRBuilder side as well. Instead explicitly pass the loaded type.
2021-03-01Fix build failure due to dump()Yaxun (Sam) Liu
Change-Id: I86b534223d63bf8bb8f49af5a64b300efbeba77b
2021-03-01[HIP] Emit kernel symbolYaxun (Sam) Liu
Currently clang uses stub function to launch kernel. This is inconvenient to interop with C++ programs since the stub function has different name as kernel, which is required by ROCm debugger. This patch emits a variable symbol which has the same name as the kernel and uses it to register and launch the kernel. This allows C++ program to launch a kernel by using the original kernel name. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D86376
2021-02-22[clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to ↵Melanie Blower
NoSanitizeList.h This patch responds to a comment from @vitalybuka in D96203: suggestion to do the change incrementally, and start by modifying this file name. I modified the file name and made the other changes that follow from that rename. Reviewers: vitalybuka, echristo, MaskRay, jansvoboda11, aaron.ballman Differential Revision: https://reviews.llvm.org/D96974
2021-01-05CGExpr - EmitMatrixSubscriptExpr - fix getAs<> null-dereference static ↵Simon Pilgrim
analyzer warning. NFCI. getAs<> can return null if the cast is invalid, which can lead to null pointer deferences. Use castAs<> instead which will assert that the cast is valid.
2021-01-04Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped ↵Thorsten Schütt
enum (II)" This reverts commit efc82c4ad2bcb256a4f4c20238d08cd3afba4d2d.
2021-01-04[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)Thorsten Schütt
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D93765
2020-12-30Use unary CreateShuffleVector if possibleJuneyoung Lee
As mentioned in D93793, there are quite a few places where unary `IRBuilder::CreateShuffleVector(X, Mask)` can be used instead of `IRBuilder::CreateShuffleVector(X, Undef, Mask)`. Let's update them. Actually, it would have been more natural if the patches were made in this order: (1) let them use unary CreateShuffleVector first (2) update IRBuilder::CreateShuffleVector to use poison as a placeholder value (D93793) The order is swapped, but in terms of correctness it is still fine. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D93923
2020-12-08UBSAN: emit distinctive trapsTim Northover
Sometimes people get minimal crash reports after a UBSAN incident. This change tags each trap with an integer representing the kind of failure encountered, which can aid in tracking down the root cause of the problem.
2020-12-02Fix assertion in tryEmitAsConstantYaxun (Sam) Liu
due to cd95338ee3022bffd658e52cd3eb9419b4c218ca Need to check if result is LValue before getLValueBase.
2020-12-02[CUDA][HIP] Fix capturing reference to host variableYaxun (Sam) Liu
In C++ when a reference variable is captured by copy, the lambda is supposed to make a copy of the referenced variable in the captures and refer to the copy in the lambda. Therefore, it is valid to capture a reference to a host global variable in a device lambda since the device lambda will refer to the copy of the host global variable instead of access the host global variable directly. However, clang tries to avoid capturing of reference to a host global variable if it determines the use of the reference variable in the lambda function is not odr-use. Clang also tries to emit load of the reference to a global variable as load of the global variable if it determines that the reference variable is a compile-time constant. For a device lambda to capture a reference variable to host global variable and use the captured value, clang needs to be taught that in such cases the use of the reference variable is odr-use and the reference variable is not compile-time constant. This patch fixes that. Differential Revision: https://reviews.llvm.org/D91088
2020-11-06[FPEnv] Use strictfp metadata in casting nodesKevin P. Neal
The strictfp metadata was added to the casting AST nodes in D85960, but we aren't using that metadata yet. This patch adds that support. In order to avoid lots of ad-hoc passing around of the strictfp bits I updated the IRBuilder when moving from a function that has the Expr* to a function that lacks it. I believe we should switch to this pattern to keep the strictfp support from being overly invasive. For the purpose of testing that we're picking up the right metadata, I also made my tests use a pragma to make the AST's strictfp metadata not match the global strictfp metadata. This exposes issues that we need to deal with in subsequent patches, and I believe this is the right method for most all of our clang strictfp tests. Differential Revision: https://reviews.llvm.org/D88913
2020-10-21[c++20] For P0732R2 / P1907R1: Basic frontend support for class types asRichard Smith
non-type template parameters. Create a unique TemplateParamObjectDecl instance for each such value, representing the globally unique template parameter object to which the template parameter refers. No IR generation support yet; that will follow in a separate patch.
2020-10-15[SVE]Fix implicit TypeSize casts in EmitCheckValueCaroline Concatto
Using TypeSize::getFixedSize() instead of relying upon the implicit TypeSize->uint64_cast as the type is always fixed width. Differential Revision: https://reviews.llvm.org/D89313
2020-10-13[Fixed Point] Add fixed-point to floating point cast types and consteval.Bevin Hansson
Reviewed By: leonardchan Differential Revision: https://reviews.llvm.org/D86631
2020-10-13[ARM] Follow AACPS standard for volatile bit-fields access widthTies Stuij
This patch resumes the work of D16586. According to the AAPCS, volatile bit-fields should be accessed using containers of the widht of their declarative type. In such case: ``` struct S1 { short a : 1; } ``` should be accessed using load and stores of the width (sizeof(short)), where now the compiler does only load the minimum required width (char in this case). However, as discussed in D16586, that could overwrite non-volatile bit-fields, which conflicted with C and C++ object models by creating data race conditions that are not part of the bit-field, e.g. ``` struct S2 { short a; int b : 16; } ``` Accessing `S2.b` would also access `S2.a`. The AAPCS Release 2020Q2 (https://documentation-service.arm.com/static/5efb7fbedbdee951c1ccf186?token=) section 8.1 Data Types, page 36, "Volatile bit-fields - preserving number and width of container accesses" has been updated to avoid conflict with the C++ Memory Model. Now it reads in the note: ``` This ABI does not place any restrictions on the access widths of bit-fields where the container overlaps with a non-bit-field member or where the container overlaps with any zero length bit-field placed between two other bit-fields. This is because the C/C++ memory model defines these as being separate memory locations, which can be accessed by two threads simultaneously. For this reason, compilers must be permitted to use a narrower memory access width (including splitting the access into multiple instructions) to avoid writing to a different memory location. For example, in struct S { int a:24; char b; }; a write to a must not also write to the location occupied by b, this requires at least two memory accesses in all current Arm architectures. In the same way, in struct S { int a:24; int:0; int b:8; };, writes to a or b must not overwrite each other. ``` I've updated the patch D16586 to follow such behavior by verifying that we only change volatile bit-field access when: - it won't overlap with any other non-bit-field member - we only access memory inside the bounds of the record - avoid overlapping zero-length bit-fields. Regarding the number of memory accesses, that should be preserved, that will be implemented by D67399. Reviewed By: ostannard Differential Revision: https://reviews.llvm.org/D72932
2020-09-28[ubsan] nullability-arg: Fix crash on C++ member pointersVedant Kumar
Extend -fsanitize=nullability-arg to handle call sites which accept C++ member pointers. rdar://62476022 Differential Revision: https://reviews.llvm.org/D88336
2020-09-08Revert "[ARM] Follow AACPS standard for volatile bit-fields access width"Ties Stuij
This reverts commit 514df1b2bb1ecd1a33327001ea38a347fd2d0380. Some of the buildbots got llvm-lit errors on CodeGen/volatile.c
2020-09-08[ARM] Follow AACPS standard for volatile bit-fields access widthTies Stuij
This patch resumes the work of D16586. According to the AAPCS, volatile bit-fields should be accessed using containers of the widht of their declarative type. In such case: ``` struct S1 { short a : 1; } ``` should be accessed using load and stores of the width (sizeof(short)), where now the compiler does only load the minimum required width (char in this case). However, as discussed in D16586, that could overwrite non-volatile bit-fields, which conflicted with C and C++ object models by creating data race conditions that are not part of the bit-field, e.g. ``` struct S2 { short a; int b : 16; } ``` Accessing `S2.b` would also access `S2.a`. The AAPCS Release 2020Q2 (https://documentation-service.arm.com/static/5efb7fbedbdee951c1ccf186?token=) section 8.1 Data Types, page 36, "Volatile bit-fields - preserving number and width of container accesses" has been updated to avoid conflict with the C++ Memory Model. Now it reads in the note: ``` This ABI does not place any restrictions on the access widths of bit-fields where the container overlaps with a non-bit-field member or where the container overlaps with any zero length bit-field placed between two other bit-fields. This is because the C/C++ memory model defines these as being separate memory locations, which can be accessed by two threads simultaneously. For this reason, compilers must be permitted to use a narrower memory access width (including splitting the access into multiple instructions) to avoid writing to a different memory location. For example, in struct S { int a:24; char b; }; a write to a must not also write to the location occupied by b, this requires at least two memory accesses in all current Arm architectures. In the same way, in struct S { int a:24; int:0; int b:8; };, writes to a or b must not overwrite each other. ``` Patch D16586 was updated to follow such behavior by verifying that we only change volatile bit-field access when: - it won't overlap with any other non-bit-field member - we only access memory inside the bounds of the record - avoid overlapping zero-length bit-fields. Regarding the number of memory accesses, that should be preserved, that will be implemented by D67399. Differential Revision: https://reviews.llvm.org/D72932 The following people contributed to this patch: - Diogo Sampaio - Ties Stuij
2020-08-26[SVE] Remove calls to VectorType::getNumElements from clangChristopher Tetreault
Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D82582
2020-08-03[OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 3Saiyedul Islam
Provides AMDGCN and NVPTX specific specialization of getGPUWarpSize, getGPUThreadID, and getGPUNumThreads methods. Adds tests for AMDGCN codegen for these methods in generic and simd modes. Also changes the precondition in InitTempAlloca to be slightly more permissive. Useful for AMDGCN OpenMP codegen where allocas are created with a cast to an address space. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D84260
2020-07-21Reapply "Rename/refactor isIntegerConstantExpression to ↵David Blaikie
getIntegerConstantExpression" Reapply 49e5f603d40083dce9c05796e3cde3a185c3beba which had been reverted in c94332919bd922032e979b3ae3ced5ca5bdf9650. Originally reverted because I hadn't updated it in quite a while when I got around to committing it, so there were a bunch of missing changes to new code since I'd written the patch. Reviewers: aaron.ballman Differential Revision: https://reviews.llvm.org/D76646
2020-07-12Revert "Rename/refactor isIntegerConstantExpression to ↵David Blaikie
getIntegerConstantExpression" Broke buildbots since I hadn't updated this patch in a while. Sorry for the noise. This reverts commit 49e5f603d40083dce9c05796e3cde3a185c3beba.
2020-07-12Rename/refactor isIntegerConstantExpression to getIntegerConstantExpressionDavid Blaikie
There is a version that just tests (also called isIntegerConstantExpression) & whereas this version is specifically used when the value is of interest (a few call sites were actually refactored to calling the test-only version) so let's make the API look more like it. Reviewers: aaron.ballman Differential Revision: https://reviews.llvm.org/D76646
2020-07-09[OPENMP50] extend array section for stride (Parsing/Sema/AST)cchen
Reviewers: ABataev, jdoerfert Reviewed By: ABataev Subscribers: yaxunl, guansong, arphaman, sstefan1, cfe-commits, sandoval, dreachem Tags: #clang Differential Revision: https://reviews.llvm.org/D82800
2020-07-08[OpenMPIRBuilder][Fix] Move llvm::omp::types to OpenMPIRBuilder.sstefan1
Summary: D82193 exposed a problem with global type definitions in `OMPConstants.h`. This causes a race when running in thinLTO mode. Types now live inside of OpenMPIRBuilder to prevent this from happening. Reviewers: jdoerfert Subscribers: yaxunl, hiraditya, guansong, dexonsmith, aaron.ballman, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D83176