aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGCall.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-01-23[Codegen] If reasonable, materialize clang's `AssumeAlignedAttr` as llvm's ↵Roman Lebedev1-9/+88
Alignment Attribute on call-site function return value Summary: This should be mostly NFC - we still lower the same alignment knowledge to the IR. The main reasoning here is that this somewhat improves readability of IR like this, and will improve test coverage in upcoming patch. Even though the alignment is guaranteed to always be an I-C-E, we don't always materialize it as llvm's Alignment Attribute because: 1. There may be a non-zero offset 2. We may be sanitizing for alignment Note that if there already was an IR alignment attribute on return value, we union them, and thus the alignment only ever rises. Also, there is a second relevant clang attribute `AllocAlignAttr`, so that is why `AbstractAssumeAlignedAttrEmitter` is templated. Reviewers: erichkeane, jdoerfert, hfinkel, aaron.ballman, rsmith Reviewed By: erichkeane Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73005
2020-01-21[NFC][Codegen] Use MaybeAlign + APInt::getLimitedValue() when creating ↵Roman Lebedev1-3/+2
Alignment attr Summary: Just an NFC code cleanup i stumbled upon when stumbling through clang alignment attribute handling. Reviewers: erichkeane, gchatelet, courbet, jdoerfert Reviewed By: gchatelet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72993
2020-01-21[Codegen] Emit both AssumeAlignedAttr and AllocAlignAttr assumptions if they ↵Roman Lebedev1-1/+2
exist Summary: We shouldn't be just giving up if we find one of them (like we currently do with `AssumeAlignedAttr`), we should emit them all. As the tests show, even if we materialized good knowledge from `__attribute__((assume_aligned(32)`, it doesn't mean `__attribute__((alloc_align([...])))` info won't be useful. It might be, but that isn't given. Reviewers: erichkeane, jdoerfert, aaron.ballman Reviewed By: erichkeane Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72979
2020-01-17Consolidate internal denormal flushing controlsMatt Arsenault1-8/+7
Currently there are 4 different mechanisms for controlling denormal flushing behavior, and about as many equivalent frontend controls. - AMDGPU uses the fp32-denormals and fp64-f16-denormals subtarget features - NVPTX uses the nvptx-f32ftz attribute - ARM directly uses the denormal-fp-math attribute - Other targets indirectly use denormal-fp-math in one DAGCombine - cl-denorms-are-zero has a corresponding denorms-are-zero attribute AMDGPU wants a distinct control for f32 flushing from f16/f64, and as far as I can tell the same is true for NVPTX (based on the attribute name). Work on consolidating these into the denormal-fp-math attribute, and a new type specific denormal-fp-math-f32 variant. Only ARM seems to support the two different flush modes, so this is overkill for the other use cases. Ideally we would error on the unsupported positive-zero mode on other targets from somewhere. Move the logic for selecting the flush mode into the compiler driver, instead of handling it in cc1. denormal-fp-math/denormal-fp-math-f32 are now both cc1 flags, but denormal-fp-math-f32 is not yet exposed as a user flag. -cl-denorms-are-zero, -fcuda-flush-denormals-to-zero and -fno-cuda-flush-denormals-to-zero will be mapped to -fp-denormal-math-f32=ieee or preserve-sign rather than the old attributes. Stop emitting the denorms-are-zero attribute for the OpenCL flag. It has no in-tree users. The meaning would also be target dependent, such as the AMDGPU choice to treat this as only meaning allow flushing of f32 and not f16 or f64. The naming is also potentially confusing, since DAZ in other contexts refers to instructions implicitly treating input denormals as zero, not necessarily flushing output denormals to zero. This also does not attempt to change the behavior for the current attribute. The LangRef now states that the default is ieee behavior, but this is inaccurate for the current implementation. The clang handling is slightly hacky to avoid touching the existing denormal-fp-math uses. Fixing this will be left for a future patch. AMDGPU is still using the subtarget feature to control the denormal mode, but the new attribute are now emitted. A future change will switch this and remove the subtarget features.
2020-01-10Add support for __declspec(guard(nocf))Andrew Paverd1-0/+11
Summary: Avoid using the `nocf_check` attribute with Control Flow Guard. Instead, use a new `"guard_nocf"` function attribute to indicate that checks should not be added on indirect calls within that function. Add support for `__declspec(guard(nocf))` following the same syntax as MSVC. Reviewers: rnk, dmajor, pcc, hans, aaron.ballman Reviewed By: aaron.ballman Subscribers: aaron.ballman, tomrittervg, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D72167
2019-12-12[clang] Turn -fno-builtin flag into an IR AttributeGuillaume Chatelet1-11/+14
Summary: This is a follow up on https://reviews.llvm.org/D61634#1742154 to turn the clang driver -fno-builtin flag into an IR attribute. I also investigated pushing the attribute earlier on (in Sema) but it looks like this patch is simple and will cover all function calls. Reviewers: aaron.ballman, courbet Subscribers: cfe-commits, tejohnson Tags: #clang Differential Revision: https://reviews.llvm.org/D71193
2019-12-10Fix bug 44190 - wrong code with #pragma pack(1)Yaxun (Sam) Liu1-3/+2
https://github.com/llvm/llvm-project/commit/5b330e8d6122c336d81dfd11c864e6c6240a381e caused a regression on s390: https://bugs.llvm.org/show_bug.cgi?id=44190 we need to copy if if either the argument is non-byval or the argument is underaligned. Differential Revision: https://reviews.llvm.org/D71282
2019-12-09Avoid Attr.h includes, CodeGen editionReid Kleckner1-1/+2
This saves around 20 includes of Attr.h. Not much.
2019-12-05 Reapply af57dbf12e54 "Add support for options -frounding-math, ↵Melanie Blower1-0/+14
ftrapping-math, -ffp-model=, and -ffp-exception-behavior=" Patch was reverted because https://bugs.llvm.org/show_bug.cgi?id=44048 The original patch is modified to set the strictfp IR attribute explicitly in CodeGen instead of as a side effect of IRBuilder. In the 2nd attempt to reapply there was a windows lit test fail, the tests were fixed to use wildcard matching. Differential Revision: https://reviews.llvm.org/D62731
2019-12-04Revert " Reapply af57dbf12e54 "Add support for options ↵Melanie Blower1-14/+0
-frounding-math, ftrapping-math, -ffp-model=, and -ffp-exception-behavior="" This reverts commit cdbed2dd856c14687efd741c2d8321686102acb8. Build break on Windows (lit fail)
2019-12-04 Reapply af57dbf12e54 "Add support for options -frounding-math, ↵Melanie Blower1-0/+14
ftrapping-math, -ffp-model=, and -ffp-exception-behavior=" Patch was reverted because https://bugs.llvm.org/show_bug.cgi?id=44048 The original patch is modified to set the strictfp IR attribute explicitly in CodeGen instead of as a side effect of IRBuilder Differential Revision: https://reviews.llvm.org/D62731
2019-12-03[CodeGen][ObjC] Emit a primitive store to store a __strong field inAkira Hatanaka1-1/+6
ExpandTypeFromArgs This fixes a bug in IRGen where a call to `llvm.objc.storeStrong` was being emitted to initialize a __strong field of an uninitialized temporary struct, which caused crashes at runtime. rdar://problem/51807365
2019-12-03[NFC] Pass a reference to CodeGenFunction to methods of LValue andAkira Hatanaka1-17/+17
AggValueSlot This reapplies 8a5b7c35709d9ce1f44a99f0c5b084bf2696ea17 after a null dereference bug in CGOpenMPRuntime::emitUserDefinedMapper. Original commit message: This is needed for the pointer authentication work we plan to do in the near future. https://github.com/apple/llvm-project/blob/a63a81bd9911f87a0b5dcd5bdd7ccdda7124af87/clang/docs/PointerAuthentication.rst
2019-12-03Revert "[NFC] Pass a reference to CodeGenFunction to methods of LValue and"Akira Hatanaka1-17/+17
This reverts commit 8a5b7c35709d9ce1f44a99f0c5b084bf2696ea17. This seems to have broken UBSan because of a null dereference.
2019-12-03[NFC] Pass a reference to CodeGenFunction to methods of LValue andAkira Hatanaka1-17/+17
AggValueSlot This is needed for the pointer authentication work we plan to do in the near future. https://github.com/apple/llvm-project/blob/a63a81bd9911f87a0b5dcd5bdd7ccdda7124af87/clang/docs/PointerAuthentication.rst
2019-11-19Work on cleaning up denormal mode handlingMatt Arsenault1-2/+3
Cleanup handling of the denormal-fp-math attribute. Consolidate places checking the allowed names in one place. This is in preparation for introducing FP type specific variants of the denormal-fp-mode attribute. AMDGPU will switch to using this in place of the current hacky use of subtarget features for the denormal mode. Introduce a new header for dealing with FP modes. The constrained intrinsic classes define related enums that should also be moved into this header for uses in other contexts. The verifier could use a check to make sure the denorm-fp-mode attribute is sane, but there currently isn't one. Currently, DAGCombiner incorrectly asssumes non-IEEE behavior by default in the one current user. Clang must be taught to start emitting this attribute by default to avoid regressions when this is switched to assume ieee behavior if the attribute isn't present.
2019-11-05[hip] Enable pointer argument lowering through coercing type.Michael Liao1-0/+9
Reviewers: tra, rjmccall, yaxunl Subscribers: jvesely, nhaehnle, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69826
2019-10-29[clang] Add no_builtin attributeGuillaume Chatelet1-4/+20
Summary: This is a follow up on https://reviews.llvm.org/D61634 This patch is simpler and only adds the no_builtin attribute. Reviewers: tejohnson, courbet, theraven, t.p.northover, jdoerfert Subscribers: mgrang, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68028 This is a re-submit after it got reverted in https://reviews.llvm.org/rGbd8791610948 since the breakage doesn't seem to come from this patch.
2019-10-28Revert "[clang] Add no_builtin attribute"Vlad Tsyrklevich1-20/+4
This reverts commit bd87916109483d33455cbf20da2309197b983cdd. It was causing ASan/MSan failures on the sanitizer buildbots.
2019-10-28[clang] Add no_builtin attributeGuillaume Chatelet1-4/+20
Summary: This is a follow up on https://reviews.llvm.org/D61634 This patch is simpler and only adds the no_builtin attribute. Reviewers: tejohnson, courbet, theraven, t.p.northover, jdoerfert Subscribers: mgrang, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68028
2019-10-15[Alignment] Migrate Attribute::getWith(Stack)AlignmentGuillaume Chatelet1-2/+2
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Reviewed By: courbet Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68792 llvm-svn: 374884
2019-10-11Reland r374450 with Richard Smith's comments and test fixed.Erich Keane1-1/+1
The behavior from the original patch has changed, since we're no longer allowing LLVM to just ignore the alignment. Instead, we're just assuming the maximum possible alignment. Differential Revision: https://reviews.llvm.org/D68824 llvm-svn: 374562
2019-10-10Revert 374450 "Fix __builtin_assume_aligned with too large values."Nico Weber1-1/+1
The test fails on Windows, with error: 'warning' diagnostics expected but not seen: File builtin-assume-aligned.c Line 62: requested alignment must be 268435456 bytes or smaller; assumption ignored error: 'warning' diagnostics seen but not expected: File builtin-assume-aligned.c Line 62: requested alignment must be 8192 bytes or smaller; assumption ignored llvm-svn: 374456
2019-10-10Fix __builtin_assume_aligned with too large values.Erich Keane1-1/+1
Code to handle __builtin_assume_aligned was allowing larger values, but would convert this to unsigned along the way. This patch removes the EmitAssumeAligned overloads that take unsigned to do away with this problem. Additionally, it adds a warning that values greater than 1 <<29 are ignored by LLVM. Differential Revision: https://reviews.llvm.org/D68824 llvm-svn: 374450
2019-10-08[IRGen] Emit lifetime markers for temporary struct allocasFrancis Visoiu Mistrih1-0/+22
When passing arguments using temporary allocas, we need to add the appropriate lifetime markers so that the stack coloring passes can re-use the stack space. This patch keeps track of all the lifetime.start calls emited before the codegened call, and adds the corresponding lifetime.end calls after the call. Differential Revision: https://reviews.llvm.org/D68611 llvm-svn: 374126
2019-10-08[SVE][IR] Scalable Vector size queries and IR instruction supportGraham Hunter1-4/+4
* Adds a TypeSize struct to represent the known minimum size of a type along with a flag to indicate that the runtime size is a integer multiple of that size * Converts existing size query functions from Type.h and DataLayout.h to return a TypeSize result * Adds convenience methods (including a transparent conversion operator to uint64_t) so that most existing code 'just works' as if the return values were still scalars. * Uses the new size queries along with ElementCount to ensure that all supported instructions used with scalable vectors can be constructed in IR. Reviewers: hfinkel, lattner, rkruppe, greened, rovka, rengolin, sdesmalen Reviewed By: rovka, sdesmalen Differential Revision: https://reviews.llvm.org/D53137 llvm-svn: 374042
2019-10-03[Alignment][Clang][NFC] Add CharUnits::getAsAlignGuillaume Chatelet1-1/+1
Summary: This is a prerequisite to removing `llvm::GlobalObject::setAlignment(unsigned)`. This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68274 llvm-svn: 373592
2019-10-03Silence static analyzer getAs<RecordType> null dereference warnings. NFCI.Simon Pilgrim1-2/+2
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<RecordType> directly and if not assert will fire for us. llvm-svn: 373584
2019-09-30[Alignment][NFC] Remove AllocaInst::setAlignment(unsigned)Guillaume Chatelet1-1/+1
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, arsenm, jvesely, nhaehnle, eraman, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68141 llvm-svn: 373207
2019-09-29For P0784R7: compute whether a variable has constant destruction if itRichard Smith1-1/+1
has a constexpr destructor. For constexpr variables, reject if the variable does not have constant destruction. In all cases, do not emit runtime calls to the destructor for variables with constant destruction. llvm-svn: 373159
2019-09-23[Alignment] fix buildGuillaume Chatelet1-5/+6
llvm-svn: 372562
2019-08-14[Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-4/+4
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
2019-07-22[OpenCL] Improve destructor support in C++ for OpenCLMarco Antognini1-1/+1
This re-applies r366422 with a fix for Bug PR42665 and a new regression test. llvm-svn: 366670
2019-07-20[Clang] Replace cc1 options '-mdisable-fp-elim' and '-momit-leaf-frame-pointer'Yuanfang Chen1-9/+12
with '-mframe-pointer' After D56351 and D64294, frame pointer handling is migrated to tri-state (all, non-leaf, none) in clang driver and on the function attribute. This patch makes the frame pointer handling cc1 option tri-state. Reviewers: chandlerc, rnk, t.p.northover, MaskRay Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D56353 llvm-svn: 366645
2019-07-18Revert r366422: [OpenCL] Improve destructor support in C++ for OpenCLIlya Biryukov1-1/+1
Reason: this commit causes crashes in the clang compiler when building LLVM Support with libc++, see https://bugs.llvm.org/show_bug.cgi?id=42665 for details. llvm-svn: 366429
2019-07-18[OpenCL] Improve destructor support in C++ for OpenCLMarco Antognini1-1/+1
Summary: This patch does mainly three things: 1. It fixes a false positive error detection in Sema that is similar to D62156. The error happens when explicitly calling an overloaded destructor for different address spaces. 2. It selects the correct destructor when multiple overloads for address spaces are available. 3. It inserts the expected address space cast when invoking a destructor, if needed, and therefore fixes a crash due to the unmet assertion in llvm::CastInst::Create. The following is a reproducer of the three issues: struct MyType { ~MyType() {} ~MyType() __constant {} }; __constant MyType myGlobal{}; kernel void foo() { myGlobal.~MyType(); // 1 and 2. // 1. error: cannot initialize object parameter of type // '__generic MyType' with an expression of type '__constant MyType' // 2. error: no matching member function for call to '~MyType' } kernel void bar() { // 3. The implicit call to the destructor crashes due to: // Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed. // in llvm::CastInst::Create. MyType myLocal; } The added test depends on D62413 and covers a few more things than the above reproducer. Subscribers: yaxunl, Anastasia, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64569 llvm-svn: 366422
2019-07-16Fix parameter name comments using clang-tidy. NFC.Rui Ueyama1-3/+3
This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
2019-06-21Ensure Target Features always_inline error happens in C++ cases.Erich Keane1-0/+10
A handful of C++ cases as reported in PR42352 didn't actually give an error when always_inlining with a different target feature list. This resulted in broken IR. llvm-svn: 364109
2019-06-05LLVM IR: Generate new-style byval-with-Type from ClangTim Northover1-1/+1
LLVM IR recently added a Type parameter to the byval Attribute, so that when pointers become opaque and no longer have an element type the information will still be present in IR. For now the Type parameter is optional (which is why Clang didn't need this change at the time), but it will become mandatory soon. llvm-svn: 362652
2019-05-03[COFF, ARM64] Fix ABI implementation of struct returnsMandeep Singh Grang1-2/+1
Summary: Related llvm patch: D60348. Patch co-authored by Sanjin Sijaric. Reviewers: rnk, efriedma, TomTan, ssijaric, ostannard Reviewed By: efriedma Subscribers: dmajor, richard.townsend.arm, ostannard, javed.absar, kristof.beyls, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60349 llvm-svn: 359932
2019-05-02Change the metadata for heapallocsite calls when the type is cast.Amy Huang1-1/+0
llvm-svn: 359823
2019-04-12Relanding r357928 with fixed debuginfo check.Amy Huang1-7/+9
[MS] Add metadata for __declspec(allocator) Original summary: Emit !heapallocsite in the metadata for calls to functions marked with __declspec(allocator). Eventually this will be emitted as S_HEAPALLOCSITE debug info in codeview. Differential Revision: https://reviews.llvm.org/D60237 llvm-svn: 358307
2019-04-10Don't emit an unreachable return block.John McCall1-9/+0
Patch by Brad Moody. llvm-svn: 358104
2019-04-08Revert "[MS] Add metadata for __declspec(allocator)"Amy Huang1-9/+7
This reverts commit e7bd735bb03a7b8141e32f7d6cb98e8914d8799e. Reverting because of buildbot failure. llvm-svn: 357952
2019-04-08[MS] Add metadata for __declspec(allocator)Amy Huang1-7/+9
Summary: Emit !heapallocsite in the metadata for calls to functions marked with __declspec(allocator). Eventually this will be emitted as S_HEAPALLOCSITE debug info in codeview. Reviewers: rnk Subscribers: jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60237 llvm-svn: 357928
2019-04-04[IR] Refactor attribute methods in Function class (NFC)Evandro Menezes1-1/+1
Rename the functions that query the optimization kind attributes. Differential revision: https://reviews.llvm.org/D60287 llvm-svn: 357731
2019-04-03[IR] Create new method in `Function` class (NFC)Evandro Menezes1-2/+1
Create method `optForNone()` testing for the function level equivalent of `-O0` and refactor appropriately. Differential revision: https://reviews.llvm.org/D59852 llvm-svn: 357638
2019-03-22IRGen: Remove StructorType; thread GlobalDecl through more code. NFCI.Peter Collingbourne1-23/+9
This should make it easier to add more structor variants. Differential Revision: https://reviews.llvm.org/D59724 llvm-svn: 356822
2019-03-19Add a spelling of pass_object_size that uses __builtin_dynamic_object_sizeErik Pilkington1-1/+1
The attribute pass_dynamic_object_size(n) behaves exactly like pass_object_size(n), but instead of evaluating __builtin_object_size on calls, it evaluates __builtin_dynamic_object_size, which has the potential to produce runtime code when the object size can't be determined statically. Differential revision: https://reviews.llvm.org/D58757 llvm-svn: 356515
2019-02-09[opaque pointer types] Cleanup CGBuilder's Create*GEP.James Y Knight1-38/+16
The various EltSize, Offset, DataLayout, and StructLayout arguments are all computable from the Address's element type and the DataLayout which the CGBuilder already has access to. After having previously asserted that the computed values are the same as those passed in, now remove the redundant arguments from CGBuilder's Create*GEP functions. Differential Revision: https://reviews.llvm.org/D57767 llvm-svn: 353629