aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGCall.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-07-01Implement AVX ABI Warning/errorErich Keane1-1/+7
The x86-64 "avx" feature changes how >128 bit vector types are passed, instead of being passed in separate 128 bit registers, they can be passed in 256 bit registers. "avx512f" does the same thing, except it switches from 256 bit registers to 512 bit registers. The result of both of these is an ABI incompatibility between functions compiled with and without these features. This patch implements a warning/error pair upon an attempt to call a function that would run afoul of this. First, if a function is called that would have its ABI changed, we issue a warning. Second, if said call is made in a situation where the caller and callee are known to have different calling conventions (such as the case of 'target'), we instead issue an error. Differential Revision: https://reviews.llvm.org/D82562
2020-06-18[ARM][Clang] Removing lowering of half-precision FP arguments and returns ↵Lucas Prates1-36/+8
from Clang's CodeGen Summary: On the process of moving the argument lowering handling for half-precision floating point arguments and returns to the backend, this patch removes the code that was responsible for handling the coercion of those arguments in Clang's Codegen. Reviewers: rjmccall, chill, ostannard, dnsampaio Reviewed By: ostannard Subscribers: stuij, kristof.beyls, dmgreen, danielkiss, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81451
2020-06-15attempt to fix failing buildbots after 3bab88b7baa20b276faaee0aa7ca87f636c91877Tyker1-10/+9
Prevent IR-gen from emitting consteval declarations Summary: with this patch instead of emitting calls to consteval function. the IR-gen will emit a store of the already computed result.
2020-06-15Revert "Prevent IR-gen from emitting consteval declarations"Kirill Bobyrev1-9/+10
This reverts commit 3bab88b7baa20b276faaee0aa7ca87f636c91877. This patch causes test failures: http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick/builds/17260
2020-06-15Prevent IR-gen from emitting consteval declarationsTyker1-10/+9
Summary: with this patch instead of emitting calls to consteval function. the IR-gen will emit a store of the already computed result. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76420
2020-06-15[IR] Prefer hasFnAttribute() where possible (NFC)Nikita Popov1-2/+1
When checking for an enum function attribute, use hasFnAttribute() rather than hasAttribute() at FunctionIndex, because it is significantly faster (and more concise to boot).
2020-06-09Reland (again) D80966 [codeview] Put !heapallocsite on calls to operator newArthur Eubanks1-1/+1
Check that getDebugInfo() is not null, as in the first revision, before calling getDebugInfo()->addHeapAllocSiteMetadata(). Else would cause a crash with a new expression in a default arg. --- Clang marks calls to operator new as heap allocation sites, but the operator declared at global scope returns a void pointer. There is no explicit cast in the code, so the compiler has to write down the allocated type itself. Also generalize a cast to use CallBase, so that we mark heap alloc sites when exceptions are enabled. Differential Revision: https://reviews.llvm.org/D80966
2020-06-08Revert "Reland D80966 [codeview] Put !heapallocsite on calls to operator new"Arthur Eubanks1-1/+1
This reverts commit b6e143aa5448bbe29da7b045072e66a31813bced. Causes https://bugs.chromium.org/p/chromium/issues/detail?id=1092370#c5. Will investigate and reland (again).
2020-06-07Reland D80966 [codeview] Put !heapallocsite on calls to operator newFangrui Song1-1/+1
With a change to use `CGM.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo` instead of `getDebugInfo()`, to fix `Profile-<arch> :: instrprof-gcov-multithread_fork.test` See CodeGenModule::CodeGenModule, `EmitGcovArcs || EmitGcovNotes` can set `clang::CodeGen::CodeGenModule::DebugInfo`. --- Clang marks calls to operator new as heap allocation sites, but the operator declared at global scope returns a void pointer. There is no explicit cast in the code, so the compiler has to write down the allocated type itself. Also generalize a cast to use CallBase, so that we mark heap alloc sites when exceptions are enabled. Differential Revision: https://reviews.llvm.org/D80966
2020-06-06Revert "[codeview] Put !heapallocsite on calls to operator new"Douglas Yung1-1/+1
This reverts commit 672ed5386024ba5cee53e19d637b7920a4889837. This commit is hitting an assertion failure across multiple bots in the test: Profile-<arch> :: instrprof-gcov-multithread_fork.test Failing bots include: http://lab.llvm.org:8011/builders/llvm-avr-linux/builds/2205 http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/8967 http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/10789 http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/27750 http://lab.llvm.org:8011/builders/sanitizer-ppc64be-linux/builds/16751
2020-06-05[codeview] Put !heapallocsite on calls to operator newReid Kleckner1-1/+1
Clang marks calls to operator new as heap allocation sites, but the operator declared at global scope returns a void pointer. There is no explicit cast in the code, so the compiler has to write down the allocated type itself. Also generalize a cast to use CallBase, so that we mark heap alloc sites when exceptions are enabled. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D80966
2020-06-01Fix how cc1 command line options are mapped into FP options.John McCall1-5/+6
Canonicalize on storing FP options in LangOptions instead of redundantly in CodeGenOptions. Incorporate -ffast-math directly into the values of those LangOptions rather than considering it separately when building FPOptions. Build IR attributes from those options rather than a mix of sources. We should really simplify the driver/cc1 interaction here and have the driver pass down options that cc1 directly honors. That can happen in a follow-up, though. Patch by Michele Scandale! https://reviews.llvm.org/D80315
2020-05-21[clang] Add nomerge function attribute to clangZequan Wu1-0/+6
Differential Revision: https://reviews.llvm.org/D79121
2020-05-21Revert "Add nomerge function attribute to clang"Zequan Wu1-6/+0
This reverts commit 307e85395485e1eff9533b2d7952b16f33ceae38.
2020-05-21Add nomerge function attribute to clangZequan Wu1-0/+6
2020-05-19[CGCall] Annotate references with "align" attribute.Eli Friedman1-11/+23
If we're going to assume references are dereferenceable, we should also assume they're aligned: otherwise, we can't actually dereference them. See also D80072. Differential Revision: https://reviews.llvm.org/D80166
2020-05-19[clang] Add an API to retrieve implicit constructor arguments.Martin Böhme1-1/+1
Summary: This is needed in Swift for C++ interop -- see here for the corresponding Swift change: https://github.com/apple/swift/pull/30630 As part of this change, I've had to make some changes to the interface of CGCXXABI to return the additional parameters separately rather than adding them directly to a `CallArgList`. Reviewers: rjmccall Reviewed By: rjmccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D79942
2020-05-16Expose IRGen API to add the default IR attributes to a function definition.John McCall1-49/+92
I've also made a stab at imposing some more order on where and how we add attributes; this part should be NFC. I wasn't sure whether the CUDA use case for libdevice should propagate CPU/features attributes, so there's a bit of unnecessary duplication.
2020-05-15[IR] Convert null-pointer-is-valid into an enum attributeNikita Popov1-1/+1
The "null-pointer-is-valid" attribute needs to be checked by many pointer-related combines. To make the check more efficient, convert it from a string into an enum attribute. In the future, this attribute may be replaced with data layout properties. Differential Revision: https://reviews.llvm.org/D78862
2020-05-08clang: Cleanup usage of CreateMemCpyMatt Arsenault1-14/+10
It handles the the pointee type casts in preparation for opaque pointers.
2020-05-05[clang][codegen] Hoist parameter attribute setting in function prolog.Michael Liao1-6/+19
Summary: - If the coerced type is still a pointer, it should be set with proper parameter attributes, such as `noalias`, `nonnull`, and etc. Hoist that (pointer) parameter attribute setting so that the coerced pointer parameter could be marked properly. Depends on D79394 Reviewers: rjmccall, kerbowa, yaxunl Subscribers: jvesely, nhaehnle, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D79395
2020-05-05[clang][codegen] Refactor argument loading in function prolog. NFC.Michael Liao1-24/+19
Summary: - Skip copying function arguments and unnecessary casting by using them directly. Reviewers: rjmccall, kerbowa, yaxunl Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D79394
2020-04-29Fix Wparentheses gcc warning. NFC.Simon Pilgrim1-1/+1
It should be either a float(32) or an int(32).
2020-04-28[CMSE] Clear padding bits of struct/unions/fp16 passed by valueMomchil Velikov1-2/+242
When passing a value of a struct/union type from secure to non-secure state (that is returning from a CMSE entry function or passing an argument to CMSE-non-secure call), there is a potential sensitive information leak via the padding bits in the structure. It is not possible in the general case to ensure those bits are cleared by using Standard C/C++. This patch makes the compiler emit code to clear such padding bits. Since type information is lost in LLVM IR, the code generation is done by Clang. For each interesting record type, we build a bitmask, in which all the bits, corresponding to user declared members, are set. Values of record types are returned by coercing them to an integer. After the coercion, the coerced value is masked (with bitwise AND) and then returned by the function. In a similar manner, values of record types are passed as arguments by coercing them to an array of integers, and the coerced values themselves are masked. For union types, we effectively clear only bits, which aren't part of any member, since we don't know which is the currently active one. The compiler will issue a warning, whenever a union is passed to non-secure state. Values of half-precision floating-point types are passed in the least significant bits of a 32-bit register (GPR or FPR) with the most significant bits unspecified. Since this is also a potential leak of sensitive information, this patch also clears those unspecified bits. Differential Revision: https://reviews.llvm.org/D76369
2020-04-27[IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand().Craig Topper1-7/+7
This method has been commented as deprecated for a while. Remove it and replace all uses with the equivalent getCalledOperand(). I also made a few cleanups in here. For example, to removes use of getElementType on a pointer when we could just use getFunctionType from the call. Differential Revision: https://reviews.llvm.org/D78882
2020-04-20[Local] Update getOrEnforceKnownAlignment/getKnownAlignment to use ↵Craig Topper1-2/+2
Align/MaybeAlign. Differential Revision: https://reviews.llvm.org/D78443
2020-04-11Revert "[TLI] Per-function fveclib for math library used for vectorization"Mehdi Amini1-21/+0
This reverts commit 60c642e74be6af86906d9f3d982728be7bd4329f. This patch is making the TLI "closed" for a predefined set of VecLib while at the moment it is extensible for anyone to customize when using LLVM as a library. Reverting while we figure out a way to re-land it without losing the generality of the current API. Differential Revision: https://reviews.llvm.org/D77925
2020-04-09[TLI] Per-function fveclib for math library used for vectorizationWenlei He1-0/+21
Summary: Encode `-fveclib` setting as per-function attribute so it can threaded through to LTO backends. Accordingly per-function TLI now reads the attributes and select available vector function list based on that. Now we also populate function list for all supported vector libraries for the shared per-module `TargetLibraryInfoImpl`, so each function can select its available vector list independently but without duplicating the vector function lists. Inlining between incompatbile vectlib attributed is also prohibited now. Subscribers: hiraditya, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77632
2020-04-03[clang][opaque pointers] Fix up a bunch of "getType()->getElementType()"Eli Friedman1-4/+4
In contexts where we know an LLVM type is a pointer, there's generally some simpler way to get the pointee type.
2020-03-24[CodeGen] Add an alignment attribute to all sret parametersErik Pilkington1-0/+1
This fixes a miscompile when the parameter is actually underaligned. rdar://58316406 Differential revision: https://reviews.llvm.org/D74183
2020-03-24[ARM][CMSE] Implement CMSE attributesMomchil Velikov1-0/+7
This patch adds CMSE attributes `cmse_nonsecure_call` and `cmse_nonsecure_entry`. As usual, specification is available here: https://developer.arm.com/docs/ecm0359818/latest Patch by Javed Absar, Bradley Smith, David Green, Momchil Velikov, possibly others. Differential Revision: https://reviews.llvm.org/D71129
2020-03-20[CodeGen] Emit destructor calls to destruct non-trivial C struct objectsAkira Hatanaka1-0/+5
returned by function calls or loaded from volatile objects rdar://problem/51867864 Differential Revision: https://reviews.llvm.org/D66094
2020-03-17[SVE][Inline-Asm] Add constraints for SVE ACLE typesKerry McLaughlin1-4/+6
Summary: Adds the constraints described below to ensure that we can tie variables of SVE ACLE types to operands in inline-asm: - y: SVE registers Z0-Z7 - Upl: One of the low eight SVE predicate registers (P0-P7) - Upa: Full range of SVE predicate registers (P0-P15) Reviewers: sdesmalen, huntergr, rovka, cameron.mcinally, efriedma, rengolin Reviewed By: efriedma Subscribers: miyuki, tschuett, rkruppe, psnobl, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75690
2020-03-07Assume ieee behavior without denormal-fp-math attributeMatt Arsenault1-3/+2
2020-02-26[clang] Annotating C++'s `operator new` with more attributesRoman Lebedev1-0/+7
Summary: Right now we annotate C++'s `operator new` with `noalias` attribute, which very much is healthy for optimizations. However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]], there are more promises on global `operator new`, namely: * non-`std::nothrow_t` `operator new` *never* returns `nullptr` * If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned * ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that. Supplying this information may not cause immediate landslide effects on any specific benchmarks, but it for sure will be healthy for optimizer in the sense that the IR will better reflect the guarantees provided in the source code. The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias` attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes? The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`. But while it is okay to add `noalias` metadata in backend, we really should be adding at least the alignment metadata to the AST, since that allows us to perform sema checks on it. Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith Reviewed By: rsmith Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D73380
2020-02-20[Sema] Demote call-site-based 'alignment is a power of two' check for ↵Roman Lebedev1-0/+4
AllocAlignAttr into a warning Summary: As @rsmith notes in https://reviews.llvm.org/D73020#inline-672219 while that is certainly UB land, it may not be actually reachable at runtime, e.g.: ``` template<int N> void *make() { if ((N & (N-1)) == 0) return operator new(N, std::align_val_t(N)); else return operator new(N); } void *p = make<7>(); ``` and we shouldn't really error-out there. That being said, i'm not really following the logic here. Which ones of these cases should remain being an error? Reviewers: rsmith, erichkeane Reviewed By: erichkeane Subscribers: cfe-commits, rsmith Tags: #clang Differential Revision: https://reviews.llvm.org/D73996
2020-02-13[AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstructionFangrui Song1-1/+1
Similar to rL328848.
2020-02-12Revert "[IRGen] Emit lifetime intrinsics around temporary aggregate argument ↵Erik Pilkington1-21/+1
allocas" This reverts commit fafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402. Should fix ppc stage2 failure: http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/23546 Conflicts: clang/lib/CodeGen/CGCall.cpp
2020-02-11Re-land "[MS] Overhaul how clang passes overaligned args on x86_32"Reid Kleckner1-6/+30
This brings back 2af74e27ed7d0832cbdde9cb969aaca7a42e99f9 and reverts eaabaf7e04fe98990a8177a3e053346395efde1c. The changes were correct, the code that was broken contained an ODR violation that assumed that these types are passed equivalently: struct alignas(uint64_t) Wrapper { uint64_t P }; void f(uint64_t p); void f(Wrapper p); MSVC does not pass them the same way, and so clang-cl should not pass them the same way either.
2020-02-10[ubsan] Null-check and adjust TypeLoc before using itVedant Kumar1-1/+1
Null-check and adjut a TypeLoc before casting it to a FunctionTypeLoc. This fixes a crash in -fsanitize=nullability-return, and also makes the location of the nonnull type available when the return type is adjusted. rdar://59263039 Differential Revision: https://reviews.llvm.org/D74355
2020-02-10[clang][codegen] Fix another lifetime emission on alloca on non-default ↵Michael Liao1-3/+5
address space. - Lifetime intrinsics expect the pointer directly from alloca. Need extra handling for targets with alloca on non-default (or non-zero) address space.
2020-02-07[IRGen] Emit lifetime intrinsics around temporary aggregate argument allocasErik Pilkington1-1/+19
These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Differential revision: https://reviews.llvm.org/D74094
2020-02-06[ubsan] Omit return value check when return block is unreachableVedant Kumar1-0/+5
If the return block is unreachable, clang removes it in CodeGenFunction::FinishFunction(). This removal can leave dangling references to values defined in the return block if the return block has successors, which it /would/ if UBSan's return value check is emitted. In this case, as the UBSan check wouldn't be reachable, it's better to simply not emit it. rdar://59196131
2020-02-04Separately track input and output denormal modeMatt Arsenault1-5/+5
AMDGPU and x86 at least both have separate controls for whether denormal results are flushed on output, and for whether denormals are implicitly treated as 0 as an input. The current DAGCombiner use only really cares about the input treatment of denormals.
2020-01-31Don't assume a reference refers to at least sizeof(T) bytes.Richard Smith1-4/+4
When T is a class type, only nvsize(T) bytes need be accessible through the reference. We had matching bugs in the application of the dereferenceable attribute and in -fsanitize=undefined.
2020-01-28[NFC] Fix comment typoFrancis Visoiu Mistrih1-1/+1
2020-01-28[CodeGen] Attach no-builtin attributes to function definitions with no DeclFrancis Visoiu Mistrih1-16/+47
When using -fno-builtin[-<name>], we don't attach the IR attributes to function definitions with no Decl, like the ones created through `CreateGlobalInitOrDestructFunction`. This results in projects using -fno-builtin or -ffreestanding to start seeing symbols like _memset_pattern16. The fix changes the behavior to always add the attribute if LangOptions requests it. Differential Revision: https://reviews.llvm.org/D73495
2020-01-28Revert "[MS] Overhaul how clang passes overaligned args on x86_32"Hans Wennborg1-30/+6
It broke some Chromium tests, so let's revert until it can be fixed; see https://crbug.com/1046362 This reverts commit 2af74e27ed7d0832cbdde9cb969aaca7a42e99f9.
2020-01-23[MS] Overhaul how clang passes overaligned args on x86_32Reid Kleckner1-6/+30
MSVC 2013 would refuse to pass highly aligned things (typically vectors and aggregates) by value. Users would receive this error: t.cpp(11) : error C2719: 'w': formal parameter with __declspec(align('32')) won't be aligned t.cpp(11) : error C2719: 'q': formal parameter with __declspec(align('32')) won't be aligned However, in MSVC 2015, this behavior was changed, and highly aligned things are now passed indirectly. To avoid breaking backwards incompatibility, objects that do not have a *required* high alignment (i.e. double) are still passed directly, even though they are not naturally aligned. This change implements the new behavior of passing things indirectly. The new behavior is: - up to three vector parameters can be passed in [XYZ]MM0-2 - remaining arguments with required alignment greater than 4 bytes are passed indirectly Previously, MSVC never passed things truly indirectly, meaning clang would always apply the byval attribute to indirect arguments. We had to go to the trouble of adding inalloca so that non-trivially copyable C++ types could be passed in place without copying the object representation. When inalloca was added, we asserted that all arguments passed indirectly must use byval. With this change, that assert no longer holds, and I had to update inalloca to handle that case. The implicit sret pointer parameter was already handled this way, and this change generalizes some of that logic to arguments. There are two cases that this change leaves unfixed: 1. objects that are non-trivially copyable *and* overaligned 2. vectorcall + inalloca + vectors For case 1, I need to touch C++ ABI code in MicrosoftCXXABI.cpp, so I want to do it in a follow-up. For case 2, my fix is one line, but it will require updating IR tests to use lots of inreg, so I wanted to separate it out. Related to D71915 and D72110 Fixes most of PR44395 Reviewed By: rjmccall, craig.topper, erichkeane Differential Revision: https://reviews.llvm.org/D72114
2020-01-23[Codegen] If reasonable, materialize clang's `AllocAlignAttr` as llvm's ↵Roman Lebedev1-8/+20
Alignment Attribute on call-site function return value Summary: Much like with the previous patch (D73005) with `AssumeAlignedAttr` handling, results in mildly more readable IR, and will improve test coverage in upcoming patch. Note that in `AllocAlignAttr`'s case, there is no requirement for that alignment parameter to end up being an I-C-E. Reviewers: erichkeane, jdoerfert, hfinkel, aaron.ballman, rsmith Reviewed By: erichkeane Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73006